Clean up device fact gathering

Remove lots of re use that really shouldn't have been re in the first
place. Initialize pcidata even if lspci is unavailable, and check for
its usability before trying to use it.

Fixes #2060.
reviewable/pr18780/r1
Daniel Hokka Zakrisson 12 years ago
parent 81cf3aa02c
commit 2402bae9ea

18
setup

@ -380,6 +380,8 @@ class LinuxHardware(Hardware):
lspci = module.get_bin_path('lspci') lspci = module.get_bin_path('lspci')
if lspci: if lspci:
rc, pcidata, err = module.run_command(lspci) rc, pcidata, err = module.run_command(lspci)
else:
pcidata = None
try: try:
block_devs = os.listdir("/sys/block") block_devs = os.listdir("/sys/block")
@ -397,19 +399,18 @@ class LinuxHardware(Hardware):
sysfs_no_links = 1 sysfs_no_links = 1
else: else:
continue continue
if re.search("virtual", path): if "virtual" in path:
continue continue
sysdir = os.path.join("/sys/block", path) sysdir = os.path.join("/sys/block", path)
if sysfs_no_links == 1: if sysfs_no_links == 1:
for folder in os.listdir(sysdir): for folder in os.listdir(sysdir):
if re.search("device", folder): if "device" in folder:
virtual = 0 virtual = 0
break break
if virtual: if virtual:
continue continue
d = {} d = {}
m = re.match(".*/(.+)$", sysdir) diskname = os.path.basename(sysdir)
diskname = m.group(1)
for key in ['vendor', 'model']: for key in ['vendor', 'model']:
d[key] = get_file_content(sysdir + "/device/" + key) d[key] = get_file_content(sysdir + "/device/" + key)
@ -448,8 +449,8 @@ class LinuxHardware(Hardware):
d['size'] = module.pretty_bytes(float(d['sectors']) * float(d['sectorsize'])) d['size'] = module.pretty_bytes(float(d['sectors']) * float(d['sectorsize']))
d['host'] = "" d['host'] = ""
m = re.match(".+/\d+:(\w+:\w+\.\w)/host\d+/\s*", sysdir) m = re.match(".+/[a-f0-9]+:([a-f0-9]+:[a-f0-9]+\.[a-f0-9]+)/host\d+/", sysdir)
if m: if m and pcidata:
pciid = m.group(1) pciid = m.group(1)
did = re.escape(pciid) did = re.escape(pciid)
m = re.search("^" + did + "\s(.*)$", pcidata, re.MULTILINE) m = re.search("^" + did + "\s(.*)$", pcidata, re.MULTILINE)
@ -457,8 +458,9 @@ class LinuxHardware(Hardware):
d['holders'] = [] d['holders'] = []
for folder in os.listdir(sysdir + "/holders"): for folder in os.listdir(sysdir + "/holders"):
if re.search("^dm-.*", folder): if not folder.startswith("dm-"):
name = get_file_content(sysdir + "/holders/" + folder + "/dm/name") continue
name = get_file_content(sysdir + "/holders/" + folder + "/dm/name")
if name: if name:
d['holders'].append(name) d['holders'].append(name)
else: else:

Loading…
Cancel
Save