]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Port netapp dataontap driver to Python 3
authorVictor Stinner <vstinner@redhat.com>
Mon, 15 Feb 2016 15:51:20 +0000 (16:51 +0100)
committerVictor Stinner <vstinner@redhat.com>
Wed, 24 Feb 2016 13:16:00 +0000 (14:16 +0100)
With this change, all unit tests on volume drivers pass on Python 3.

Changes:

* Replace a/b with a//b to get an integer on Python 3.
* Replace map(...) and filter(...) with a list-comprehension to get a
  list on Python 3.
* Replace dict.keys() with list(dict.keys()) to get a list
  on Python 3.
* Replace (str, int, float, long) with
  six.integer_types + (str, float): long type was removed
  from Python 3.
* decode_base32_to_hex(): on Python 3, decode encode_hex_to_base32()
  to return a Unicode string.
* convert_es_fmt_to_uuid(): encode/decode on Python 3 to pass the
  right types to base64.b32decode() (bytes) and uuid.UUID()
  (Unicode).
* fakes.py: Change type of XML document from Unicode to bytes: add
  b prefix to literal strings (b'...').
* Replace range(a, b) with list(range(a, b)) to get a list
  on Python 3.
* tests-py3.txt: add cinder.tests.unit.volume.drivers, all volume
  drivers tests now pass on Python 3.

Partial-Implements: blueprint cinder-python3
Change-Id: Iee609f72bbbef3789fa5e970d209047a113d005c

cinder/tests/unit/volume/drivers/netapp/dataontap/client/fakes.py
cinder/tests/unit/volume/drivers/netapp/dataontap/client/test_api.py
cinder/tests/unit/volume/drivers/netapp/dataontap/performance/test_perf_7mode.py
cinder/tests/unit/volume/drivers/netapp/dataontap/performance/test_perf_cmode.py
cinder/tests/unit/volume/drivers/netapp/dataontap/test_nfs_7mode.py
cinder/tests/unit/volume/drivers/netapp/dataontap/test_nfs_cmode.py
cinder/tests/unit/volume/drivers/netapp/eseries/test_host_mapper.py
cinder/volume/drivers/netapp/dataontap/client/api.py
cinder/volume/drivers/netapp/eseries/client.py
cinder/volume/drivers/netapp/eseries/utils.py
tests-py3.txt

index b21858fd76447b8f8c11fde2b983067aebaef331..cec69d9f7cc1389bf50e31743a68c65d9b99a46d 100644 (file)
@@ -20,7 +20,7 @@ from six.moves import urllib
 import cinder.volume.drivers.netapp.dataontap.client.api as netapp_api
 
 
-FAKE_VOL_XML = """<volume-info xmlns='http://www.netapp.com/filer/admin'>
+FAKE_VOL_XML = b"""<volume-info xmlns='http://www.netapp.com/filer/admin'>
     <name>open123</name>
     <state>online</state>
     <size-total>0</size-total>
@@ -30,12 +30,12 @@ FAKE_VOL_XML = """<volume-info xmlns='http://www.netapp.com/filer/admin'>
     <is-invalid>false</is-invalid>
     </volume-info>"""
 
-FAKE_XML1 = """<options>\
+FAKE_XML1 = b"""<options>\
 <test1>abc</test1>\
 <test2>abc</test2>\
 </options>"""
 
-FAKE_XML2 = """<root><options>somecontent</options></root>"""
+FAKE_XML2 = b"""<root><options>somecontent</options></root>"""
 
 FAKE_NA_ELEMENT = netapp_api.NaElement(etree.XML(FAKE_VOL_XML))
 
index f577c9cea10bfdb7472f78fbc854f18826ed24ab..44ebe3ca1803b735380976bd3c754022fbade351 100644 (file)
@@ -468,7 +468,7 @@ class NetAppApiInvokeTests(test.TestCase):
         api_name = zapi_fakes.FAKE_API_NAME
         invoke_generator = netapp_api.invoke_api(na_server, api_name)
 
-        self.assertRaises(exception.InvalidInput, invoke_generator.next)
+        self.assertRaises(exception.InvalidInput, next, invoke_generator)
 
     @ddt.data({'params': {'na_server': zapi_fakes.FAKE_NA_SERVER,
                           'api_name': zapi_fakes.FAKE_API_NAME}},
index 71a04d95848179b28abe7f126ac7d3a2235e7bec..4e363f546100a54ff53d9450e3148811b1d38aa9 100644 (file)
@@ -87,7 +87,7 @@ class Performance7modeLibraryTestCase(test.TestCase):
 
     def test_update_performance_cache(self):
 
-        self.perf_library.performance_counters = range(11, 21)
+        self.perf_library.performance_counters = list(range(11, 21))
 
         mock_get_node_utilization_counters = self.mock_object(
             self.perf_library, '_get_node_utilization_counters',
@@ -98,7 +98,8 @@ class Performance7modeLibraryTestCase(test.TestCase):
 
         self.perf_library.update_performance_cache()
 
-        self.assertEqual(range(12, 22), self.perf_library.performance_counters)
+        self.assertEqual(list(range(12, 22)),
+                         self.perf_library.performance_counters)
         self.assertEqual(25, self.perf_library.utilization)
         mock_get_node_utilization_counters.assert_called_once_with()
         mock_get_node_utilization.assert_called_once_with(12, 21, fake.NODE)
@@ -120,7 +121,7 @@ class Performance7modeLibraryTestCase(test.TestCase):
 
     def test_update_performance_cache_counters_unavailable(self):
 
-        self.perf_library.performance_counters = range(11, 21)
+        self.perf_library.performance_counters = list(range(11, 21))
         self.perf_library.utilization = 55.0
 
         mock_get_node_utilization_counters = self.mock_object(
@@ -132,7 +133,7 @@ class Performance7modeLibraryTestCase(test.TestCase):
 
         self.perf_library.update_performance_cache()
 
-        self.assertEqual(range(11, 21),
+        self.assertEqual(list(range(11, 21)),
                          self.perf_library.performance_counters)
         self.assertEqual(55.0, self.perf_library.utilization)
         mock_get_node_utilization_counters.assert_called_once_with()
index 12446764f6722840c71c8e137fba79e3792b0cde..78e5db932b8804b94ff1ab6799b8d2f31f595f67 100644 (file)
@@ -142,8 +142,8 @@ class PerformanceCmodeLibraryTestCase(test.TestCase):
     def test_update_performance_cache(self):
 
         self.perf_library.performance_counters = {
-            'node1': range(11, 21),
-            'node2': range(21, 31),
+            'node1': list(range(11, 21)),
+            'node2': list(range(21, 31)),
         }
         mock_get_aggregates_for_pools = self.mock_object(
             self.perf_library, '_get_aggregates_for_pools',
@@ -162,8 +162,8 @@ class PerformanceCmodeLibraryTestCase(test.TestCase):
         self.perf_library.update_performance_cache(self.fake_volumes)
 
         expected_performance_counters = {
-            'node1': range(12, 22),
-            'node2': range(22, 32),
+            'node1': list(range(12, 22)),
+            'node2': list(range(22, 32)),
         }
         self.assertEqual(expected_performance_counters,
                          self.perf_library.performance_counters)
index c463d5b8d054467ff58b929c29ed8cbb08a19cea..c2e92d9ccfb0c4a39c0a13b91fd85800926b07bc 100644 (file)
@@ -64,9 +64,9 @@ class NetApp7modeNfsDriverTestCase(test.TestCase):
         thick = not nfs_sparsed_volumes
 
         total_capacity_gb = na_utils.round_down(
-            fake.TOTAL_BYTES / units.Gi, '0.01')
+            fake.TOTAL_BYTES // units.Gi, '0.01')
         free_capacity_gb = na_utils.round_down(
-            fake.AVAILABLE_BYTES / units.Gi, '0.01')
+            fake.AVAILABLE_BYTES // units.Gi, '0.01')
         provisioned_capacity_gb = total_capacity_gb - free_capacity_gb
         capacity = {
             'reserved_percentage': fake.RESERVED_PERCENTAGE,
index 4f3d43b7917d9259c6e2f99b30bc9abddca79d8d..0aac910a91c787c0fbbc15177023d845df3793e0 100644 (file)
@@ -122,9 +122,9 @@ class NetAppCmodeNfsDriverTestCase(test.TestCase):
         thick = not thin and not nfs_sparsed_volumes
 
         total_capacity_gb = na_utils.round_down(
-            fake.TOTAL_BYTES / units.Gi, '0.01')
+            fake.TOTAL_BYTES // units.Gi, '0.01')
         free_capacity_gb = na_utils.round_down(
-            fake.AVAILABLE_BYTES / units.Gi, '0.01')
+            fake.AVAILABLE_BYTES // units.Gi, '0.01')
         provisioned_capacity_gb = total_capacity_gb - free_capacity_gb
         capacity = {
             'reserved_percentage': fake.RESERVED_PERCENTAGE,
index 3e7f07d1a96209b4ff748e8032d1c232d164e516..314923dc112c076c2224180d89e9f4645bc27b41 100644 (file)
@@ -41,7 +41,7 @@ def get_fake_volume():
 
 FAKE_MAPPINGS = [{u'lun': 1}]
 
-FAKE_USED_UP_MAPPINGS = map(lambda n: {u'lun': n}, range(256))
+FAKE_USED_UP_MAPPINGS = [{u'lun': n} for n in range(256)]
 
 FAKE_USED_UP_LUN_ID_DICT = {n: 1 for n in range(256)}
 
index e8847bda4650b9307b35c8597f486cdbb84b9967..4d729f99e77cae41faa3dd09bdcc50b3ebd579b8 100644 (file)
@@ -390,7 +390,7 @@ class NaElement(object):
     def get_attr_names(self):
         """Returns the list of attribute names."""
         attributes = self._element.attrib or {}
-        return attributes.keys()
+        return list(attributes.keys())
 
     def add_new_child(self, name, content, convert=False):
         """Add child with tag name and context.
@@ -466,7 +466,7 @@ class NaElement(object):
                     child = NaElement(key)
                     child.add_child_elem(value)
                     self.add_child_elem(child)
-                elif isinstance(value, (str, int, float, long)):
+                elif isinstance(value, six.integer_types + (str, float)):
                     self.add_new_child(key, six.text_type(value))
                 elif isinstance(value, (list, tuple, dict)):
                     child = NaElement(key)
index e9c8f0b09b0aec4b185b87c95852bfb076adb91e..49dcc5e66a8036b09120679e305094c853ceb869 100644 (file)
@@ -488,21 +488,18 @@ class RestClient(WebserviceClient):
     def get_volume_mappings_for_volume(self, volume):
         """Gets all host mappings for given volume from array."""
         mappings = self.get_volume_mappings() or []
-        host_maps = filter(lambda x: x.get('volumeRef') == volume['volumeRef'],
-                           mappings)
-        return host_maps
+        return [x for x in mappings
+                if x.get('volumeRef') == volume['volumeRef']]
 
     def get_volume_mappings_for_host(self, host_ref):
         """Gets all volume mappings for given host from array."""
         mappings = self.get_volume_mappings() or []
-        host_maps = filter(lambda x: x.get('mapRef') == host_ref, mappings)
-        return host_maps
+        return [x for x in mappings if x.get('mapRef') == host_ref]
 
     def get_volume_mappings_for_host_group(self, hg_ref):
         """Gets all volume mappings for given host group from array."""
         mappings = self.get_volume_mappings() or []
-        hg_maps = filter(lambda x: x.get('mapRef') == hg_ref, mappings)
-        return hg_maps
+        return [x for x in mappings if x.get('mapRef') == hg_ref]
 
     def create_volume_mapping(self, object_id, target_id, lun):
         """Creates volume mapping on array."""
index c99fb0f88992c4435077d0b6b5c6e5932c578aa0..0c699c2cf3306410c82af005112ef06732f61773 100644 (file)
@@ -47,12 +47,20 @@ def decode_base32_to_hex(base32_string):
 def convert_uuid_to_es_fmt(uuid_str):
     """Converts uuid to e-series compatible name format."""
     uuid_base32 = encode_hex_to_base32(uuid.UUID(six.text_type(uuid_str)).hex)
-    return str(uuid_base32.strip(b'='))
+    es_label = uuid_base32.strip(b'=')
+    if six.PY3:
+        es_label = es_label.decode('ascii')
+    return es_label
 
 
 def convert_es_fmt_to_uuid(es_label):
     """Converts e-series name format to uuid."""
-    if es_label.startswith('tmp-'):
+    if isinstance(es_label, six.text_type):
+        es_label = es_label.encode('utf-8')
+    if es_label.startswith(b'tmp-'):
         es_label = es_label[4:]
-    es_label_b32 = es_label.ljust(32, '=')
-    return uuid.UUID(binascii.hexlify(base64.b32decode(es_label_b32)))
+    es_label = es_label.ljust(32, b'=')
+    es_label = binascii.hexlify(base64.b32decode(es_label))
+    if six.PY3:
+        es_label = es_label.decode('ascii')
+    return uuid.UUID(es_label)
index d2372030c0fe090ad3bfee5f8566556a5d69843a..6f93ebbd46c5eb0650c24231daec01c2346f46b5 100644 (file)
@@ -145,10 +145,7 @@ cinder.tests.unit.test_volume_utils
 cinder.tests.unit.test_vzstorage
 cinder.tests.unit.test_xio
 cinder.tests.unit.test_zfssa
-cinder.tests.unit.volume.drivers.emc.scaleio
-cinder.tests.unit.volume.drivers.netapp.eseries.test_library
-cinder.tests.unit.volume.drivers.test_fujitsu
-cinder.tests.unit.volume.drivers.test_hgst
+cinder.tests.unit.volume.drivers
 cinder.tests.unit.volume.flows.test_create_volume_flow
 cinder.tests.unit.windows.test_smbfs
 cinder.tests.unit.windows.test_vhdutils