Fix vendor info retrieval for some versions of lshw
There is one more place that relies on lshw json output being a dict, so let's fix the function that gets the dict rather than places it is being used in. Change-Id: Ia1c2c2e6a32c76ac0249e6a46e4cced18d6093a9 Task: 39527 Story: 2007588
This commit is contained in:
parent
37dc11fcc1
commit
3761a44800
|
@ -97,7 +97,12 @@ def _get_system_lshw_dict():
|
||||||
:return: A python dict from the lshw json output
|
:return: A python dict from the lshw json output
|
||||||
"""
|
"""
|
||||||
out, _e = utils.execute('lshw', '-quiet', '-json', log_stdout=False)
|
out, _e = utils.execute('lshw', '-quiet', '-json', log_stdout=False)
|
||||||
return json.loads(out)
|
out = json.loads(out)
|
||||||
|
# Depending on lshw version, output might be a list, starting with
|
||||||
|
# https://github.com/lyonel/lshw/commit/135a853c60582b14c5b67e5cd988a8062d9896f4 # noqa
|
||||||
|
if isinstance(out, list):
|
||||||
|
return out[0]
|
||||||
|
return out
|
||||||
|
|
||||||
|
|
||||||
def _udev_settle():
|
def _udev_settle():
|
||||||
|
@ -1143,10 +1148,6 @@ class GenericHardwareManager(HardwareManager):
|
||||||
LOG.warning('Could not get real physical RAM from lshw: %s', e)
|
LOG.warning('Could not get real physical RAM from lshw: %s', e)
|
||||||
physical = None
|
physical = None
|
||||||
else:
|
else:
|
||||||
# Depending on lshw version, output might be a list, starting with
|
|
||||||
# https://github.com/lyonel/lshw/commit/135a853c60582b14c5b67e5cd988a8062d9896f4 # noqa
|
|
||||||
if isinstance(sys_dict, list):
|
|
||||||
sys_dict = sys_dict[0]
|
|
||||||
physical = _calc_memory(sys_dict)
|
physical = _calc_memory(sys_dict)
|
||||||
|
|
||||||
if not physical:
|
if not physical:
|
||||||
|
|
|
@ -4390,6 +4390,14 @@ class TestGenericHardwareManager(base.IronicAgentTest):
|
||||||
self.assertEqual('1234567', vendor_info.serial_number)
|
self.assertEqual('1234567', vendor_info.serial_number)
|
||||||
self.assertEqual('GENERIC', vendor_info.manufacturer)
|
self.assertEqual('GENERIC', vendor_info.manufacturer)
|
||||||
|
|
||||||
|
@mock.patch.object(utils, 'execute', autospec=True)
|
||||||
|
def test_get_system_vendor_info_lshw_list(self, mocked_execute):
|
||||||
|
mocked_execute.return_value = (f"[{LSHW_JSON_OUTPUT_V2[0]}]", "")
|
||||||
|
vendor_info = self.hardware.get_system_vendor_info()
|
||||||
|
self.assertEqual('ABCD', vendor_info.product_name)
|
||||||
|
self.assertEqual('1234', vendor_info.serial_number)
|
||||||
|
self.assertEqual('ABCD', vendor_info.manufacturer)
|
||||||
|
|
||||||
@mock.patch.object(utils, 'execute', autospec=True)
|
@mock.patch.object(utils, 'execute', autospec=True)
|
||||||
def test_get_system_vendor_info_failure(self, mocked_execute):
|
def test_get_system_vendor_info_failure(self, mocked_execute):
|
||||||
mocked_execute.side_effect = processutils.ProcessExecutionError()
|
mocked_execute.side_effect = processutils.ProcessExecutionError()
|
||||||
|
|
Loading…
Reference in New Issue