From: Mike Perez Date: Tue, 22 Apr 2014 23:27:42 +0000 (-0700) Subject: Keep volume available if retype fails due to quota X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=3305f9dd061e70736fc4b890a207ecd4d30c3544;p=openstack-build%2Fcinder-build.git Keep volume available if retype fails due to quota If we're over quota for a volume type that we're retyping a volume to, keep the volume available. Closes-Bug: #1308819 Change-Id: I7e66e95bf12b7e5a6df04eeb5a501badb5f2941f --- diff --git a/cinder/tests/test_volume.py b/cinder/tests/test_volume.py index 796320ccc..9d37fcfd6 100644 --- a/cinder/tests/test_volume.py +++ b/cinder/tests/test_volume.py @@ -2305,6 +2305,28 @@ class VolumeTestCase(BaseVolumeTestCase): self.assertEqual(volume['host'], 'newhost') self.assertIsNone(volume['migration_status']) + def test_retype_setup_fail_volume_is_available(self): + """Verify volume is still available if retype prepare failed.""" + elevated = context.get_admin_context() + project_id = self.context.project_id + + db.volume_type_create(elevated, {'name': 'old', 'extra_specs': {}}) + old_vol_type = db.volume_type_get_by_name(elevated, 'old') + db.volume_type_create(elevated, {'name': 'new', 'extra_specs': {}}) + new_vol_type = db.volume_type_get_by_name(elevated, 'new') + db.quota_create(elevated, project_id, 'volumes_new', 0) + + volume = tests_utils.create_volume(self.context, size=1, + host=CONF.host, status='available', + volume_type_id=old_vol_type['id']) + + api = cinder.volume.api.API() + self.assertRaises(exception.VolumeLimitExceeded, api.retype, + self.context, volume, new_vol_type['id']) + + volume = db.volume_get(elevated, volume.id) + self.assertEqual(volume['status'], 'available') + def _retype_volume_exec(self, driver, snap=False, policy='on-demand', migrate_exc=False, exc=None, diff_equal=False): elevated = context.get_admin_context() diff --git a/cinder/volume/api.py b/cinder/volume/api.py index 19cdade7c..088f95c25 100644 --- a/cinder/volume/api.py +++ b/cinder/volume/api.py @@ -933,13 +933,14 @@ class API(base.Base): 'in-use volumes') raise exception.InvalidInput(reason=msg) - self.update(context, volume, {'status': 'retyping'}) - # We're checking here in so that we can report any quota issues as # early as possible, but won't commit until we change the type. We # pass the reservations onward in case we need to roll back. reservations = quota_utils.get_volume_type_reservation(context, volume, vol_type_id) + + self.update(context, volume, {'status': 'retyping'}) + request_spec = {'volume_properties': volume, 'volume_id': volume['id'], 'volume_type': vol_type,