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 94e9ece90..5191204c0 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 @@ -96,7 +96,7 @@ class TestBrcdFCZoneClientCLI(client_cli.BrcdFCZoneClientCLI, test.TestCase): get_active_zs_mock): get_active_zs_mock.return_value = active_zoneset self.add_zones(new_zones, False, None) - self.assertEqual(2, get_active_zs_mock.call_count) + self.assertEqual(1, get_active_zs_mock.call_count) self.assertEqual(3, apply_zone_change_mock.call_count) cfg_save_mock.assert_called_once_with() @@ -138,6 +138,22 @@ class TestBrcdFCZoneClientCLI(client_cli.BrcdFCZoneClientCLI, test.TestCase): self.assertEqual(2, apply_zone_change_mock.call_count) self.assertEqual(1, 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_all_exists_memb_not_same(self, apply_zone_change_mock, + activate_zoneset_mock, + delete_zones_mock, + get_active_zs_mock): + + self.add_zones(new_zone_memb_not_same, True, active_zoneset) + call_args = apply_zone_change_mock.call_args[0][0] + self.assertEqual(0, get_active_zs_mock.call_count) + self.assertEqual(2, apply_zone_change_mock.call_count) + self.assertEqual(1, delete_zones_mock.call_count) + self.assertTrue('cfgcreate' in call_args) + @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 817e294d1..51ba3ecc0 100644 --- a/cinder/zonemanager/drivers/brocade/brcd_fc_zone_client_cli.py +++ b/cinder/zonemanager/drivers/brocade/brcd_fc_zone_client_cli.py @@ -139,6 +139,7 @@ class BrcdFCZoneClientCLI(object): active_zone_set = self.get_active_zone_set() LOG.debug("Active zone set: %s", active_zone_set) zone_list = active_zone_set[zone_constant.CFG_ZONES] + zone_updated = [] LOG.debug("zone list: %s", zone_list) for zone in zones.keys(): # If zone exists, its an update. Delete & insert @@ -150,6 +151,7 @@ class BrcdFCZoneClientCLI(object): break try: self.delete_zones(zone, activate, active_zone_set) + zone_updated.append(zone) except exception.BrocadeZoningCliException: with excutils.save_and_reraise_exception(): LOG.error(_LE("Deleting zone failed %s"), zone) @@ -170,10 +172,12 @@ class BrcdFCZoneClientCLI(object): if not zone_with_sep: return try: - # Get active zone set from device, as some of the zones - # could be deleted. - active_zone_set = self.get_active_zone_set() - cfg_name = active_zone_set[zone_constant.ACTIVE_ZONE_CONFIG] + # If all existing zones are to be updated, the active zone config + # will require a recreate, since all zones have been deleted. + if len(zone_list) == len(zone_updated): + cfg_name = None + else: + cfg_name = active_zone_set[zone_constant.ACTIVE_ZONE_CONFIG] cmd = None if not cfg_name: cfg_name = zone_constant.OPENSTACK_CFG_NAME