]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Add exception catch if Storwize/SVC driver failed when
authorLi Min Liu <liminliu@cn.ibm.com>
Fri, 11 Apr 2014 02:50:24 +0000 (10:50 +0800)
committerJay S. Bryant <jsbryant@us.ibm.com>
Tue, 15 Apr 2014 16:29:15 +0000 (11:29 -0500)
retyping

If adding a copy for a volume of Storwize/SVC which is under
migration, Storwize/SVC command will fail because the
number of the copies of the volume exceed the limit which
is 2.

Modifying the volume type when adding a copy for the volume,
Storwize/SVC driver will also fail, should add exception catch.

Also add exception catch when getting the volume from the database.
This change is necessary to enable resolving bug 1305550
(https://bugs.launchpad.net/cinder/+bug/1305550 - Failed retype with
driver raised exception should set volume status to "error" ).

Change-Id: I1cf4b6606b5228c8adcb2bde21f345fa979bc13e
Closes-Bug: #1298201

cinder/volume/drivers/ibm/storwize_svc/__init__.py
cinder/volume/drivers/ibm/storwize_svc/helpers.py

index eb0f589556671d6dc6a7aeab2317899cdbb5fc6d..9011bc8d16a83bf8fa70ec56aa5689e821064f4c 100644 (file)
@@ -628,7 +628,16 @@ class StorwizeSVCDriver(san.SanDriver):
         ctxt = context.get_admin_context()
         copy_items = self._vdiskcopyops.items()
         for vol_id, copy_ops in copy_items:
-            volume = self.db.volume_get(ctxt, vol_id)
+            try:
+                volume = self.db.volume_get(ctxt, vol_id)
+            except Exception:
+                LOG.warn(_('Volume %s does not exist.'), vol_id)
+                del self._vdiskcopyops[vol_id]
+                if not len(self._vdiskcopyops):
+                    self._vdiskcopyops_loop.stop()
+                    self._vdiskcopyops_loop = None
+                continue
+
             for copy_op in copy_ops:
                 try:
                     synced = self._helpers.is_vdisk_copy_synced(volume['name'],
@@ -675,6 +684,7 @@ class StorwizeSVCDriver(san.SanDriver):
         else:
             vol_type = None
 
+        self._check_volume_copy_ops()
         new_op = self._helpers.add_vdisk_copy(volume['name'], dest_pool,
                                               vol_type, self._state,
                                               self.configuration)
@@ -696,6 +706,11 @@ class StorwizeSVCDriver(san.SanDriver):
                      host['host'] is its name, and host['capabilities'] is a
                      dictionary of its reported capabilities.
         """
+        def retype_iogrp_property(volume, new, old):
+            if new != old:
+                self._helpers.change_vdisk_iogrp(volume['name'],
+                                                 self._state, (new, old))
+
         LOG.debug(_('enter: retype: id=%(id)s, new_type=%(new_type)s,'
                     'diff=%(diff)s, host=%(host)s') % {'id': volume['id'],
                                                        'new_type': new_type,
@@ -725,24 +740,27 @@ class StorwizeSVCDriver(san.SanDriver):
             need_copy = True
 
         if need_copy:
+            self._check_volume_copy_ops()
             dest_pool = self._helpers.can_migrate_to_host(host, self._state)
             if dest_pool is None:
                 return False
 
-            if old_opts['iogrp'] != new_opts['iogrp']:
-                self._helpers.change_vdisk_iogrp(volume['name'], self._state,
-                                                 (new_opts['iogrp'],
-                                                  old_opts['iogrp']))
-
-            new_op = self._helpers.add_vdisk_copy(volume['name'], dest_pool,
-                                                  new_type, self._state,
-                                                  self.configuration)
-            self._add_vdisk_copy_op(ctxt, volume, new_op)
+            retype_iogrp_property(volume, new_opts['iogrp'], old_opts['iogrp'])
+            try:
+                new = self._helpers.add_vdisk_copy(volume['name'], dest_pool,
+                                                   new_type, self._state,
+                                                   self.configuration)
+                self._add_vdisk_copy_op(ctxt, volume, new)
+            except exception.VolumeDriverException:
+                # roll back changing iogrp property
+                retype_iogrp_property(volume, old_opts['iogrp'],
+                                      new_opts['iogrp'])
+                msg = (_('Unable to retype:  A copy of volume %s exists. '
+                         'Retyping would exceed the limit of 2 copies.'),
+                       volume['id'])
+                raise exception.VolumeDriverException(message=msg)
         else:
-            if old_opts['iogrp'] != new_opts['iogrp']:
-                self._helpers.change_vdisk_iogrp(volume['name'], self._state,
-                                                 (new_opts['iogrp'],
-                                                  old_opts['iogrp']))
+            retype_iogrp_property(volume, new_opts['iogrp'], old_opts['iogrp'])
 
             self._helpers.change_vdisk_options(volume['name'], vdisk_changes,
                                                new_opts, self._state)
index b973c45844deae6473677b829f8e081c767ba50e..558117526a43ef9094d9d465ec910e4782b55cbb 100644 (file)
@@ -681,12 +681,13 @@ class StorwizeHelpers(object):
 
     def add_vdisk_copy(self, vdisk, dest_pool, volume_type, state, config):
         """Add a vdisk copy in the given pool."""
-        this_pool = config.storwize_svc_volpool_name
         resp = self.ssh.lsvdiskcopy(vdisk)
-        orig_copy_id = None
-        for copy_id, mdisk_grp in resp.select('copy_id', 'mdisk_grp_name'):
-            if mdisk_grp == this_pool:
-                orig_copy_id = copy_id
+        if len(resp) > 1:
+            msg = (_('add_vdisk_copy failed: A copy of volume %s exists. '
+                     'Adding another copy would exceed the limit of '
+                     '2 copies.') % vdisk)
+            raise exception.VolumeDriverException(message=msg)
+        orig_copy_id = resp[0].get("copy_id", None)
 
         if orig_copy_id is None:
             msg = (_('add_vdisk_copy started without a vdisk copy in the '