]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Port image/glance.py to Python 3
authorVictor Stinner <vstinner@redhat.com>
Tue, 30 Jun 2015 14:06:28 +0000 (16:06 +0200)
committerVictor Stinner <vstinner@redhat.com>
Thu, 2 Jul 2015 11:33:28 +0000 (13:33 +0200)
* Fix usage of six.reraise(): new_exc is the exception value, not the
  exception type
* Replace __builtin__ with six.moves.builtins.
* test_extracting_v2_boot_properties(): set config.glance_num_retries to
  fix the test on Python 3 (comparison between mock and int now raises
  a TypeError on Python 3).
* TestGlanceSerializer: use dictionaries with only one key to have a
  reliable output even if the hash is randomized (hash randomization is
  now enabled by default in Python 3).
* tox.ini: add cinder.tests.unit.image.test_glance to Python 3.4.

Blueprint cinder-python3
Change-Id: I33cd02e1b0666d7b5999b2fdaf469dc59fff1866

cinder/image/glance.py
cinder/tests/unit/image/test_glance.py
tox.ini

index be32766b612b6e6da63e7a6a75e59b1dfe5c65d3..961e7cce631c064d631da60586966f07f38b9563 100644 (file)
@@ -482,14 +482,14 @@ def _reraise_translated_image_exception(image_id):
     """Transform the exception for the image but keep its traceback intact."""
     _exc_type, exc_value, exc_trace = sys.exc_info()
     new_exc = _translate_image_exception(image_id, exc_value)
-    six.reraise(new_exc, None, exc_trace)
+    six.reraise(type(new_exc), new_exc, exc_trace)
 
 
 def _reraise_translated_exception():
     """Transform the exception but keep its traceback intact."""
     _exc_type, exc_value, exc_trace = sys.exc_info()
     new_exc = _translate_plain_exception(exc_value)
-    six.reraise(new_exc, None, exc_trace)
+    six.reraise(type(new_exc), new_exc, exc_trace)
 
 
 def _translate_image_exception(image_id, exc_value):
index a8b61caea1b5993d518b404ccd048bed0c32ff3a..e1defc409b4909f5069afe3cabd62c4717c3ee83 100644 (file)
@@ -45,15 +45,11 @@ class TestGlanceSerializer(test.TestCase):
                     'properties': {
                         'prop1': 'propvalue1',
                         'mappings': [
-                            {'virtual': 'aaa',
-                             'device': 'bbb'},
-                            {'virtual': 'xxx',
-                             'device': 'yyy'}],
+                            {'device': 'bbb'},
+                            {'device': 'yyy'}],
                         'block_device_mapping': [
-                            {'virtual_device': 'fake',
-                             'device_name': '/dev/fake'},
-                            {'virtual_device': 'ephemeral0',
-                             'device_name': '/dev/fake0'}]}}
+                            {'device_name': '/dev/fake'},
+                            {'device_name': '/dev/fake0'}]}}
 
         converted_expected = {
             'name': 'image1',
@@ -62,12 +58,11 @@ class TestGlanceSerializer(test.TestCase):
             'properties': {
                 'prop1': 'propvalue1',
                 'mappings':
-                '[{"device": "bbb", "virtual": "aaa"}, '
-                '{"device": "yyy", "virtual": "xxx"}]',
+                '[{"device": "bbb"}, '
+                '{"device": "yyy"}]',
                 'block_device_mapping':
-                '[{"virtual_device": "fake", "device_name": "/dev/fake"}, '
-                '{"virtual_device": "ephemeral0", '
-                '"device_name": "/dev/fake0"}]'}}
+                '[{"device_name": "/dev/fake"}, '
+                '{"device_name": "/dev/fake0"}]'}}
         converted = glance._convert_to_string(metadata)
         self.assertEqual(converted, converted_expected)
         self.assertEqual(glance._convert_from_string(converted), metadata)
@@ -518,7 +513,7 @@ class TestGlanceImageService(test.TestCase):
         self.assertRaises(exception.ImageNotFound, service.download,
                           self.context, image_id, writer)
 
-    @mock.patch('__builtin__.open')
+    @mock.patch('six.moves.builtins.open')
     @mock.patch('shutil.copyfileobj')
     def test_download_from_direct_file(self, mock_copyfileobj, mock_open):
         fixture = self._make_fixture(name='test image',
@@ -530,7 +525,7 @@ class TestGlanceImageService(test.TestCase):
         self.service.download(self.context, image_id, writer)
         mock_copyfileobj.assert_called_once_with(mock.ANY, writer)
 
-    @mock.patch('__builtin__.open')
+    @mock.patch('six.moves.builtins.open')
     @mock.patch('shutil.copyfileobj')
     def test_download_from_direct_file_non_file(self,
                                                 mock_copyfileobj, mock_open):
@@ -613,6 +608,7 @@ class TestGlanceImageService(test.TestCase):
     def test_extracting_v2_boot_properties(self, config):
 
         config.glance_api_version = 2
+        config.glance_num_retries = 0
 
         attributes = ['size', 'disk_format', 'owner', 'container_format',
                       'checksum', 'id', 'name', 'created_at', 'updated_at',
diff --git a/tox.ini b/tox.ini
index 1ff355b8325006e1359930c7eac524316a8c0843..0c92b462e31e5c3102cee97557f5a96cb24b50e9 100644 (file)
--- a/tox.ini
+++ b/tox.ini
@@ -29,6 +29,7 @@ downloadcache = ~/cache/pip
 [testenv:py34]
 commands =
   python -m testtools.run \
+    cinder.tests.unit.image.test_glance \
     cinder.tests.unit.targets.test_base_iscsi_driver \
     cinder.tests.unit.targets.test_cxt_driver \
     cinder.tests.unit.targets.test_iser_driver \