]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
attaching volumes will set instance_uuid instantly
authorMike Perez <thingee@gmail.com>
Thu, 29 Nov 2012 11:18:08 +0000 (03:18 -0800)
committerMike Perez <thingee@gmail.com>
Fri, 30 Nov 2012 08:56:58 +0000 (00:56 -0800)
This change allows the instance_uuid field to be set instantly when
beginning an attach action. The user will no longer have to wait for the
attachment to be complete to know what it is attaching to. If attaching
fails on the driver layer, we got error state and keep the instance_uuid
set for troubleshooting purposes.

blueprint instance-attached-field
Change-Id: Ie9860876ab865f766c0ae4cb616a45fd363931f8

cinder/tests/test_volume.py
cinder/volume/api.py

index 513118aae6272465fb93bdcb6b0aac461419d785..35f467afa8b70be3d2d2b38638ed90a90d2983e1 100644 (file)
@@ -274,6 +274,23 @@ class VolumeTestCase(test.TestCase):
                           self.context,
                           volume_id)
 
+    def test_preattach_status_volume(self):
+        """Ensure volume goes into pre-attaching state"""
+
+        instance_uuid = '12345678-1234-5678-1234-567812345678'
+        mountpoint = "/dev/sdf"
+        volume = db.volume_create(self.context, {'size': 1,
+                                                 'status': 'available'})
+        volume_id = volume['id']
+
+        volume_api = cinder.volume.api.API()
+        volume_api.attach(self.context, volume, instance_uuid, mountpoint)
+
+        vol = db.volume_get(self.context, volume_id)
+        self.assertEqual(vol['status'], "attaching")
+        self.assertEqual(vol['attach_status'], None)
+        self.assertEqual(vol['instance_uuid'], instance_uuid)
+
     def test_concurrent_volumes_get_different_targets(self):
         """Ensure multiple concurrent volumes get different targets."""
         volume_ids = []
index 3b53a6dcc75927c194eb68f6ef611733ab5471d6..e96a82dac952f25ca40cd9ff4da85be7301483b6 100644 (file)
@@ -383,6 +383,8 @@ class API(base.Base):
 
     @wrap_check_policy
     def attach(self, context, volume, instance_uuid, mountpoint):
+        self.update(context, volume, {"instance_uuid": instance_uuid,
+                                      "status": "attaching"})
         return self.volume_rpcapi.attach_volume(context,
                                                 volume,
                                                 instance_uuid,