from cinder.brick import exception
from cinder.brick import executor
-from cinder.i18n import _, _LE, _LW
+from cinder.i18n import _, _LE, _LI, _LW
from cinder.openstack.common import log as logging
:param root_helper: root_helper to use for execute
:param vg_name: optional, gathers info for only the specified VG
+ :param lv_name: optional, gathers info for only the specified LV
:returns: List of Dictionaries with LV info
"""
cmd.append(vg_name)
lvs_start = time.time()
- (out, _err) = putils.execute(*cmd,
- root_helper=root_helper,
- run_as_root=True)
+ try:
+ (out, _err) = putils.execute(*cmd,
+ root_helper=root_helper,
+ run_as_root=True)
+ except putils.ProcessExecutionError as err:
+ with excutils.save_and_reraise_exception(reraise=True) as ctx:
+ if "not found" in err.stderr:
+ ctx.reraise = False
+ msg = _LI("'Not found' when querying LVM info. "
+ "(vg_name=%(vg)s, lv_name=%(lv)s")
+ LOG.info(msg, {'vg': vg_name, 'lv': lv_name})
+ out = None
+
total_time = time.time() - lvs_start
if total_time > 60:
- LOG.warning(_LW('Took %s seconds to get logical volumes.'),
+ LOG.warning(_LW('Took %s seconds to get logical volume info.'),
total_time)
lv_list = []
:returns: dict representation of Logical Volume if exists
"""
- 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)
- )
+ ref_list = self.get_volumes(name)
+ for r in ref_list:
+ if r['name'] == name:
+ return r
return None
@staticmethod
"lWyauW-dKpG-Rz7E-xtKY-jeju-QsYU-SLG7Z2\n"
data += " fake-vg-3:10.00:10.00:0:"\
"mXzbuX-dKpG-Rz7E-xtKY-jeju-QsYU-SLG8Z3\n"
+ elif ('env, LC_ALL=C, lvs, --noheadings, '
+ '--unit=g, -o, vg_name,name,size, --nosuffix, '
+ 'fake-vg/lv-nothere' in cmd_string):
+ raise processutils.ProcessExecutionError(
+ stderr="One or more specified logical volume(s) not found.")
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."
+ stderr="One or more volume(s) not found."
)
data = " fake-vg fake-1 1.00g\n"
data += " fake-vg fake-2 1.00g\n"
def test_get_volume_none(self):
self.assertEqual(self.vg.get_volume('fake-unknown'), None)
+ def test_get_lv_info_notfound(self):
+ self.assertEqual(
+ self.vg.get_lv_info(
+ 'sudo', vg_name='fake-vg', lv_name='lv-nothere'),
+ []
+ )
+
def test_get_all_physical_volumes(self):
# Filtered VG version
pvs = self.vg.get_all_physical_volumes('sudo', 'fake-vg')