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__)
: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):
"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
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')