Fix Python 3 issues in cmd
* Replace filter() with a list-comprehension using if to get a list on Python 3. * Get the mock module from the stdlib unittest module on Python 3.3 and newer, or fallback to the third-party mock module. * Replace __builtin__ with six.moves.builtins. * tox.ini: add the following tests for Python 3.4 - cinder.tests.unit.test_api - cinder.tests.unit.test_cmd Blueprint cinder-python3 Change-Id: Iea516ae598e8eebfc1087663a9b3e0a00d0633d3
This commit is contained in:
parent
85b0917570
commit
432c23dddb
@ -229,7 +229,7 @@ def parse_optional_create(argv):
|
||||
|
||||
for arg in argv:
|
||||
if arg.startswith('-a'):
|
||||
ips = filter(None, arg[2:].split(','))
|
||||
ips = [ip for ip in arg[2:].split(',') if ip]
|
||||
if not ips:
|
||||
usage()
|
||||
optional_args['portals_ips'] = ips
|
||||
|
@ -14,7 +14,10 @@ import datetime
|
||||
import six
|
||||
import sys
|
||||
|
||||
import mock
|
||||
try:
|
||||
from unittest import mock
|
||||
except ImportError:
|
||||
import mock
|
||||
from oslo_config import cfg
|
||||
|
||||
try:
|
||||
@ -533,7 +536,7 @@ class TestCinderManageCmd(test.TestCase):
|
||||
|
||||
self.assertEqual(expected_out, fake_out.getvalue())
|
||||
|
||||
@mock.patch('__builtin__.open')
|
||||
@mock.patch('six.moves.builtins.open')
|
||||
@mock.patch('os.listdir')
|
||||
def test_get_log_commands_errors(self, listdir, open):
|
||||
CONF.set_override('log_dir', 'fake-dir')
|
||||
@ -552,7 +555,7 @@ class TestCinderManageCmd(test.TestCase):
|
||||
open.assert_called_once_with('fake-dir/fake-error.log', 'r')
|
||||
listdir.assert_called_once_with(CONF.log_dir)
|
||||
|
||||
@mock.patch('__builtin__.open')
|
||||
@mock.patch('six.moves.builtins.open')
|
||||
@mock.patch('os.path.exists')
|
||||
def test_get_log_commands_syslog_no_log_file(self, path_exists, open):
|
||||
path_exists.return_value = False
|
||||
|
2
tox.ini
2
tox.ini
@ -35,6 +35,7 @@ commands =
|
||||
cinder.tests.unit.targets.test_lio_driver \
|
||||
cinder.tests.unit.targets.test_scst_driver \
|
||||
cinder.tests.unit.targets.test_tgt_driver \
|
||||
cinder.tests.unit.test_api \
|
||||
cinder.tests.unit.test_api_urlmap \
|
||||
cinder.tests.unit.test_backup \
|
||||
cinder.tests.unit.test_backup_ceph \
|
||||
@ -44,6 +45,7 @@ commands =
|
||||
cinder.tests.unit.test_block_device \
|
||||
cinder.tests.unit.test_blockbridge \
|
||||
cinder.tests.unit.test_cloudbyte \
|
||||
cinder.tests.unit.test_cmd \
|
||||
cinder.tests.unit.test_conf \
|
||||
cinder.tests.unit.test_context \
|
||||
cinder.tests.unit.test_create_volume_flow \
|
||||
|
Loading…
x
Reference in New Issue
Block a user