]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Fix the LV NotFound situation for thin-type LVM
authorDavid Pineau <dav.pineau@gmail.com>
Thu, 6 Nov 2014 14:01:13 +0000 (15:01 +0100)
committerDavid Pineau <dav.pineau@gmail.com>
Mon, 10 Nov 2014 11:49:44 +0000 (12:49 +0100)
If the logical volume is not found, LVM displays on the error output
that the volumes could not be found. So here, we filter on this very
specific situation, and let all the other cases go through the stack.

Added a test for this new code path, which raises an exception of the
proper type to be caught by the new code.

Change-Id: I703af8ccd87c6332d9f88eff63fcf26ebed234f4
Closes-Bug: #1390081

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

index aecdb3c2bbfd7afb2aa59a9253a3bc5075608bb7..50acfe3a0e1e580a5626c1dfe47513268f8bedf0 100644 (file)
@@ -25,9 +25,12 @@ import time
 from cinder.brick import exception
 from cinder.brick import executor
 from cinder.i18n import _
+from cinder.openstack.common import excutils
+from cinder.openstack.common.gettextutils import _LW
 from cinder.openstack.common import log as logging
 from cinder.openstack.common import processutils as putils
 
+
 LOG = logging.getLogger(__name__)
 
 
@@ -284,10 +287,22 @@ class LVM(executor.Executor):
         :returns: dict representation of Logical Volume if exists
 
         """
-        ref_list = self.get_volumes(name)
-        for r in ref_list:
-            if r['name'] == name:
-                return r
+        try:
+            ref_list = self.get_volumes(name)
+            for r in ref_list:
+                if r['name'] == name:
+                    return r
+        except putils.ProcessExecutionError as err:
+            # NOTE(joachim): Catch the "notfound" case from the stderr
+            # in order to let the other errors through.
+            with excutils.save_and_reraise_exception(reraise=True) as ctx:
+                if "not found" in err.stderr:
+                    ctx.reraise = False
+                    LOG.warning(
+                        _LW("Caught exception for lvs 'LV not found': %s")
+                        % (name)
+                    )
+        return None
 
     @staticmethod
     def get_all_physical_volumes(root_helper, vg_name=None):
index 95b37ae1203bd58e33673e7f8da6ed25f0fe6573..11a317d9adbbd6ece20b36d5024d22ca06107de1 100644 (file)
@@ -89,6 +89,10 @@ class BrickLvmTestCase(test.TestCase):
                     "mXzbuX-dKpG-Rz7E-xtKY-jeju-QsYU-SLG8Z3\n"
         elif ('env, LC_ALL=C, lvs, --noheadings, '
               '--unit=g, -o, vg_name,name,size' in cmd_string):
+            if 'fake-unknown' in cmd_string:
+                raise processutils.ProcessExecutionError(
+                    stderr="One of more volume(s) not found."
+                )
             data = "  fake-vg fake-1 1.00g\n"
             data += "  fake-vg fake-2 1.00g\n"
         elif ('env, LC_ALL=C, lvdisplay, --noheading, -C, -o, Attr' in
@@ -147,6 +151,9 @@ class BrickLvmTestCase(test.TestCase):
     def test_get_volume(self):
         self.assertEqual(self.vg.get_volume('fake-1')['name'], 'fake-1')
 
+    def test_get_volume_none(self):
+        self.assertEqual(self.vg.get_volume('fake-unknown'), None)
+
     def test_get_all_physical_volumes(self):
         # Filtered VG version
         pvs = self.vg.get_all_physical_volumes('sudo', 'fake-vg')