]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Removes 3PAR domain option from cinder config file
authorViraj Hardikar <viraj.hardikar@hp.com>
Tue, 25 Jun 2013 22:37:09 +0000 (15:37 -0700)
committerViraj Hardikar <viraj.hardikar@hp.com>
Mon, 1 Jul 2013 18:10:50 +0000 (11:10 -0700)
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
cinder/volume/drivers/san/hp/hp_3par_common.py
cinder/volume/drivers/san/hp/hp_3par_fc.py
cinder/volume/drivers/san/hp/hp_3par_iscsi.py
etc/cinder/cinder.conf.sample

index 1f4dedee7f32339a4b51a4ed0b01e3ef80d528b8..9587cd553fe8e98f2d5aa1373dbe0614e24283d2 100644 (file)
@@ -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)
 
index 2bc879cda54afb11348ffd9dbc03628c97efb42d..0e46253aa4731983e7949cb1897fd4a390b236ea 100644 (file)
@@ -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:
index 1abd291825d51d46b4bbb3d294d679434e31ff57..5b93c54c35d4e3da8d27e33aaa501a4f1fa67bdc 100644 (file)
@@ -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)
 
index 5bec277bdffd9608d22880c9cfd1113d57b973f1..ce158d16bf604815d2602662c91a485fdb108f87 100644 (file)
@@ -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)
 
index 67e84c889de021aefea5535611800f090d431fcf..fbc921d52342b36046de73d7ecb3fc5231872e29 100644 (file)
 # 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)