From 3ffb34e8e92d0aa7e23a470695627434455c9858 Mon Sep 17 00:00:00 2001 From: Rushi Agrawal Date: Sun, 18 Jan 2015 12:23:32 +0530 Subject: [PATCH] EQLX: Consolidate CHAP config options In order to reduce configuration option bloat, it would be a good exercise to consolidate configuration options which many drivers implement under their own distinct name but have same functionality. Here, a first attempt is made to consolidate CHAP configuration options. Dell's EQLSanISCSIDriver is made to use these new set of configuration options 'use_chap_auth', 'chap_username' and 'chap_password' instead of the driver-specific options 'eqlx_use_chap', 'eqlx_chap_login' and 'eqlx_chap_password' respectively in this patch. More drivers are to be added in the future. DocImpact: Config options of Dell EQLSanISCSIDriver are changed Change-Id: I5c51301653ad0f76ce0550e12177ad08f20290e0 Partial-Bug: 1398976 --- cinder/tests/test_eqlx.py | 15 ++++++----- cinder/volume/driver.py | 21 ++++++++++++--- cinder/volume/drivers/eqlx.py | 49 +++++++++++++++++++++++++---------- 3 files changed, 61 insertions(+), 24 deletions(-) diff --git a/cinder/tests/test_eqlx.py b/cinder/tests/test_eqlx.py index 6ef37a1cd..b5fb350cf 100644 --- a/cinder/tests/test_eqlx.py +++ b/cinder/tests/test_eqlx.py @@ -50,12 +50,15 @@ class DellEQLSanISCSIDriverTestCase(test.TestCase): self.configuration.ssh_max_pool_conn = 5 self.configuration.ssh_conn_timeout = 30 self.configuration.eqlx_pool = 'non-default' - self.configuration.eqlx_use_chap = True self.configuration.eqlx_group_name = 'group-0' self.configuration.eqlx_cli_timeout = 30 self.configuration.eqlx_cli_max_retries = 5 - self.configuration.eqlx_chap_login = 'admin' - self.configuration.eqlx_chap_password = 'password' + + self.configuration.eqlx_use_chap = False + self.configuration.use_chap_auth = True + self.configuration.chap_username = 'admin' + self.configuration.chap_password = 'password' + self._context = context.get_admin_context() self.driver = eqlx.DellEQLSanISCSIDriver( configuration=self.configuration) @@ -82,8 +85,8 @@ class DellEQLSanISCSIDriverTestCase(test.TestCase): 'provider_location': "%s:3260,1 %s 0" % (self.driver._group_ip, self.fake_iqn), 'provider_auth': 'CHAP %s %s' % ( - self.configuration.eqlx_chap_login, - self.configuration.eqlx_chap_password) + self.configuration.chap_username, + self.configuration.chap_password) } def _fake_get_iscsi_properties(self, volume): @@ -206,7 +209,7 @@ class DellEQLSanISCSIDriverTestCase(test.TestCase): self.connector['initiator'], 'authmethod', 'chap', 'username', - self.configuration.eqlx_chap_login) + self.configuration.chap_username) self.mox.ReplayAll() iscsi_properties = self.driver.initialize_connection(volume, self.connector) diff --git a/cinder/volume/driver.py b/cinder/volume/driver.py index eb9cd552b..92456b8ff 100644 --- a/cinder/volume/driver.py +++ b/cinder/volume/driver.py @@ -36,6 +36,11 @@ from cinder.volume import utils as volume_utils LOG = logging.getLogger(__name__) + +deprecated_use_chap_auth_opts = [cfg.DeprecatedOpt('eqlx_use_chap')] +deprecated_chap_username_opts = [cfg.DeprecatedOpt('eqlx_chap_login')] +deprecated_chap_password_opts = [cfg.DeprecatedOpt('eqlx_chap_password')] + volume_opts = [ cfg.IntOpt('num_shell_tries', default=3, @@ -165,12 +170,20 @@ volume_opts = [ default='iscsi', help='SCST target implementation can choose from multiple ' 'SCST target drivers.'), + cfg.BoolOpt('use_chap_auth', + default=False, + help='Option to enable/disable CHAP authentication for ' + 'targets.', + deprecated_opts=deprecated_use_chap_auth_opts), cfg.StrOpt('chap_username', - default=None, - help='CHAP username to use for iSCSI Targets'), + default='', + help='CHAP user name.', + deprecated_opts=deprecated_chap_username_opts), cfg.StrOpt('chap_password', - default=None, - help='CHAP password to use for iSCSI Targets'), + default='', + help='Password for specified CHAP account name.', + deprecated_opts=deprecated_chap_password_opts, + secret=True), ] # for backward compatibility diff --git a/cinder/volume/drivers/eqlx.py b/cinder/volume/drivers/eqlx.py index 6e4704173..b2388cb93 100644 --- a/cinder/volume/drivers/eqlx.py +++ b/cinder/volume/drivers/eqlx.py @@ -48,15 +48,22 @@ eqlx_opts = [ help='Maximum retry count for reconnection. Default is 5.'), cfg.BoolOpt('eqlx_use_chap', default=False, - help='Use CHAP authentication for targets. Defaults to ' - '"False".'), + help='Use CHAP authentication for targets. Note that this ' + 'option is deprecated in favour of "use_chap_auth" as ' + 'specified in cinder/volume/driver.py and will be ' + 'removed in next release.'), cfg.StrOpt('eqlx_chap_login', default='admin', - help='Existing CHAP account name. Defaults to "admin".'), + help='Existing CHAP account name. Note that this ' + 'option is deprecated in favour of "chap_username" as ' + 'specified in cinder/volume/driver.py and will be ' + 'removed in next release.'), cfg.StrOpt('eqlx_chap_password', default='password', - help='Password for specified CHAP account name. Defaults ' - 'to "password".', + help='Password for specified CHAP account name. Note that this ' + 'option is deprecated in favour of "chap_password" as ' + 'specified in cinder/volume/driver.py and will be ' + 'removed in the next release', secret=True), cfg.StrOpt('eqlx_pool', default='default', @@ -117,9 +124,9 @@ class DellEQLSanISCSIDriver(SanISCSIDriver): In order to use target CHAP authentication (which is disabled by default) SAN administrator must create a local CHAP user and specify the following flags for the driver: - eqlx_use_chap=true - eqlx_chap_login= - eqlx_chap_password= + use_chap_auth=True + chap_login= + chap_password= eqlx_group_name parameter actually represents the CLI prompt message without '>' ending. E.g. if prompt looks like 'group-0>', then the @@ -129,7 +136,7 @@ class DellEQLSanISCSIDriver(SanISCSIDriver): eqlx_cli_timeout= """ - VERSION = "1.0.0" + VERSION = "1.1.0" def __init__(self, *args, **kwargs): super(DellEQLSanISCSIDriver, self).__init__(*args, **kwargs) @@ -137,6 +144,20 @@ class DellEQLSanISCSIDriver(SanISCSIDriver): self._group_ip = None self.sshpool = None + if self.configuration.eqlx_use_chap is True: + LOG.warning(_LW( + 'Configuration options eqlx_use_chap, ' + 'eqlx_chap_login and eqlx_chap_password are deprecated. Use ' + 'use_chap_auth, chap_username and chap_password ' + 'respectively for the same.')) + + self.configuration.use_chap_auth = \ + self.configuration.eqlx_use_chap + self.configuration.chap_username = \ + self.configuration.eqlx_chap_login + self.configuration.chap_password = \ + self.configuration.eqlx_chap_password + def _get_output(self, chan): out = '' ending = '%s> ' % self.configuration.eqlx_group_name @@ -256,10 +277,10 @@ class DellEQLSanISCSIDriver(SanISCSIDriver): lun_id = "%s:%s,1 %s 0" % (self._group_ip, '3260', target_name) model_update = {} model_update['provider_location'] = lun_id - if self.configuration.eqlx_use_chap: + if self.configuration.use_chap_auth: model_update['provider_auth'] = 'CHAP %s %s' % \ - (self.configuration.eqlx_chap_login, - self.configuration.eqlx_chap_password) + (self.configuration.chap_username, + self.configuration.chap_password) return model_update def _get_space_in_gb(self, val): @@ -460,9 +481,9 @@ class DellEQLSanISCSIDriver(SanISCSIDriver): try: cmd = ['volume', 'select', volume['name'], 'access', 'create', 'initiator', connector['initiator']] - if self.configuration.eqlx_use_chap: + if self.configuration.use_chap_auth: cmd.extend(['authmethod', 'chap', 'username', - self.configuration.eqlx_chap_login]) + self.configuration.chap_username]) self._eql_execute(*cmd) iscsi_properties = self._get_iscsi_properties(volume) return { -- 2.45.2