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.create_replication_action.return_value = 'action-123'
self.drv.zfssa.send_repl_update.return_value = True 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): def test_migrate_volume(self):
self._util_migrate_volume_exceptions() self._util_migrate_volume_exceptions()

View File

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