]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Brocade driver add_zone optimization
authorWilson Liu <liuxinguo@huawei.com>
Tue, 13 Oct 2015 07:19:18 +0000 (15:19 +0800)
committerWilson Liu <liuxinguo@huawei.com>
Tue, 27 Oct 2015 01:15:17 +0000 (09:15 +0800)
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

cinder/tests/unit/zonemanager/test_brcd_fc_zone_client_cli.py
cinder/zonemanager/drivers/brocade/brcd_fc_zone_client_cli.py

index 321349587eda12f62be1f200af7fc2866bf193fd..3f1c188769de6ceaa9f78136ba3494ff4763283b 100644 (file)
@@ -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
index 480fd03adf81d0f4119d09f077ec91dcb4c69125..1e6174e772e388658f66c0089f5ec0f98685f15d 100644 (file)
@@ -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.