Skip to content

Commit

Permalink
Removes 3PAR domain option from cinder config file
Browse files Browse the repository at this point in the history
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
  • Loading branch information
viraj-hp committed Jul 1, 2013
1 parent e102c28 commit d863510
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 15 deletions.
22 changes: 19 additions & 3 deletions cinder/tests/test_hp3par.py
Expand Up @@ -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',
Expand Down Expand Up @@ -433,7 +436,6 @@ def setUp(self):
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'
Expand All @@ -457,6 +459,8 @@ def setUp(self):
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

Expand Down Expand Up @@ -491,7 +495,6 @@ def fake_create_3par_fibrechan_host(self, hostname, wwn,
'id': 11,
'name': hostname}
self._hosts[hostname] = host

self.properties = {'data':
{'target_discovered': True,
'target_lun': 186,
Expand Down Expand Up @@ -575,6 +578,8 @@ def test_create_host(self):

#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)

Expand All @@ -596,6 +601,8 @@ def test_create_invalid_host(self):

#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)

Expand All @@ -621,6 +628,8 @@ def test_create_modify_host(self):

#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)

Expand Down Expand Up @@ -654,7 +663,6 @@ def setUp(self):
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'
Expand Down Expand Up @@ -682,6 +690,8 @@ def setUp(self):
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)
Expand Down Expand Up @@ -803,6 +813,8 @@ def test_create_host(self):

#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)

Expand All @@ -825,6 +837,8 @@ def test_create_invalid_host(self):

#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)

Expand All @@ -850,6 +864,8 @@ def test_create_modify_host(self):

#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)

Expand Down
35 changes: 28 additions & 7 deletions cinder/volume/drivers/san/hp/hp_3par_common.py
Expand Up @@ -74,9 +74,11 @@
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"),
Expand Down Expand Up @@ -124,6 +126,10 @@ def __init__(self, config):
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:
Expand Down Expand Up @@ -169,14 +175,21 @@ def validate_cpg(self, cpg_name):
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
Expand Down Expand Up @@ -681,6 +694,14 @@ def get_next_word(self, s, search_string):
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:
Expand Down
5 changes: 3 additions & 2 deletions cinder/volume/drivers/san/hp/hp_3par_fc.py
Expand Up @@ -217,6 +217,8 @@ def _create_host(self, volume, connector):
"""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']:
Expand All @@ -228,8 +230,7 @@ def _create_host(self, volume, connector):
# 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)

Expand Down
5 changes: 3 additions & 2 deletions cinder/volume/drivers/san/hp/hp_3par_iscsi.py
Expand Up @@ -238,6 +238,8 @@ def _create_host(self, volume, connector):
# 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']:
Expand All @@ -249,8 +251,7 @@ def _create_host(self, volume, connector):
# 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)

Expand Down
2 changes: 1 addition & 1 deletion etc/cinder/cinder.conf.sample
Expand Up @@ -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)
Expand Down

0 comments on commit d863510

Please sign in to comment.