From e27b171883c1b87b8d2fdf0994947d4b93e640d9 Mon Sep 17 00:00:00 2001 From: Mike Perez Date: Thu, 29 Nov 2012 03:18:08 -0800 Subject: [PATCH] attaching volumes will set instance_uuid instantly 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 | 17 +++++++++++++++++ cinder/volume/api.py | 2 ++ 2 files changed, 19 insertions(+) diff --git a/cinder/tests/test_volume.py b/cinder/tests/test_volume.py index 513118aae..35f467afa 100644 --- a/cinder/tests/test_volume.py +++ b/cinder/tests/test_volume.py @@ -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 = [] diff --git a/cinder/volume/api.py b/cinder/volume/api.py index 3b53a6dcc..e96a82dac 100644 --- a/cinder/volume/api.py +++ b/cinder/volume/api.py @@ -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, -- 2.45.2