Merge "zfssaiscsi driver initiator group option processing"

This commit is contained in:
Jenkins 2017-07-14 03:07:04 +00:00 committed by Gerrit Code Review
commit 48b58580b6
2 changed files with 54 additions and 24 deletions

View File

@ -192,6 +192,33 @@ class TestZFSSAISCSIDriver(test.TestCase):
self.drv.zfssa.create_replication_action.return_value = 'action-123'
self.drv.zfssa.send_repl_update.return_value = True
@mock.patch.object(iscsi.LOG, 'warning')
@mock.patch.object(iscsi.LOG, 'error')
@mock.patch.object(iscsi, 'factory_zfssa')
def test_parse_initiator_config(self, _factory_zfssa, elog, wlog):
"""Test the parsing of the old style initator config variables. """
lcfg = self.configuration
with mock.patch.object(lcfg, 'zfssa_initiator_config', ''):
# Test empty zfssa_initiator_group
with mock.patch.object(lcfg, 'zfssa_initiator_group', ''):
self.assertRaises(exception.InvalidConfigurationValue,
self.drv.do_setup, {})
# Test empty zfssa_initiator with zfssa_initiator_group set to
# a value other than "default"
with mock.patch.object(lcfg, 'zfssa_initiator', ''):
self.assertRaises(exception.InvalidConfigurationValue,
self.drv.do_setup, {})
# Test zfssa_initiator_group set to 'default' with non-empty
# zfssa_initiator.
with mock.patch.object(lcfg, 'zfssa_initiator_group', 'default'):
self.drv.do_setup({})
wlog.assert_called_with(mock.ANY,
{'inigrp': lcfg.zfssa_initiator_group,
'ini': lcfg.zfssa_initiator})
def test_migrate_volume(self):
self._util_migrate_volume_exceptions()

View File

@ -195,36 +195,39 @@ class ZFSSAISCSIDriver(driver.ISCSIDriver):
else:
LOG.warning('zfssa_initiator_config not found. '
'Using deprecated configuration options.')
if not lcfg.zfssa_initiator_group:
LOG.error('zfssa_initiator_group cannot be empty. '
'Explicitly set the value "default" to use '
'the default initiator group.')
raise exception.InvalidConfigurationValue(
value='', option='zfssa_initiator_group')
if (not lcfg.zfssa_initiator and
(not lcfg.zfssa_initiator_group and
lcfg.zfssa_initiator_group != 'default')):
lcfg.zfssa_initiator_group != 'default'):
LOG.error('zfssa_initiator cannot be empty when '
'creating a zfssa_initiator_group.')
raise exception.InvalidConfigurationValue(
value='',
option='zfssa_initiator')
value='', option='zfssa_initiator')
if (lcfg.zfssa_initiator != '' and
(lcfg.zfssa_initiator_group == '' or
lcfg.zfssa_initiator_group == 'default')):
LOG.warning('zfssa_initiator: %(ini)s will not be used on '
'zfssa_initiator_group= %(inigrp)s.',
{'ini': lcfg.zfssa_initiator,
'inigrp': lcfg.zfssa_initiator_group})
if lcfg.zfssa_initiator != '':
if lcfg.zfssa_initiator_group == 'default':
LOG.warning('zfssa_initiator: %(ini)s wont be used on '
'zfssa_initiator_group= %(inigrp)s.',
{'ini': lcfg.zfssa_initiator,
'inigrp': lcfg.zfssa_initiator_group})
# Setup initiator and initiator group
if (lcfg.zfssa_initiator != '' and
lcfg.zfssa_initiator_group != '' and
lcfg.zfssa_initiator_group != 'default'):
for initiator in lcfg.zfssa_initiator.split(','):
initiator = initiator.strip()
self.zfssa.create_initiator(
initiator,
lcfg.zfssa_initiator_group + '-' + initiator,
chapuser=lcfg.zfssa_initiator_user,
chapsecret=lcfg.zfssa_initiator_password)
self.zfssa.add_to_initiatorgroup(
initiator, lcfg.zfssa_initiator_group)
# Setup initiator and initiator group
else:
for initiator in lcfg.zfssa_initiator.split(','):
initiator = initiator.strip()
self.zfssa.create_initiator(
initiator,
lcfg.zfssa_initiator_group + '-' + initiator,
chapuser=lcfg.zfssa_initiator_user,
chapsecret=lcfg.zfssa_initiator_password)
self.zfssa.add_to_initiatorgroup(
initiator, lcfg.zfssa_initiator_group)
# Parse interfaces
interfaces = []