]> 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)
committerMike Perez <thingee@gmail.com>
Tue, 22 Apr 2014 23:34:08 +0000 (16:34 -0700)
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

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

index 796320ccc266d29c145d5828b83d18d13357d7c3..9d37fcfd6f1bf0827b200dc8906df844e0f3c4d4 100644 (file)
@@ -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()
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,