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
This commit is contained in:
David Pineau 2014-11-06 15:01:13 +01:00
parent 37e4a12652
commit f782b9c4fe
2 changed files with 26 additions and 4 deletions

View 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):

View 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')