]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Fixes the 3PAR drivers CPG validation
authorKurt Martin <kurt.f.martin@hp.com>
Mon, 3 Dec 2012 02:25:23 +0000 (18:25 -0800)
committerKurt Martin <kurt.f.martin@hp.com>
Mon, 3 Dec 2012 22:15:57 +0000 (14:15 -0800)
The 3PAR drivers were not checking if the Common Provisioning
Group(CPG) exists in the virtual domain at volume create time when
the default was being overwritten by volume type extra_specs value.
It was also reporting the default CPG in the metadata returning
after creating the volume. Now it reporting the correct CPG and
setting the correct snapshot cpg if different from the default
or not set.

Fixes bug 1186427

Change-Id: Idef7a4f29854c82980789786f2414e5046c8d8fb

cinder/volume/drivers/san/hp/hp_3par_common.py

index 0df0843e3244ca3ae7d8a2b0084423ee728e83ea..e99f94388cb436169d88e3cf0a49c84b5fe1e6c6 100644 (file)
@@ -146,25 +146,28 @@ class HP3PARCommon(object):
 
         self.client_login()
 
-        # make sure the CPG exists
         try:
-            cpg = self.client.getCPG(self.config.hp3par_cpg)
+            # make sure the default CPG exists
+            self.validate_cpg(self.config.hp3par_cpg)
+        finally:
+            self.client_logout()
+
+    def validate_cpg(self, cpg_name):
+        try:
+            cpg = self.client.getCPG(cpg_name)
         except hpexceptions.HTTPNotFound as ex:
-            err = (_("CPG (%s) doesn't exist on array")
-                   % self.config.hp3par_cpg)
+            err = (_("CPG (%s) doesn't exist on array") % cpg_name)
             LOG.error(err)
             raise exception.InvalidInput(reason=err)
 
         if ('domain' not in cpg
-            and cpg['domain'] != self.config.hp3par_domain):
+            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))
             LOG.error(err)
             raise exception.InvalidInput(reason=err)
 
-        self.client_logout()
-
     def _get_3par_vol_name(self, volume_id):
         """
         Converts the openstack volume id from
@@ -567,6 +570,23 @@ exit
 
             cpg = self._get_volume_type_value(volume_type, 'cpg',
                                               self.config.hp3par_cpg)
+            if cpg is not self.config.hp3par_cpg:
+                # The cpg was specified in a volume type extra spec so it
+                # needs to be validiated that it's in the correct domain.
+                self.validate_cpg(cpg)
+                # Also, look to see if the snap_cpg was specified in volume
+                # type extra spec, if not use the extra spec cpg as the
+                # default.
+                snap_cpg = self._get_volume_type_value(volume_type,
+                                                       'snap_cpg', cpg)
+            else:
+                # default snap_cpg to hp3par_cpg_snap if it's not specified
+                # in the volume type extra specs.
+                snap_cpg = self.config.hp3par_cpg_snap
+                # if it's still not set or empty then set it to the cpg
+                # specified in the cinder.conf file.
+                if not self.config.hp3par_cpg_snap:
+                    snap_cpg = cpg
 
             # if provisioning is not set use thin
             default_prov = self.valid_prov_values[0]
@@ -585,15 +605,6 @@ exit
             if prov_value == "full":
                 ttpv = False
 
-            # default to hp3par_cpg if hp3par_cpg_snap is not set.
-            if self.config.hp3par_cpg_snap == "":
-                snap_default = self.config.hp3par_cpg
-            else:
-                snap_default = self.config.hp3par_cpg_snap
-            snap_cpg = self._get_volume_type_value(volume_type,
-                                                   'snap_cpg',
-                                                   snap_default)
-
             # check for valid persona even if we don't use it until
             # attach time, this will given end user notice that the
             # persona type is invalid at volume creation time
@@ -624,7 +635,7 @@ exit
             LOG.error(str(ex))
             raise exception.CinderException(ex.get_description())
 
-        metadata = {'3ParName': volume_name, 'CPG': self.config.hp3par_cpg,
+        metadata = {'3ParName': volume_name, 'CPG': cpg,
                     'snapCPG': extras['snapCPG']}
         return metadata