]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Fix swap_volume for case without migration
authorRyan McNair <rdmcnair@us.ibm.com>
Thu, 19 Nov 2015 19:48:37 +0000 (19:48 +0000)
committerRyan McNair <rdmcnair@us.ibm.com>
Thu, 19 Nov 2015 19:55:38 +0000 (19:55 +0000)
Fix swap_volume so that even when a volume-migration does not
occur, the volumes don't get stuck in "attaching" and "detaching".
Previously the swap_volume was changed in
https://review.openstack.org/#/c/101932 and
https://review.openstack.org/#/c/101933 to move the final
attach and detach logic to Cinder, however those changes only fix
the migration path.  This change calls Cinder's "attach" and "detach"
for the non-migration path to update the volumes' states.

Change-Id: I242c2c7c4a7197bbce04d0b3d75688f989ea1fd5
Closes-Bug: #1489744

cinder/volume/api.py

index 2031c0c78bf45c57f641f6b993754d93880d4456..8dfcf5e3d613547d6c5e37b0dc4ffd75c93bb8a2 100644 (file)
@@ -1405,6 +1405,19 @@ class API(base.Base):
         # This is a volume swap initiated by Nova, not Cinder. Nova expects
         # us to return the new_volume_id.
         if not (volume['migration_status'] or new_volume['migration_status']):
+            # Don't need to do migration, but still need to finish the
+            # volume attach and detach so volumes don't end in 'attaching'
+            # and 'detaching' state
+            attachments = volume['volume_attachment']
+            for attachment in attachments:
+                self.detach(context, volume, attachment['id'])
+
+                self.attach(context, new_volume,
+                            attachment['instance_uuid'],
+                            attachment['attached_host'],
+                            attachment['mountpoint'],
+                            'rw')
+
             return new_volume['id']
 
         if not volume['migration_status']: