]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Keep volume available if retype fails due to quota
authorMike Perez <thingee@gmail.com>
Tue, 22 Apr 2014 23:27:42 +0000 (16:27 -0700)
committerThomas Goirand <thomas@goirand.fr>
Mon, 9 Jun 2014 14:08:50 +0000 (22:08 +0800)
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
(cherry picked from commit 3305f9dd061e70736fc4b890a207ecd4d30c3544)

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

index 99752f6596daa3bfd4cfeb48c42a977d1f2ccea7..f85a0fe22bb4ad5fea0795e12944c97f90d28bb9 100644 (file)
@@ -2306,6 +2306,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()
index 19cdade7cf77721c9440513530dab98bcce0cc4c..088f95c250d61e7e364088d7cf7df720cc01bfa9 100644 (file)
@@ -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,