Fix inventory crash on nvme binary too old or absent (#170)

* When nvme binary absent or too old and no json output, this crash the inventory, i prefer just pass nvme inventory and continue

* log if nvme-cli is not installed
This commit is contained in:
Cyrinux 2020-10-14 12:40:19 +02:00 committed by GitHub
parent 00653628c6
commit 0f2cb531ae
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -88,22 +88,28 @@ class LSHW():
self.disks.append(d)
elif "nvme" in obj["configuration"]["driver"]:
nvme = json.loads(
subprocess.check_output(
["nvme", '-list', '-o', 'json'],
encoding='utf8')
)
if not is_tool('nvme'):
logging.error('nvme-cli >= 1.0 does not seem to be installed')
else:
try:
nvme = json.loads(
subprocess.check_output(
["nvme", '-list', '-o', 'json'],
encoding='utf8')
)
for device in nvme["Devices"]:
d = {}
d['logicalname'] = device["DevicePath"]
d['product'] = device["ModelNumber"]
d['serial'] = device["SerialNumber"]
d["version"] = device["Firmware"]
d['size'] = device["UsedSize"]
d['description'] = "NVME Disk"
for device in nvme["Devices"]:
d = {}
d['logicalname'] = device["DevicePath"]
d['product'] = device["ModelNumber"]
d['serial'] = device["SerialNumber"]
d["version"] = device["Firmware"]
d['size'] = device["UsedSize"]
d['description'] = "NVME Disk"
self.disks.append(d)
self.disks.append(d)
except Exception:
pass
def find_cpus(self, obj):
if "product" in obj: