Browse Source

Add empty check before using zone driver

When initiator_target_map is {}, it really means we don't need to
do anything with zone driver.

Change-Id: I1cb1e7b38fb24624d5a0aeb9d5f31e4b008128a9
changes/98/636098/4
yenai 3 years ago
parent
commit
6f93d64ff0
  1. 18
      cinder/tests/fake_driver.py
  2. 24
      cinder/tests/unit/zonemanager/test_volume_driver.py
  3. 4
      cinder/zonemanager/utils.py

18
cinder/tests/fake_driver.py

@ -249,6 +249,15 @@ class FakeFibreChannelDriver(driver.FibreChannelDriver):
fczm_utils.add_fc_zone(conn_info)
return conn_info
def initialize_connection_with_empty_map(self, volume, connector):
conn_info = {
'driver_volume_type': 'fibre_channel',
'data': {
'initiator_target_map': {},
}}
fczm_utils.add_fc_zone(conn_info)
return conn_info
def no_zone_initialize_connection(self, volume, connector):
"""This shouldn't call the ZM."""
conn_info = {
@ -268,6 +277,15 @@ class FakeFibreChannelDriver(driver.FibreChannelDriver):
fczm_utils.remove_fc_zone(conn_info)
return conn_info
def terminate_connection_with_empty_map(self, volume, connector, **kwargs):
conn_info = {
'driver_volume_type': 'fibre_channel',
'data': {
'initiator_target_map': {},
}}
fczm_utils.remove_fc_zone(conn_info)
return conn_info
def no_zone_terminate_connection(self, volume, connector, **kwargs):
conn_info = {
'driver_volume_type': 'bogus',

24
cinder/tests/unit/zonemanager/test_volume_driver.py

@ -55,6 +55,18 @@ class TestVolumeDriver(test.TestCase):
conn_info = self.driver.initialize_connection(None, None)
add_zone_mock.assert_called_once_with(conn_info)
@mock.patch('cinder.zonemanager.utils.create_zone_manager')
@mock.patch('oslo_config.cfg._is_opt_registered', return_value=False)
@mock.patch.object(utils, 'require_driver_initialized')
def test_initialize_connection_with_decorator_and_empty_map(
self, utils_mock, opt_mock, zm_create_mock):
utils_mock.return_value = True
with mock.patch.object(fc_zone_manager.ZoneManager, 'add_connection')\
as add_zone_mock:
self.driver.initialize_connection_with_empty_map(None, None)
zm_create_mock.assert_not_called()
add_zone_mock.assert_not_called()
@mock.patch.object(utils, 'require_driver_initialized')
def test_initialize_connection_no_decorator(self, utils_mock):
utils_mock.return_value = True
@ -78,6 +90,18 @@ class TestVolumeDriver(test.TestCase):
conn_info = self.driver.terminate_connection(None, None)
remove_zone_mock.assert_called_once_with(conn_info)
@mock.patch('cinder.zonemanager.utils.create_zone_manager')
@mock.patch('oslo_config.cfg._is_opt_registered', return_value=False)
@mock.patch.object(utils, 'require_driver_initialized')
def test_terminate_connection_with_decorator_and_empty_map(
self, utils_mock, opt_mock, zm_create_mock):
utils_mock.return_value = True
with mock.patch.object(fc_zone_manager.ZoneManager,
'delete_connection') as remove_zone_mock:
self.driver.terminate_connection_with_empty_map(None, None)
zm_create_mock.assert_not_called()
remove_zone_mock.assert_not_called()
@mock.patch.object(utils, 'require_driver_initialized')
def test_terminate_connection_no_decorator(self, utils_mock):
utils_mock.return_value = True

4
cinder/zonemanager/utils.py

@ -78,7 +78,7 @@ def add_fc_zone(connection_info):
if connection_info:
vol_type = connection_info.get('driver_volume_type', None)
if vol_type == 'fibre_channel':
if 'initiator_target_map' in connection_info['data']:
if connection_info['data'].get('initiator_target_map'):
zm = create_zone_manager()
if zm:
LOG.debug("add_fc_zone connection info: %(conninfo)s.",
@ -91,7 +91,7 @@ def remove_fc_zone(connection_info):
if connection_info:
vol_type = connection_info.get('driver_volume_type', None)
if vol_type == 'fibre_channel':
if 'initiator_target_map' in connection_info['data']:
if connection_info['data'].get('initiator_target_map'):
zm = create_zone_manager()
if zm:
LOG.debug("remove_fc_zone connection info: %(conninfo)s.",

Loading…
Cancel
Save