]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Fix snapshot id for snapshot_destroy
authorXing Yang <xing.yang@emc.com>
Sun, 3 Aug 2014 13:33:28 +0000 (09:33 -0400)
committerXing Yang <xing.yang@emc.com>
Wed, 6 Aug 2014 14:49:26 +0000 (10:49 -0400)
The id passed to snapshot_destroy should be snapshot['id'],
not volume['id'].

CCLA SCHEDULE B SUBMISSION

Change-Id: I1d84f1d596ebf014c0e3ea4202902ff515b3172a
Closes-Bug: 1351997

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

index eafd097433ba267fa24f2ea3f17c4a424ec07844..b4f3174418cb9c13589fdc651e729944e9c468f7 100644 (file)
@@ -1678,6 +1678,42 @@ class VolumeTestCase(BaseVolumeTestCase):
                           self.context,
                           snapshot_id)
 
+    @mock.patch.object(db, 'snapshot_create',
+                       side_effect=exception.InvalidSnapshot(
+                           'Create snapshot in db failed!'))
+    def test_create_snapshot_failed_db_snapshot(self, mock_snapshot):
+        """Test exception handling when create snapshot in db failed."""
+        test_volume = tests_utils.create_volume(
+            self.context,
+            **self.volume_params)
+        self.volume.create_volume(self.context, test_volume['id'])
+        test_volume['status'] = 'available'
+        volume_api = cinder.volume.api.API()
+        self.assertRaises(exception.InvalidSnapshot,
+                          volume_api.create_snapshot,
+                          self.context,
+                          test_volume,
+                          'fake_name',
+                          'fake_description')
+
+    @mock.patch.object(QUOTAS, 'commit',
+                       side_effect=exception.QuotaError(
+                           'Snapshot quota commit failed!'))
+    def test_create_snapshot_failed_quota_commit(self, mock_snapshot):
+        """Test exception handling when snapshot quota commit failed."""
+        test_volume = tests_utils.create_volume(
+            self.context,
+            **self.volume_params)
+        self.volume.create_volume(self.context, test_volume['id'])
+        test_volume['status'] = 'available'
+        volume_api = cinder.volume.api.API()
+        self.assertRaises(exception.QuotaError,
+                          volume_api.create_snapshot,
+                          self.context,
+                          test_volume,
+                          'fake_name',
+                          'fake_description')
+
     def test_cannot_delete_volume_in_use(self):
         """Test volume can't be deleted in invalid stats."""
         # create a volume and assign to host
index 89355772e5f909bdc726d6edce931b2eceb36a98..42437d0848cacb7c83b43642d33770452d1b36bf 100644 (file)
@@ -524,13 +524,15 @@ class API(base.Base):
                    'encryption_key_id': volume['encryption_key_id'],
                    'metadata': metadata}
 
+        snapshot = None
         try:
             snapshot = self.db.snapshot_create(context, options)
             QUOTAS.commit(context, reservations)
         except Exception:
             with excutils.save_and_reraise_exception():
                 try:
-                    self.db.snapshot_destroy(context, volume['id'])
+                    if snapshot:
+                        self.db.snapshot_destroy(context, snapshot['id'])
                 finally:
                     QUOTAS.rollback(context, reservations)