From 471bd7924a49d8de840ba378082a5b4e06cf2d34 Mon Sep 17 00:00:00 2001 From: Wilson Liu Date: Tue, 13 Oct 2015 15:19:18 +0800 Subject: [PATCH] Brocade driver add_zone optimization Check whether the new zone we want to add/create has the same zone name and members with the existing zone on the switch. If they are same, no need to delete and re-add it. This is significant if we create volume from image or upload volume to image in batch. Implements: blueprint brocade-add-zone-optimization Change-Id: I257ec25fed9fab4b3a85a0f200c2ee426c8e6f8c --- .../test_brcd_fc_zone_client_cli.py | 32 +++++++++++++++++++ .../brocade/brcd_fc_zone_client_cli.py | 10 ++++-- 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/cinder/tests/unit/zonemanager/test_brcd_fc_zone_client_cli.py b/cinder/tests/unit/zonemanager/test_brcd_fc_zone_client_cli.py index 321349587..3f1c18876 100644 --- a/cinder/tests/unit/zonemanager/test_brcd_fc_zone_client_cli.py +++ b/cinder/tests/unit/zonemanager/test_brcd_fc_zone_client_cli.py @@ -50,6 +50,12 @@ active_zoneset_multiple_zones = { 'openstack50060b0000c26602201900051ee8e327': ['50:06:0b:00:00:c2:66:02', '20:19:00:05:1e:e8:e3:27']}, 'active_zone_config': 'OpenStack_Cfg'} +new_zone_memb_same = { + 'openstack50060b0000c26604201900051ee8e329': + ['50:06:0b:00:00:c2:66:04', '20:19:00:05:1e:e8:e3:29']} +new_zone_memb_not_same = { + 'openstack50060b0000c26604201900051ee8e329': + ['50:06:0b:00:00:c2:66:04', '20:19:00:05:1e:e8:e3:30']} new_zone = {'openstack10000012345678902001009876543210': ['10:00:00:12:34:56:78:90', '20:01:00:98:76:54:32:10']} new_zones = {'openstack10000012345678902001009876543210': @@ -108,6 +114,32 @@ class TestBrcdFCZoneClientCLI(client_cli.BrcdFCZoneClientCLI, test.TestCase): activate_zoneset_mock.assert_called_once_with( active_zoneset['active_zone_config']) + @mock.patch.object(client_cli.BrcdFCZoneClientCLI, 'get_active_zone_set') + @mock.patch.object(client_cli.BrcdFCZoneClientCLI, 'delete_zones') + @mock.patch.object(client_cli.BrcdFCZoneClientCLI, 'activate_zoneset') + @mock.patch.object(client_cli.BrcdFCZoneClientCLI, 'apply_zone_change') + def test_add_zone_exists_memb_same(self, apply_zone_change_mock, + activate_zoneset_mock, + delete_zones_mock, + get_active_zs_mock): + get_active_zs_mock.return_value = active_zoneset + self.add_zones(new_zone_memb_same, True, active_zoneset) + self.assertEqual(0, apply_zone_change_mock.call_count) + self.assertEqual(0, delete_zones_mock.call_count) + + @mock.patch.object(client_cli.BrcdFCZoneClientCLI, 'get_active_zone_set') + @mock.patch.object(client_cli.BrcdFCZoneClientCLI, 'delete_zones') + @mock.patch.object(client_cli.BrcdFCZoneClientCLI, 'activate_zoneset') + @mock.patch.object(client_cli.BrcdFCZoneClientCLI, 'apply_zone_change') + def test_add_zone_exists_memb_not_same(self, apply_zone_change_mock, + activate_zoneset_mock, + delete_zones_mock, + get_active_zs_mock): + get_active_zs_mock.return_value = active_zoneset + self.add_zones(new_zone_memb_not_same, True, active_zoneset) + self.assertEqual(2, apply_zone_change_mock.call_count) + self.assertEqual(1, delete_zones_mock.call_count) + @mock.patch.object(client_cli.BrcdFCZoneClientCLI, '_ssh_execute') def test_activate_zoneset(self, ssh_execute_mock): ssh_execute_mock.return_value = True diff --git a/cinder/zonemanager/drivers/brocade/brcd_fc_zone_client_cli.py b/cinder/zonemanager/drivers/brocade/brcd_fc_zone_client_cli.py index 480fd03ad..1e6174e77 100644 --- a/cinder/zonemanager/drivers/brocade/brcd_fc_zone_client_cli.py +++ b/cinder/zonemanager/drivers/brocade/brcd_fc_zone_client_cli.py @@ -140,9 +140,13 @@ class BrcdFCZoneClientCLI(object): zone_list = active_zone_set[ZoneConstant.CFG_ZONES] LOG.debug("zone list: %s", zone_list) for zone in zones.keys(): - # if zone exists, its an update. Delete & insert - # TODO(skolathur): This can be optimized to an update call later + # If zone exists, its an update. Delete & insert + # TODO(skolathur): This still need to be optimized + # to an update call later. Now we just handled the + # same zone name with same zone members. if (zone in zone_list): + if set(zones[zone]) == set(zone_list[zone]): + break try: self.delete_zones(zone, activate, active_zone_set) except exception.BrocadeZoningCliException: @@ -162,6 +166,8 @@ class BrcdFCZoneClientCLI(object): zone_with_sep += ';' iterator_count += 1 zone_with_sep += zone + if not zone_with_sep: + return try: # Get active zone set from device, as some of the zones # could be deleted. -- 2.45.2