From d863510ca97a2ea1ff8e0a81a5f41c0cd1fe3670 Mon Sep 17 00:00:00 2001 From: Viraj Hardikar Date: Tue, 25 Jun 2013 15:37:09 -0700 Subject: [PATCH] Removes 3PAR domain option from cinder config file The HP 3PAR domain is no longer required to be specified in the cinder configuration file. This patch automatically looks up the domain using the Common Provisioning Group (CPG) specified. hp3par_domain will remain in the config for now and will be logged as deprecated. It will be removed in the I release. DocImpact Change-Id: I3ed01eed26209caa1904bec1f585059860294f38 Fixes: bug 1194599 --- cinder/tests/test_hp3par.py | 22 ++++++++++-- .../volume/drivers/san/hp/hp_3par_common.py | 35 +++++++++++++++---- cinder/volume/drivers/san/hp/hp_3par_fc.py | 5 +-- cinder/volume/drivers/san/hp/hp_3par_iscsi.py | 5 +-- etc/cinder/cinder.conf.sample | 2 +- 5 files changed, 54 insertions(+), 15 deletions(-) diff --git a/cinder/tests/test_hp3par.py b/cinder/tests/test_hp3par.py index 1f4dedee7..9587cd553 100644 --- a/cinder/tests/test_hp3par.py +++ b/cinder/tests/test_hp3par.py @@ -336,6 +336,9 @@ class HP3PARBaseDriver(): def fake_create_client(self): return FakeHP3ParClient(self.driver.configuration.hp3par_api_url) + def fake_get_domain(self, cpg): + return HP3PAR_DOMAIN + def fake_get_3par_host(self, hostname): if hostname not in self._hosts: msg = {'code': 'NON_EXISTENT_HOST', @@ -433,7 +436,6 @@ class TestHP3PARFCDriver(HP3PARBaseDriver, test.TestCase): configuration.hp3par_username = 'testUser' configuration.hp3par_password = 'testPassword' configuration.hp3par_api_url = 'https://1.1.1.1/api/v1' - configuration.hp3par_domain = HP3PAR_DOMAIN configuration.hp3par_cpg = HP3PAR_CPG configuration.hp3par_cpg_snap = HP3PAR_CPG_SNAP configuration.iscsi_ip_address = '1.1.1.2' @@ -457,6 +459,8 @@ class TestHP3PARFCDriver(HP3PARBaseDriver, test.TestCase): self.fake_create_3par_vlun) self.stubs.Set(hpdriver.hpcommon.HP3PARCommon, "get_ports", self.fake_get_ports) + self.stubs.Set(hpfcdriver.hpcommon.HP3PARCommon, "get_domain", + self.fake_get_domain) self.configuration = configuration @@ -491,7 +495,6 @@ class TestHP3PARFCDriver(HP3PARBaseDriver, test.TestCase): 'id': 11, 'name': hostname} self._hosts[hostname] = host - self.properties = {'data': {'target_discovered': True, 'target_lun': 186, @@ -575,6 +578,8 @@ class TestHP3PARFCDriver(HP3PARBaseDriver, test.TestCase): #record self.stubs.UnsetAll() + self.stubs.Set(hpfcdriver.hpcommon.HP3PARCommon, "get_domain", + self.fake_get_domain) _run_ssh = self.mox.CreateMock(hpdriver.hpcommon.HP3PARCommon._run_ssh) self.stubs.Set(hpdriver.hpcommon.HP3PARCommon, "_run_ssh", _run_ssh) @@ -596,6 +601,8 @@ class TestHP3PARFCDriver(HP3PARBaseDriver, test.TestCase): #record self.stubs.UnsetAll() + self.stubs.Set(hpdriver.hpcommon.HP3PARCommon, "get_domain", + self.fake_get_domain) _run_ssh = self.mox.CreateMock(hpdriver.hpcommon.HP3PARCommon._run_ssh) self.stubs.Set(hpdriver.hpcommon.HP3PARCommon, "_run_ssh", _run_ssh) @@ -621,6 +628,8 @@ class TestHP3PARFCDriver(HP3PARBaseDriver, test.TestCase): #record self.stubs.UnsetAll() + self.stubs.Set(hpdriver.hpcommon.HP3PARCommon, "get_domain", + self.fake_get_domain) _run_ssh = self.mox.CreateMock(hpdriver.hpcommon.HP3PARCommon._run_ssh) self.stubs.Set(hpdriver.hpcommon.HP3PARCommon, "_run_ssh", _run_ssh) @@ -654,7 +663,6 @@ class TestHP3PARISCSIDriver(HP3PARBaseDriver, test.TestCase): configuration.hp3par_username = 'testUser' configuration.hp3par_password = 'testPassword' configuration.hp3par_api_url = 'https://1.1.1.1/api/v1' - configuration.hp3par_domain = HP3PAR_DOMAIN configuration.hp3par_cpg = HP3PAR_CPG configuration.hp3par_cpg_snap = HP3PAR_CPG_SNAP configuration.iscsi_ip_address = '1.1.1.2' @@ -682,6 +690,8 @@ class TestHP3PARISCSIDriver(HP3PARBaseDriver, test.TestCase): self.fake_delete_3par_host) self.stubs.Set(hpdriver.hpcommon.HP3PARCommon, "_create_3par_vlun", self.fake_create_3par_vlun) + self.stubs.Set(hpdriver.hpcommon.HP3PARCommon, "get_domain", + self.fake_get_domain) self.driver = hpdriver.HP3PARISCSIDriver(configuration=configuration) self.driver.do_setup(None) @@ -803,6 +813,8 @@ class TestHP3PARISCSIDriver(HP3PARBaseDriver, test.TestCase): #record self.stubs.UnsetAll() + self.stubs.Set(hpdriver.hpcommon.HP3PARCommon, "get_domain", + self.fake_get_domain) _run_ssh = self.mox.CreateMock(hpdriver.hpcommon.HP3PARCommon._run_ssh) self.stubs.Set(hpdriver.hpcommon.HP3PARCommon, "_run_ssh", _run_ssh) @@ -825,6 +837,8 @@ class TestHP3PARISCSIDriver(HP3PARBaseDriver, test.TestCase): #record self.stubs.UnsetAll() + self.stubs.Set(hpdriver.hpcommon.HP3PARCommon, "get_domain", + self.fake_get_domain) _run_ssh = self.mox.CreateMock(hpdriver.hpcommon.HP3PARCommon._run_ssh) self.stubs.Set(hpdriver.hpcommon.HP3PARCommon, "_run_ssh", _run_ssh) @@ -850,6 +864,8 @@ class TestHP3PARISCSIDriver(HP3PARBaseDriver, test.TestCase): #record self.stubs.UnsetAll() + self.stubs.Set(hpdriver.hpcommon.HP3PARCommon, "get_domain", + self.fake_get_domain) _run_ssh = self.mox.CreateMock(hpdriver.hpcommon.HP3PARCommon._run_ssh) self.stubs.Set(hpdriver.hpcommon.HP3PARCommon, "_run_ssh", _run_ssh) diff --git a/cinder/volume/drivers/san/hp/hp_3par_common.py b/cinder/volume/drivers/san/hp/hp_3par_common.py index 2bc879cda..0e46253aa 100644 --- a/cinder/volume/drivers/san/hp/hp_3par_common.py +++ b/cinder/volume/drivers/san/hp/hp_3par_common.py @@ -74,9 +74,11 @@ hp3par_opts = [ default='', help="3PAR Super user password", secret=True), + #TODO(kmartin): Remove hp3par_domain during I release. cfg.StrOpt('hp3par_domain', - default="OpenStack", - help="The 3par domain name to use"), + default=None, + help="This option is DEPRECATED and no longer used. " + "The 3par domain name to use."), cfg.StrOpt('hp3par_cpg', default="OpenStack", help="The CPG to use for volume creation"), @@ -124,6 +126,10 @@ class HP3PARCommon(object): self.config = config self.hosts_naming_dict = dict() self.client = None + if CONF.hp3par_domain is not None: + LOG.deprecated(_("hp3par_domain has been deprecated and " + "is no longer used. The domain is automatically " + "looked up based on the CPG.")) def check_flags(self, options, required_flags): for flag in required_flags: @@ -169,14 +175,21 @@ class HP3PARCommon(object): LOG.error(err) raise exception.InvalidInput(reason=err) - if ('domain' not in cpg - or cpg['domain'] != self.config.hp3par_domain): - err = ("CPG's domain '%s' and config option hp3par_domain '%s'" - " must be the same" % - (cpg['domain'], self.config.hp3par_domain)) + def get_domain(self, cpg_name): + try: + cpg = self.client.getCPG(cpg_name) + except hpexceptions.HTTPNotFound: + err = (_("CPG (%s) doesn't exist on array.") % cpg_name) LOG.error(err) raise exception.InvalidInput(reason=err) + domain = cpg['domain'] + if not domain: + err = (_("CPG (%s) must be in a domain") % cpg_name) + LOG.error(err) + raise exception.InvalidInput(reason=err) + return domain + def _get_3par_vol_name(self, volume_id): """ Converts the openstack volume id from @@ -681,6 +694,14 @@ exit word = re.search(search_string.strip(' ') + ' ([^ ]*)', s) return word.groups()[0].strip(' ') + def get_volume_metadata_value(self, volume, key): + metadata = volume.get('volume_metadata') + if metadata: + for i in volume['volume_metadata']: + if i['key'] == key: + return i['value'] + return None + def create_cloned_volume(self, volume, src_vref): try: diff --git a/cinder/volume/drivers/san/hp/hp_3par_fc.py b/cinder/volume/drivers/san/hp/hp_3par_fc.py index 1abd29182..5b93c54c3 100644 --- a/cinder/volume/drivers/san/hp/hp_3par_fc.py +++ b/cinder/volume/drivers/san/hp/hp_3par_fc.py @@ -217,6 +217,8 @@ class HP3PARFCDriver(cinder.volume.driver.FibreChannelDriver): """Creates or modifies existing 3PAR host.""" host = None hostname = self.common._safe_hostname(connector['host']) + cpg = self.common.get_volume_metadata_value(volume, 'CPG') + domain = self.common.get_domain(cpg) try: host = self.common._get_3par_host(hostname) if not host['FCPaths']: @@ -228,8 +230,7 @@ class HP3PARFCDriver(cinder.volume.driver.FibreChannelDriver): # host doesn't exist, we have to create it hostname = self._create_3par_fibrechan_host(hostname, connector['wwpns'], - self.configuration. - hp3par_domain, + domain, persona_id) host = self.common._get_3par_host(hostname) diff --git a/cinder/volume/drivers/san/hp/hp_3par_iscsi.py b/cinder/volume/drivers/san/hp/hp_3par_iscsi.py index 5bec277bd..ce158d16b 100644 --- a/cinder/volume/drivers/san/hp/hp_3par_iscsi.py +++ b/cinder/volume/drivers/san/hp/hp_3par_iscsi.py @@ -238,6 +238,8 @@ class HP3PARISCSIDriver(cinder.volume.driver.ISCSIDriver): # make sure we don't have the host already host = None hostname = self.common._safe_hostname(connector['host']) + cpg = self.common.get_volume_metadata_value(volume, 'CPG') + domain = self.common.get_domain(cpg) try: host = self.common._get_3par_host(hostname) if not host['iSCSIPaths']: @@ -249,8 +251,7 @@ class HP3PARISCSIDriver(cinder.volume.driver.ISCSIDriver): # host doesn't exist, we have to create it hostname = self._create_3par_iscsi_host(hostname, connector['initiator'], - self.configuration. - hp3par_domain, + domain, persona_id) host = self.common._get_3par_host(hostname) diff --git a/etc/cinder/cinder.conf.sample b/etc/cinder/cinder.conf.sample index 67e84c889..fbc921d52 100644 --- a/etc/cinder/cinder.conf.sample +++ b/etc/cinder/cinder.conf.sample @@ -1116,7 +1116,7 @@ # 3PAR Super user password (string value) #hp3par_password= -# The 3par domain name to use (string value) +# The 3par domain name to use (string value)-DEPRECATED #hp3par_domain=OpenStack # The CPG to use for volume creation (string value) -- 2.45.2