]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Prevent create volume from snapshot with bad size
authorJean-Baptiste RANSY <jean-baptiste.ransy@alyseo.com>
Sat, 30 Mar 2013 14:25:29 +0000 (15:25 +0100)
committerJean-Baptiste RANSY <jean-baptiste.ransy@alyseo.com>
Thu, 4 Apr 2013 14:37:25 +0000 (16:37 +0200)
Prevent to create a volume from a snapshot with a volume size less
than the snapshot size.

Check if a volume size is specified that it is less than
the snapshot size.

Raise a exception if it's lesser.

Fixes bug 1161841

Change-Id: Ic1afbfb025ce0b3906c35c6c50a71734d74a9851

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

index 5a06be538fef95a950fa5a62ab51a1693ea00860..b980206fb774f4f16e736ad837f29fc2f868b7fc 100644 (file)
@@ -253,6 +253,20 @@ class VolumeTestCase(test.TestCase):
         self.volume.delete_snapshot(self.context, snapshot_id)
         self.volume.delete_volume(self.context, volume_src['id'])
 
+    def test_create_volume_from_snapshot_fail_bad_size(self):
+        """Test volume can't be created from snapshot with bad volume size."""
+        volume_api = cinder.volume.api.API()
+        snapshot = dict(id=1234,
+                        status='available',
+                        volume_size=10)
+        self.assertRaises(exception.InvalidInput,
+                          volume_api.create,
+                          self.context,
+                          size=1,
+                          name='fake_name',
+                          description='fake_desc',
+                          snapshot=snapshot)
+
     def test_create_volume_with_invalid_exclusive_options(self):
         """Test volume create with multiple exclusive options fails."""
         volume_api = cinder.volume.api.API()
index 995276748cb4e8d15da9398164032e9e5be38588..93a0513246273828a7e35437f58197e6a036cf87 100644 (file)
@@ -104,7 +104,10 @@ class API(base.Base):
                 raise exception.InvalidSnapshot(reason=msg)
             if not size:
                 size = snapshot['volume_size']
-
+            elif size < snapshot['volume_size']:
+                msg = _("Volume size cannot be lesser than"
+                        " the Snapshot size")
+                raise exception.InvalidInput(reason=msg)
             snapshot_id = snapshot['id']
         else:
             snapshot_id = None