diff options
author | Jenkins <jenkins@review.openstack.org> | 2015-04-06 13:40:26 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2015-04-06 13:40:26 +0000 |
commit | f8b6feb5eb9bcf41a68ad516da520b79559faa4c (patch) | |
tree | 0b24640a3bb3786fe269e833043aa0d50d5c5d51 | |
parent | c5cb524967c0088040c52d404d5787d74aea4136 (diff) | |
parent | 909a4eb2fd5411f11e57c2589fc786611cdeda57 (diff) | |
download | cinder-f8b6feb5eb9bcf41a68ad516da520b79559faa4c.tar.gz |
Merge "Check volume status in detach db api"
-rw-r--r-- | cinder/db/sqlalchemy/api.py | 4 | ||||
-rw-r--r-- | cinder/tests/test_volume.py | 25 |
2 files changed, 28 insertions, 1 deletions
diff --git a/cinder/db/sqlalchemy/api.py b/cinder/db/sqlalchemy/api.py index 5fc00640b..4707a8c5b 100644 --- a/cinder/db/sqlalchemy/api.py +++ b/cinder/db/sqlalchemy/api.py @@ -1215,7 +1215,9 @@ def volume_detached(context, volume_id, attachment_id): volume_ref = _volume_get(context, volume_id, session=session) if not remain_attachment: # Hide status update from user if we're performing volume migration - if not volume_ref['migration_status']: + # or uploading it to image + if (not volume_ref['migration_status'] and + not (volume_ref['status'] == 'uploading')): volume_ref['status'] = 'available' volume_ref['attach_status'] = 'detached' diff --git a/cinder/tests/test_volume.py b/cinder/tests/test_volume.py index 41cd59947..f622a324e 100644 --- a/cinder/tests/test_volume.py +++ b/cinder/tests/test_volume.py @@ -2433,6 +2433,31 @@ class VolumeTestCase(BaseVolumeTestCase): self.assertEqual('readonly', admin_metadata[0]['key']) self.assertEqual('True', admin_metadata[0]['value']) + def test_detach_volume_while_uploading_to_image_is_in_progress(self): + # If instance is booted from volume with 'Terminate on Delete' flag + # set, and when we delete instance then it tries to delete volume + # even it is in 'uploading' state. + # It is happening because detach call is setting volume status to + # 'available'. + mountpoint = "/dev/sdf" + # Attach volume to the instance + instance_uuid = '12345678-1234-5678-1234-567812345678' + volume = tests_utils.create_volume(self.context, + admin_metadata={'readonly': 'True'}, + **self.volume_params) + volume_id = volume['id'] + self.volume.create_volume(self.context, volume_id) + self.volume.attach_volume(self.context, volume_id, instance_uuid, + None, mountpoint, 'ro') + # Change volume status to 'uploading' + db.volume_update(self.context, volume_id, {'status': 'uploading'}) + # Call detach api + self.volume.detach_volume(self.context, volume_id) + vol = db.volume_get(self.context, volume_id) + # Check that volume status is 'uploading' + self.assertEqual("uploading", vol['status']) + self.assertEqual("detached", vol['attach_status']) + @mock.patch.object(cinder.volume.api.API, 'update') @mock.patch.object(db, 'volume_get') def test_reserve_volume_success(self, volume_get, volume_update): |