]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Port violin driver to Python 3
authorVictor Stinner <vstinner@redhat.com>
Wed, 7 Oct 2015 17:01:57 +0000 (19:01 +0200)
committerVictor Stinner <vstinner@redhat.com>
Wed, 7 Oct 2015 21:21:05 +0000 (23:21 +0200)
* Replace dict.items()[0] with list(dict.items())[0], same for
  dict.values()
* Replace dict.iteritems() with dict.items()
* Replace dict.itervalues() with dict.values()
* Replace a/b with a//b to get integer on Python 3.
* test_get_active_fc_targets(): ignore order when comparing active
  FC targets. On Python 3, the hash function is randomized and so
  dictionaries values are returned in a random order.

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

cinder/tests/unit/test_v7000_fcp.py
cinder/volume/drivers/violin/v6000_common.py
cinder/volume/drivers/violin/v6000_fcp.py
cinder/volume/drivers/violin/v6000_iscsi.py
cinder/volume/drivers/violin/v7000_common.py
cinder/volume/drivers/violin/v7000_fcp.py
tests-py3.txt

index b5c81912d95bf60a02cb1d5e97cff81e9bfe25a7..f736a7d8c53160ea30ccc4f917fe829d5743fd83 100644 (file)
@@ -385,9 +385,9 @@ class V7000FCPDriverTestCase(test.TestCase):
 
         result = self.driver._get_active_fc_targets()
 
-        self.assertEqual(['2100001b9745e230', '2100001b9745e25f',
-                          '2100001b9745e231', '2100001b9745e25e'],
-                         result)
+        self.assertEqual({'2100001b9745e230', '2100001b9745e25f',
+                          '2100001b9745e231', '2100001b9745e25e'},
+                         set(result))
 
     def test_initialize_connection(self):
         lun_id = 1
index a777d7d4f66062cfce590cb769219fb7bd816566..9d1cc09c05bab96f5fb39adeae5d78184c618c66 100644 (file)
@@ -115,7 +115,7 @@ class V6000Common(object):
         ret_dict = self.vip.basic.get_node_values(
             "/vshare/state/local/container/*")
         if ret_dict:
-            self.container = ret_dict.items()[0][1]
+            self.container = list(ret_dict.items())[0][1]
 
     def check_for_setup_error(self):
         """Returns an error if prerequisites aren't met."""
index af19efa3b9965a07e8266ecc9a73422212bd7841..096aeee116531ac4c7f59ab15dd18b4bdcaf25b3 100644 (file)
@@ -430,8 +430,8 @@ class V6000FCDriver(driver.FibreChannelDriver):
         free_gb = 0
         v = self.common.vip
 
-        master_cluster_id = v.basic.get_node_values(
-            '/cluster/state/master_id').values()[0]
+        master_cluster_id = list(v.basic.get_node_values(
+            '/cluster/state/master_id').values())[0]
 
         bn1 = "/vshare/state/global/%s/container/%s/total_bytes" \
             % (master_cluster_id, self.common.container)
@@ -440,14 +440,14 @@ class V6000FCDriver(driver.FibreChannelDriver):
         resp = v.basic.get_node_values([bn1, bn2])
 
         if bn1 in resp:
-            total_gb = resp[bn1] / units.Gi
+            total_gb = resp[bn1] // units.Gi
         else:
             LOG.warning(_LW("Failed to receive update for total_gb stat!"))
             if 'total_capacity_gb' in self.stats:
                 total_gb = self.stats['total_capacity_gb']
 
         if bn2 in resp:
-            free_gb = resp[bn2] / units.Gi
+            free_gb = resp[bn2] // units.Gi
         else:
             LOG.warning(_LW("Failed to receive update for free_gb stat!"))
             if 'free_capacity_gb' in self.stats:
index aa525e9c73bc0748ebc13f3c471d1a067e5e6aa6..adad1150b0138bbb8550dba92c9cf1e0c1656a08 100644 (file)
@@ -449,8 +449,8 @@ class V6000ISCSIDriver(driver.ISCSIDriver):
         free_gb = 0
         v = self.common.vip
 
-        master_cluster_id = v.basic.get_node_values(
-            '/cluster/state/master_id').values()[0]
+        master_cluster_id = list(v.basic.get_node_values(
+            '/cluster/state/master_id').values())[0]
 
         bn1 = "/vshare/state/global/%s/container/%s/total_bytes" \
             % (master_cluster_id, self.common.container)
@@ -459,14 +459,14 @@ class V6000ISCSIDriver(driver.ISCSIDriver):
         resp = v.basic.get_node_values([bn1, bn2])
 
         if bn1 in resp:
-            total_gb = resp[bn1] / units.Gi
+            total_gb = resp[bn1] // units.Gi
         else:
             LOG.warning(_LW("Failed to receive update for total_gb stat!"))
             if 'total_capacity_gb' in self.stats:
                 total_gb = self.stats['total_capacity_gb']
 
         if bn2 in resp:
-            free_gb = resp[bn2] / units.Gi
+            free_gb = resp[bn2] // units.Gi
         else:
             LOG.warning(_LW("Failed to receive update for free_gb stat!"))
             if 'free_capacity_gb' in self.stats:
@@ -554,7 +554,7 @@ class V6000ISCSIDriver(driver.ISCSIDriver):
 
         ret_dict = conn.basic.get_node_values("/system/hostname")
         if ret_dict:
-            hostname = ret_dict.items()[0][1]
+            hostname = list(ret_dict.items())[0][1]
         else:
             LOG.debug("Unable to fetch gateway hostname for %s.", mg_to_query)
 
index fba65080e1aa2517e519fb788d16f2925dc0e266..b4e8516e0c108540ba2abaaf66fc756658b4f68e 100644 (file)
@@ -133,7 +133,7 @@ class V7000Common(object):
             thin_lun = True
             # Set the actual allocation size for thin lun
             # default here is 10%
-            size_mb = size_mb / 10
+            size_mb = size_mb // 10
 
         typeid = volume['volume_type_id']
         if typeid:
@@ -143,7 +143,7 @@ class V7000Common(object):
                 thin_lun = True
                 # Set the actual allocation size for thin lun
                 # default here is 10%
-                size_mb = size_mb / 10
+                size_mb = size_mb // 10
 
             spec_value = self._get_volume_type_extra_spec(volume, "dedup")
             if spec_value and spec_value.lower() == "true":
@@ -153,7 +153,7 @@ class V7000Common(object):
                 # Set the actual allocation size for thin lun
                 # default here is 10%. The actual allocation may
                 # different, depending on other factors
-                size_mb = full_size_mb / 10
+                size_mb = full_size_mb // 10
 
             # Extract the storage_pool name if one is specified
             pool = self._get_violin_extra_spec(volume, "storage_pool")
@@ -817,7 +817,7 @@ class V7000Common(object):
         if typeid:
             volume_type = volume_types.get_volume_type(ctxt, typeid)
             volume_specs = volume_type.get('extra_specs')
-            for key, val in volume_specs.iteritems():
+            for key, val in volume_specs.items():
 
                 # Strip the prefix "capabilities"
                 if ':' in key:
@@ -842,7 +842,7 @@ class V7000Common(object):
         if typeid:
             volume_type = volume_types.get_volume_type(ctxt, typeid)
             volume_specs = volume_type.get('extra_specs')
-            for key, val in volume_specs.iteritems():
+            for key, val in volume_specs.items():
 
                 # Strip the prefix "violin"
                 if ':' in key:
index f6aef8a9c7ce171d739b0bb392d43eb9187c727d..4e57bbce41dc523d28ccd2d6461e4f1392f5e0ad 100644 (file)
@@ -269,8 +269,8 @@ class V7000FCPDriver(driver.FibreChannelDriver):
 
         for x in all_devices:
             if socket.getfqdn(x['owner']) == array_name:
-                total_gb += x['size_mb'] / 1024
-                free_gb += x['availsize_mb'] / 1024
+                total_gb += x['size_mb'] // 1024
+                free_gb += x['availsize_mb'] // 1024
 
         backend_name = self.configuration.volume_backend_name
         data['volume_backend_name'] = backend_name or self.__class__.__name__
@@ -297,7 +297,7 @@ class V7000FCPDriver(driver.FibreChannelDriver):
         active_gw_fcp_wwns = []
 
         fc_info = v.adapter.get_fc_info()
-        for x in fc_info.itervalues():
+        for x in fc_info.values():
             active_gw_fcp_wwns.append(x[0])
 
         return active_gw_fcp_wwns
index e933f6a316be8899b3b6293e357bafaf33932538..af6b30412e46ec70a2dbfa2cfc6cfafa096e3492 100644 (file)
@@ -80,6 +80,10 @@ cinder.tests.unit.test_solidfire
 cinder.tests.unit.test_test
 cinder.tests.unit.test_test_utils
 cinder.tests.unit.test_v6000_common
+cinder.tests.unit.test_v6000_fcp
+cinder.tests.unit.test_v6000_iscsi
+cinder.tests.unit.test_v7000_common
+cinder.tests.unit.test_v7000_fcp
 cinder.tests.unit.test_vmware_vmdk
 cinder.tests.unit.test_vmware_volumeops
 cinder.tests.unit.test_volume