]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Can't force-create snapshot by an non-exist error volume
authorlirenke <lvhancy@163.com>
Tue, 4 Mar 2014 12:59:07 +0000 (04:59 -0800)
committerlirenke <lvhancy@163.com>
Wed, 19 Mar 2014 13:52:47 +0000 (06:52 -0700)
If we create an LVM volume whose size larger than
rest space in VG, the volume would not exist with
error status.
But then we still can force create a snapshot
by this volume, and the snapshot's status is available.
In the code,I found in create_lv_snapshot,
it return False when fail to get the volume.
However, raising an exception is only way to be
handle outside.
So, we should raise exception instead of return False.

Closes-Bug: #1283338

Change-Id: I80256f19d66da460c95ff23834abb79a557763bf

cinder/brick/local_dev/lvm.py
cinder/tests/brick/test_brick_lvm.py

index 0c8c10f813aed5ef3872f166cba00e37a5030560..095d79e29e5713e15b09ba54cef04f18d159a976 100644 (file)
@@ -490,8 +490,9 @@ class LVM(executor.Executor):
         """
         source_lvref = self.get_volume(source_lv_name)
         if source_lvref is None:
-            LOG.error(_("Unable to find LV: %s") % source_lv_name)
-            return False
+            LOG.error(_("Trying to create snapshot by non-existent LV: %s")
+                      % source_lv_name)
+            raise exception.VolumeDeviceNotFound(device=source_lv_name)
         cmd = ['lvcreate', '--name', name,
                '--snapshot', '%s/%s' % (self.vg_name, source_lv_name)]
         if lv_type != 'thin':
index a213b96037fa942aaaf572a320ce41e845a222ba..95b37ae1203bd58e33673e7f8da6ed25f0fe6573 100644 (file)
@@ -15,7 +15,7 @@
 
 import mox
 
-
+from cinder.brick import exception
 from cinder.brick.local_dev import lvm as brick
 from cinder.openstack.common import log as logging
 from cinder.openstack.common import processutils
@@ -109,11 +109,27 @@ class BrickLvmTestCase(test.TestCase):
             pass
         elif 'lvcreate, -T, -V, ' in cmd_string:
             pass
+        elif 'lvcreate, --name, ' in cmd_string:
+            pass
         else:
             raise AssertionError('unexpected command called: %s' % cmd_string)
 
         return (data, "")
 
+    def test_create_lv_snapshot(self):
+        self.assertEqual(self.vg.create_lv_snapshot('snapshot-1', 'fake-1'),
+                         None)
+
+        self._mox.StubOutWithMock(self.vg, 'get_volume')
+        self.vg.get_volume('fake-non-existent').AndReturn(None)
+        self._mox.ReplayAll()
+        try:
+            self.vg.create_lv_snapshot('snapshot-1', 'fake-non-existent')
+        except exception.VolumeDeviceNotFound as e:
+            self.assertEqual(e.kwargs['device'], 'fake-non-existent')
+        else:
+            self.fail("Exception not raised")
+
     def test_vg_exists(self):
         self.assertEqual(self.vg._vg_exists(), True)