Refactor dmidecode fact gathering code (#83211)

* Code now bails out early if dmidecode command is unavailable

Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
pull/83278/head
Abhijeet Kasurde 7 months ago committed by GitHub
parent 65638b4d01
commit ac6200b597
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,3 @@
---
bugfixes:
- freebsd - refactor dmidecode fact gathering code for simplicity.

@ -253,18 +253,22 @@ class FreeBSDHardware(Hardware):
'product_version': 'system-version', 'product_version': 'system-version',
'system_vendor': 'system-manufacturer', 'system_vendor': 'system-manufacturer',
} }
if dmi_bin is None:
dmi_facts = dict.fromkeys(
DMI_DICT.keys(),
'NA'
)
return dmi_facts
for (k, v) in DMI_DICT.items(): for (k, v) in DMI_DICT.items():
if dmi_bin is not None: (rc, out, err) = self.module.run_command('%s -s %s' % (dmi_bin, v))
(rc, out, err) = self.module.run_command('%s -s %s' % (dmi_bin, v)) if rc == 0:
if rc == 0: # Strip out commented lines (specific dmidecode output)
# Strip out commented lines (specific dmidecode output) # FIXME: why add the fact and then test if it is json?
# FIXME: why add the fact and then test if it is json? dmi_facts[k] = ''.join([line for line in out.splitlines() if not line.startswith('#')])
dmi_facts[k] = ''.join([line for line in out.splitlines() if not line.startswith('#')]) try:
try: json.dumps(dmi_facts[k])
json.dumps(dmi_facts[k]) except UnicodeDecodeError:
except UnicodeDecodeError:
dmi_facts[k] = 'NA'
else:
dmi_facts[k] = 'NA' dmi_facts[k] = 'NA'
else: else:
dmi_facts[k] = 'NA' dmi_facts[k] = 'NA'

@ -393,20 +393,24 @@ class LinuxHardware(Hardware):
'product_version': 'system-version', 'product_version': 'system-version',
'system_vendor': 'system-manufacturer', 'system_vendor': 'system-manufacturer',
} }
if dmi_bin is None:
dmi_facts = dict.fromkeys(
DMI_DICT.keys(),
'NA'
)
return dmi_facts
for (k, v) in DMI_DICT.items(): for (k, v) in DMI_DICT.items():
if dmi_bin is not None: (rc, out, err) = self.module.run_command('%s -s %s' % (dmi_bin, v))
(rc, out, err) = self.module.run_command('%s -s %s' % (dmi_bin, v)) if rc == 0:
if rc == 0: # Strip out commented lines (specific dmidecode output)
# Strip out commented lines (specific dmidecode output) thisvalue = ''.join([line for line in out.splitlines() if not line.startswith('#')])
thisvalue = ''.join([line for line in out.splitlines() if not line.startswith('#')]) try:
try: json.dumps(thisvalue)
json.dumps(thisvalue) except UnicodeDecodeError:
except UnicodeDecodeError: thisvalue = "NA"
thisvalue = "NA"
dmi_facts[k] = thisvalue dmi_facts[k] = thisvalue
else:
dmi_facts[k] = 'NA'
else: else:
dmi_facts[k] = 'NA' dmi_facts[k] = 'NA'

Loading…
Cancel
Save