]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Fix Python 3 issues in cmd
authorVictor Stinner <vstinner@redhat.com>
Tue, 30 Jun 2015 14:47:15 +0000 (16:47 +0200)
committerVictor Stinner <vstinner@redhat.com>
Thu, 2 Jul 2015 11:42:20 +0000 (13:42 +0200)
* 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

cinder/cmd/rtstool.py
cinder/tests/unit/test_cmd.py
tox.ini

index a1ae0b1a9a0df6d5a34fe66144df4f1a82af5fe3..4714f4130d9181a248a353abfed23aee47828b78 100644 (file)
@@ -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
index 1cd592de571435f00c98974c8fe9b4272f2a565c..25c04f9ecafc7affcb5fe87a3ce9d1fa14dbcf92 100644 (file)
@@ -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
diff --git a/tox.ini b/tox.ini
index 1ff355b8325006e1359930c7eac524316a8c0843..faccff1fe2020069031042cd791113160c932946 100644 (file)
--- a/tox.ini
+++ b/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 \