From f782b9c4fe1aaa6ffb455dd2ef4ea9c14bc6ca69 Mon Sep 17 00:00:00 2001 From: David Pineau Date: Thu, 6 Nov 2014 15:01:13 +0100 Subject: [PATCH] Fix the LV NotFound situation for thin-type LVM 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 | 23 +++++++++++++++++++---- cinder/tests/brick/test_brick_lvm.py | 7 +++++++ 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/cinder/brick/local_dev/lvm.py b/cinder/brick/local_dev/lvm.py index aecdb3c2b..50acfe3a0 100644 --- a/cinder/brick/local_dev/lvm.py +++ b/cinder/brick/local_dev/lvm.py @@ -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): diff --git a/cinder/tests/brick/test_brick_lvm.py b/cinder/tests/brick/test_brick_lvm.py index 95b37ae12..11a317d9a 100644 --- a/cinder/tests/brick/test_brick_lvm.py +++ b/cinder/tests/brick/test_brick_lvm.py @@ -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') -- 2.45.2