]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Port EMC VNX CLI to Python 3
authorVictor Stinner <vstinner@redhat.com>
Wed, 7 Oct 2015 14:07:22 +0000 (16:07 +0200)
committerVictor Stinner <vstinner@redhat.com>
Fri, 13 Nov 2015 09:22:14 +0000 (10:22 +0100)
CreateConsistencyGroupTask, WaitMigrationsCompleteTask: sort the lun
identifier keys to have a determinist order. On Python 3, the hash
function is randomized, so set() order is undefined and changes at
each run.

Other changes:

* Replace map() with list-comprehension to get a list on Python 3.
* Replace assertTrue(str.find(pattern) > 0) with
  assertIn(pattern, str) to not fail if pattern is at the beginning
  on the string. On Python 3, the hash function is randomized and so
  parts of the provider_location are in a random order, it can be at
  the beginning.
* tests-py3.txt: add cinder.tests.unit.test_emc_vnxdirect

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

cinder/tests/unit/test_emc_vnxdirect.py
cinder/volume/drivers/emc/emc_vnx_cli.py
tests-py3.txt

index 9e9a6caa233cb119bc2f5fa90dee125ef797907f..591db15d7ba89da8d12e6d00762e2d2bae7c6911 100644 (file)
@@ -2026,8 +2026,7 @@ Time Remaining:  0 second(s)
                                          vol,
                                          fake_host)
         self.assertTrue(ret[0])
-        self.assertTrue(
-            ret[1]['provider_location'].find('type^lun') > 0)
+        self.assertIn('type^lun', ret[1]['provider_location'])
         # verification
         expect_cmd = [mock.call(*self.testData.MIGRATION_CMD(),
                                 retry_disable=True,
@@ -2597,8 +2596,7 @@ Time Remaining:  0 second(s)
         vol = self.driver.create_volume_from_snapshot(
             self.testData.test_volume_with_type,
             self.testData.test_snapshot)
-        self.assertTrue(
-            vol['provider_location'].find('type^smp') > 0)
+        self.assertIn('type^smp', vol['provider_location'])
         expect_cmd = [
             mock.call(
                 *self.testData.SNAP_COPY_CMD(
@@ -2768,8 +2766,7 @@ Time Remaining:  0 second(s)
         vol = self.driver.create_cloned_volume(
             self.testData.test_clone,
             self.testData.test_volume_with_type)
-        self.assertTrue(
-            vol['provider_location'].find('type^smp') > 0)
+        self.assertIn('type^smp', vol['provider_location'])
         expect_cmd = [
             mock.call(
                 *self.testData.SNAP_CREATE_CMD(
@@ -3738,8 +3735,7 @@ Time Remaining:  0 second(s)
                                  host_test_data)
         self.assertTrue(type(ret) == tuple)
         self.assertTrue(ret[0])
-        self.assertTrue(
-            ret[1]['provider_location'].find('type^lun') > 0)
+        self.assertIn('type^lun', ret[1]['provider_location'])
         expect_cmd = [
             mock.call(*self.testData.SNAP_LIST_CMD(), poll=False),
             mock.call(*self.testData.SNAP_DELETE_CMD(tmp_snap),
@@ -4228,10 +4224,10 @@ Time Remaining:  0 second(s)
                       vol2_in_new_cg['name'] + '_dest'), poll=False),
             mock.call(*td.MIGRATION_CMD(6232, 2),
                       poll=True, retry_disable=True),
-            mock.call(*td.MIGRATION_VERIFY_CMD(6232), poll=True),
             mock.call(*td.MIGRATION_VERIFY_CMD(6231), poll=True),
+            mock.call(*td.MIGRATION_VERIFY_CMD(6232), poll=True),
             mock.call(*td.CREATE_CONSISTENCYGROUP_CMD(
-                      new_cg['id'], [6232, 6231]), poll=True),
+                      new_cg['id'], [6231, 6232]), poll=True),
             mock.call(*td.DELETE_CG_SNAPSHOT(copied_snap_name))]
         self.assertEqual(expect_cmd, fake_cli.call_args_list)
 
@@ -5150,8 +5146,8 @@ class EMCVNXCLIDriverFCTestCase(DriverTestCaseBase):
                               poll=False),
                     mock.call('port', '-list', '-gname', 'fakehost')]
         fake_cli.assert_has_calls(expected)
-        self.assertEqual(['5006016A0860080F', '5006016008600195'],
-                         data['data']['target_wwn'])
+        self.assertEqual(set(['5006016A0860080F', '5006016008600195']),
+                         set(data['data']['target_wwn']))
 
     @mock.patch('random.randint',
                 mock.Mock(return_value=0))
@@ -5187,8 +5183,8 @@ class EMCVNXCLIDriverFCTestCase(DriverTestCaseBase):
                               poll=False),
                     mock.call('port', '-list', '-gname', 'fakehost')]
         fake_cli.assert_has_calls(expected)
-        self.assertEqual(['5006016A0860080F', '5006016008600195'],
-                         data['data']['target_wwn'])
+        self.assertEqual(set(['5006016A0860080F', '5006016008600195']),
+                         set(data['data']['target_wwn']))
 
     @mock.patch(
         "cinder.zonemanager.fc_san_lookup_service.FCSanLookupService." +
index b3b7ffd83f6084dc82a705ed0dcd77838fd4765d..4829a0b441af4ea1e838414fb0074e81f8397a6d 100644 (file)
@@ -3225,11 +3225,9 @@ class EMCVnxCliBase(object):
         wwnns = connector['wwnns']
         wwpns = connector['wwpns']
         wwns = [(node + port).upper() for node, port in zip(wwnns, wwpns)]
-        return map(lambda wwn: re.sub(r'\S\S',
-                                      lambda m: m.group(0) + ':',
-                                      wwn,
-                                      len(wwn) / 2 - 1),
-                   wwns)
+        return [re.sub(r'\S\S', lambda m: m.group(0) + ':',
+                       wwn, len(wwn) // 2 - 1)
+                for wwn in wwns]
 
     def _exec_command_setpath(self, initiator_uid, sp, port_id,
                               ip, host, vport_id=None):
@@ -4063,8 +4061,8 @@ class EMCVnxCliBase(object):
                                pool_list)
         pool_feature = (self._client.get_pool_feature_properties(poll=False)
                         if self.check_max_pool_luns_threshold else None)
-        self.stats['pools'] = map(
-            lambda pool: self._build_pool_stats(pool, pool_feature), pool_list)
+        self.stats['pools'] = [self._build_pool_stats(pool, pool_feature)
+                               for pool in pool_list]
 
         return self.stats
 
@@ -4265,8 +4263,8 @@ class AllowReadWriteOnSnapshotTask(task.Task):
 class CreateConsistencyGroupTask(task.Task):
     """Task to create a consistency group."""
     def __init__(self, lun_id_key_template, num_of_members):
-        self.lun_id_keys = set(
-            [lun_id_key_template % i for i in range(num_of_members)])
+        self.lun_id_keys = sorted(set(
+            [lun_id_key_template % i for i in range(num_of_members)]))
         super(CreateConsistencyGroupTask, self).__init__(
             requires=self.lun_id_keys)
 
@@ -4280,8 +4278,8 @@ class CreateConsistencyGroupTask(task.Task):
 class WaitMigrationsCompleteTask(task.Task):
     """Task to wait migrations to be completed."""
     def __init__(self, lun_id_key_template, num_of_members):
-        self.lun_id_keys = set(
-            [lun_id_key_template % i for i in range(num_of_members)])
+        self.lun_id_keys = sorted(set(
+            [lun_id_key_template % i for i in range(num_of_members)]))
         super(WaitMigrationsCompleteTask, self).__init__(
             requires=self.lun_id_keys)
 
index 5e33a271a52b49fef40d106ccf4ce0a425b6df4a..6426844c931afadddc506c5d4c18dc920e4cd64a 100644 (file)
@@ -56,6 +56,7 @@ cinder.tests.unit.test_dellsc
 cinder.tests.unit.test_dellscapi
 cinder.tests.unit.test_dothill
 cinder.tests.unit.test_drbdmanagedrv
+cinder.tests.unit.test_emc_vnxdirect
 cinder.tests.unit.test_emc_xtremio
 cinder.tests.unit.test_eqlx
 cinder.tests.unit.test_evaluator