From b2050e4a08d5ba0b54b4fba67eded25653e79481 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Tue, 24 Nov 2015 17:33:37 +0100 Subject: [PATCH] Port zonemanager to Python 3 * Replace xrange() with six.moves.range() * Replace filter() with list-comprehension to get a list on Python 3. * get_formatted_wwn(): join byte strings with b':' instead of ':' * ZoneManager: don't pass arguments to object.__new__() * tests-py3.txt: add zonemanager tests Partial-Implements: blueprint cinder-python3 Change-Id: Ia3fcd816c5afd7a08b8769fbc9d2839b70c8c3fb --- .../unit/zonemanager/test_cisco_fc_zone_client_cli.py | 3 ++- .../drivers/brocade/brcd_fc_san_lookup_service.py | 8 ++++---- .../zonemanager/drivers/brocade/brcd_fc_zone_driver.py | 2 +- .../drivers/cisco/cisco_fc_san_lookup_service.py | 8 ++++---- cinder/zonemanager/fc_zone_manager.py | 2 +- tests-py3.txt | 10 ++++++++++ 6 files changed, 22 insertions(+), 11 deletions(-) diff --git a/cinder/tests/unit/zonemanager/test_cisco_fc_zone_client_cli.py b/cinder/tests/unit/zonemanager/test_cisco_fc_zone_client_cli.py index 9e63a9c2b..c5c057c32 100644 --- a/cinder/tests/unit/zonemanager/test_cisco_fc_zone_client_cli.py +++ b/cinder/tests/unit/zonemanager/test_cisco_fc_zone_client_cli.py @@ -19,6 +19,7 @@ import mock from oslo_concurrency import processutils +from six.moves import range from cinder import exception from cinder import test @@ -219,7 +220,7 @@ class TestCiscoFCZoneClientCLI(cli.CiscoFCZoneClientCLI, test.TestCase): expected_num_calls = 5 expected_calls = [] - for i in xrange(expected_num_calls): + for i in range(expected_num_calls): expected_calls.append(mock.call(cmd_list, True)) self.assertEqual(expected_num_calls, run_ssh_mock.call_count) diff --git a/cinder/zonemanager/drivers/brocade/brcd_fc_san_lookup_service.py b/cinder/zonemanager/drivers/brocade/brcd_fc_san_lookup_service.py index 3e4059963..fd79de3f5 100644 --- a/cinder/zonemanager/drivers/brocade/brcd_fc_san_lookup_service.py +++ b/cinder/zonemanager/drivers/brocade/brcd_fc_san_lookup_service.py @@ -139,10 +139,10 @@ class BrcdFCSanLookupService(fc_service.FCSanLookupService): "caller-%s", formatted_initiator_list) LOG.debug("Lookup service:target list from " "caller-%s", formatted_target_list) - visible_targets = filter(lambda x: x in formatted_target_list, - nsinfo) - visible_initiators = filter(lambda x: x in - formatted_initiator_list, nsinfo) + visible_targets = [x for x in nsinfo + if x in formatted_target_list] + visible_initiators = [x for x in nsinfo + if x in formatted_initiator_list] if visible_targets: LOG.debug("Filtered targets is: %s", visible_targets) diff --git a/cinder/zonemanager/drivers/brocade/brcd_fc_zone_driver.py b/cinder/zonemanager/drivers/brocade/brcd_fc_zone_driver.py index 8b8fe227b..e865ea0b8 100644 --- a/cinder/zonemanager/drivers/brocade/brcd_fc_zone_driver.py +++ b/cinder/zonemanager/drivers/brocade/brcd_fc_zone_driver.py @@ -105,7 +105,7 @@ class BrcdFCZoneDriver(fc_zone_driver.FCZoneDriver): if len(wwn_str) != 16: return wwn_str else: - return ':'.join( + return b':'.join( [wwn_str[i:i + 2] for i in range(0, len(wwn_str), 2)]) @lockutils.synchronized('brcd', 'fcfabric-', True) diff --git a/cinder/zonemanager/drivers/cisco/cisco_fc_san_lookup_service.py b/cinder/zonemanager/drivers/cisco/cisco_fc_san_lookup_service.py index 8db7743d2..5edc9ef16 100644 --- a/cinder/zonemanager/drivers/cisco/cisco_fc_san_lookup_service.py +++ b/cinder/zonemanager/drivers/cisco/cisco_fc_san_lookup_service.py @@ -137,10 +137,10 @@ class CiscoFCSanLookupService(fc_service.FCSanLookupService): formatted_initiator_list) LOG.debug("Lookup service:target list from caller-%s", formatted_target_list) - visible_targets = filter(lambda x: x in formatted_target_list, - nsinfo) - visible_initiators = filter(lambda x: x in - formatted_initiator_list, nsinfo) + visible_targets = [x for x in nsinfo + if x in formatted_target_list] + visible_initiators = [x for x in nsinfo + if x in formatted_initiator_list] if visible_targets: LOG.debug("Filtered targets is: %s", visible_targets) diff --git a/cinder/zonemanager/fc_zone_manager.py b/cinder/zonemanager/fc_zone_manager.py index c19565a85..2d598b5fc 100644 --- a/cinder/zonemanager/fc_zone_manager.py +++ b/cinder/zonemanager/fc_zone_manager.py @@ -81,7 +81,7 @@ class ZoneManager(fc_common.FCCommon): def __new__(class_, *args, **kwargs): if not hasattr(class_, "_instance"): - class_._instance = object.__new__(class_, *args, **kwargs) + class_._instance = object.__new__(class_) return class_._instance def __init__(self, **kwargs): diff --git a/tests-py3.txt b/tests-py3.txt index 3305ce77f..a4b71b02d 100644 --- a/tests-py3.txt +++ b/tests-py3.txt @@ -137,3 +137,13 @@ cinder.tests.unit.windows.test_windows cinder.tests.unit.windows.test_windows_remotefs cinder.tests.unit.windows.test_windows_utils cinder.tests.unit.wsgi +cinder.tests.unit.zonemanager.test_brcd_fc_san_lookup_service +cinder.tests.unit.zonemanager.test_brcd_fc_zone_client_cli +cinder.tests.unit.zonemanager.test_brcd_fc_zone_driver +cinder.tests.unit.zonemanager.test_brcd_lookup_service +cinder.tests.unit.zonemanager.test_cisco_fc_san_lookup_service +cinder.tests.unit.zonemanager.test_cisco_fc_zone_client_cli +cinder.tests.unit.zonemanager.test_cisco_fc_zone_driver +cinder.tests.unit.zonemanager.test_cisco_lookup_service +cinder.tests.unit.zonemanager.test_fc_zone_manager +cinder.tests.unit.zonemanager.test_volume_driver -- 2.45.2