@@ -69,7 +69,7 @@ class USBNetDevice(NetDevice):
6969
7070 # Now we need to find the corresponding device name in sysfs
7171 if self._find_device() == False:
72- return None
72+ raise RuntimeError("Unable to find USB network device")
7373
7474 def _getname(self, dpath):
7575 for root, dirs, files in os.walk(dpath, topdown=False):
@@ -122,8 +122,7 @@ class HostConfig():
122122 try:
123123 cursor = cursor_consume_next(cursor, "Host IP Assignment Type: ")
124124 if cursor == None:
125- printf("redfish-finder: Unable to parse SMBIOS Host IP Assignment Type")
126- return None
125+ raise RuntimeError("redfish-finder: Unable to parse SMBIOS Host IP Assignment Type")
127126 if cursor.split()[0] == "Static":
128127 self.assigntype = []
129128 self.assigntype.append(AssignType.STATIC)
@@ -151,11 +150,9 @@ class HostConfig():
151150 self.network.append(0)
152151 else:
153152 # Support the other types later
154- print("redfish-finder: Unable to parse SMBIOS Host configuaration")
155- return None
153+ raise RuntimeError("redfish-finder: Unable to parse SMBIOS Host configuaration")
156154 except:
157- print("redfish-finder: Unexpected error while parsing HostConfig!")
158- return None
155+ raise RuntimeError("redfish-finder: Unexpected error while parsing HostConfig!")
159156
160157 def merge(self, newconfig):
161158 self.assigntype.extend(newconfig.assigntype)
@@ -209,8 +206,7 @@ class ServiceConfig():
209206 try:
210207 cursor = cursor_consume_next(cursor, "Redfish Service IP Discovery Type: ")
211208 if cursor == None:
212- print("redfish-finder: Unable to find Redfish Service Info")
213- return None
209+ raise RuntimeError("redfish-finder: Unable to find Redfish Service Info")
214210 if cursor.split()[0] == "Static":
215211 self.assigntype = AssignType.STATIC
216212 cursor = cursor_consume_next(cursor, "Redfish Service IP Address Format: ")
@@ -246,7 +242,7 @@ class ServiceConfig():
246242 else:
247243 self.hostname = ""
248244 except:
249- print ("redfish-finder: Unexpected error parsing ServiceConfig")
245+ raise RuntimeError ("redfish-finder: Unexpected error parsing ServiceConfig")
250246
251247 def merge(self, newconfig):
252248 self.address.extend(newconfig.address)
@@ -272,12 +268,14 @@ class dmiobject():
272268 cursor = dmioutput
273269 # Find the type 42 header, if not found, nothing to do here
274270 cursor = cursor_consume_next(cursor, "Management Controller Host Interface\n")
271+ if cursor == None:
272+ raise RuntimeError("Unable to find Management Controller Host Interface block in SMBIOS")
275273 while (cursor != None):
276274 if (cursor == None):
277- return None
275+ raise RuntimeError("No Redfish Host support detected")
278276 cursor = cursor_consume_next(cursor, "Host Interface Type: Network\n")
279277 if (cursor == None):
280- return None
278+ raise RuntimeError("No supported Redfish host interface type found")
281279
282280 # If we get here then we know this is a network interface device
283281 cursor = cursor_consume_next(cursor, "Device Type: ")
@@ -290,9 +288,6 @@ class dmiobject():
290288 if (dtype == "USB"):
291289 newdev = USBNetDevice(cursor)
292290
293- if newdev == None:
294- return None
295-
296291 if self.device == None:
297292 self.device = newdev
298293 else:
@@ -301,21 +296,16 @@ class dmiobject():
301296 # Now find the Redfish over IP section
302297 cursor = cursor_consume_next(cursor, "Protocol ID: 04 (Redfish over IP)\n")
303298 if (cursor == None):
304- print("redfish-finder: Unable to find Redfish Protocol")
305- return None
299+ raise RuntimeError("No Redfish over IP Protocol support")
306300
307301 newhostconfig = HostConfig(cursor)
308- if newhostconfig == None:
309- return None
310302
311303 if self.hostconfig == None:
312304 self.hostconfig = newhostconfig
313305 else:
314306 self.hostconfig.merge(newhostconfig)
315307
316308 serviceconfig = ServiceConfig(cursor)
317- if serviceconfig == None:
318- return None
319309
320310 if self.serviceconfig == None:
321311 self.serviceconfig = serviceconfig
@@ -417,8 +407,7 @@ class nmConnection():
417407 subprocess.check_call(create)
418408 propstr = subprocess.check_output(["nmcli", "con", "show", ifc.getifcname()])
419409 except:
420- print("redfish-finder: Unexpected error building connection to %s" % self.ifc)
421- return None
410+ raise RuntimeError("redfish-finder: Unexpected error building connection to %s" % self.ifc)
422411
423412 try:
424413 self.properties = {}
@@ -430,8 +419,7 @@ class nmConnection():
430419 continue
431420 self.properties[la[0].strip(":")] = la[1]
432421 except:
433- print("Unexpected error parsing connection for %s" % self.ifc)
434- return None
422+ raise RuntimeError("Unexpected error parsing connection for %s" % self.ifc)
435423
436424 #
437425 # Update a property value in this network manager object
@@ -491,7 +479,10 @@ class nmConnection():
491479 return str(self.properties)
492480
493481def get_info_from_dmidecode():
494- dmioutput = subprocess.check_output(["/usr/sbin/dmidecode", "-t42"])
482+ try:
483+ dmioutput = subprocess.check_output(["/usr/sbin/dmidecode", "-t42"])
484+ except:
485+ raise RuntimeError("Failed to run dmidecode. Make sure you run as root")
495486 return dmiobject(dmioutput.decode())
496487
497488def main():
@@ -500,13 +491,19 @@ def main():
500491 args = parser.parse_args(sys.argv[1:])
501492
502493 print("redfish-finder: Getting dmidecode info")
503- smbios_info = get_info_from_dmidecode()
504- if smbios_info == None:
494+ try:
495+ smbios_info = get_info_from_dmidecode()
496+ except RuntimeError as e:
497+ print("Error parsing dmidecode information: %s\n" % e)
505498 sys.exit(1)
499+
506500 print("redfish-finder: Building NetworkManager connection info")
507- conn = nmConnection(smbios_info.device)
508- if conn == None:
501+ try:
502+ conn = nmConnection(smbios_info.device)
503+ except RuntimeError as e:
504+ print("redfish-finder: Error building nm connection: %s\n" % e)
509505 sys.exit(1)
506+
510507 print("redfish-finder: Obtaining OS config info")
511508 svc = OSServiceData(smbios_info.serviceconfig)
512509 if svc == None:
0 commit comments