提交 f8769a29 编写于 作者: C cuixucui

Code specification rectification

上级 b7d464a9
......@@ -286,7 +286,7 @@ class EulerCertification():
try:
Command("dmidecode").get_str("IPMI Device Information", single_line=False)
sort_devices["ipmi"] = [empty_device]
except:
except OSError as e:
pass
return sort_devices
......@@ -319,7 +319,7 @@ class EulerCertification():
try:
num = int(reply)
except:
except ValueError:
continue
if num > 0 and num <= len(self.test_factory):
......
......@@ -60,7 +60,7 @@ class CertDevice:
properties["INFO"] = attribute
else:
break
except Exception as e:
except OSError as e:
print("Warning: get devices fail")
print(e)
self.devices.sort(key=lambda k: k.path)
......
......@@ -34,7 +34,7 @@ class Document():
with open(self.filename, "w+") as save_f:
json.dump(self.document, save_f, indent=4)
save_f.close()
except Exception as e:
except (IOError, ValueError) as e:
print("Error: doc save fail.")
print(e)
return False
......@@ -46,7 +46,7 @@ class Document():
self.document = json.load(load_f)
load_f.close()
return True
except:
except (IOError, json.decoder.JSONDecodeError):
return False
class CertDocument(Document):
......@@ -74,7 +74,7 @@ class CertDocument(Document):
self.document[key] = value
else:
break
except Exception as e:
except OSError as e:
print("Error: get hardware info fail.")
print(e)
......
......@@ -63,7 +63,7 @@ class Reboot:
try:
Command("systemctl daemon-reload").run_quiet()
Command("systemctl enable oech").run_quiet()
except:
except OSError as e:
print("Error: enable oech.service fail.")
return False
......@@ -81,7 +81,7 @@ class Reboot:
self.job.job_id = self.reboot["job_id"]
self.job.subtests_filter = self.reboot["rebootup"]
time_reboot = datetime.datetime.strptime(self.reboot["time"], "%Y%m%d%H%M%S")
except:
except KeyError:
print("Error: reboot file format not as expect.")
return False
......
......@@ -35,7 +35,7 @@ class SysInfo:
f = open(file)
text = f.read()
f.close()
except:
except IOError:
print("Release file not found.")
return
......
......@@ -13,7 +13,7 @@
# Create: 2020-04-01
from hwcompatible.test import Test
from hwcompatible.command import Command
from hwcompatible.command import Command, CertCommandError
class AcpiTest(Test):
......@@ -26,7 +26,7 @@ class AcpiTest(Test):
try:
Command("acpidump").echo()
return True
except OSError as e:
except CertCommandError as e:
print(e)
return False
......@@ -50,7 +50,7 @@ class DiskTest(Test):
Command("cat /proc/mdstat").echo(ignore_errors=True)
sys.stdout.flush()
print("\n")
except Exception as e:
except CertCommandError as e:
print("Warning: could not get disk info")
print(e)
......@@ -195,7 +195,7 @@ class DiskTest(Test):
if not self.do_fio(path, size, opts):
return_code = False
break
except Exception as e:
except CertCommandError as e:
print(e)
return_code = False
break
......
......@@ -36,7 +36,7 @@ class KdumpTest(Test):
def test(self):
try:
Command("cat /proc/cmdline").get_str(r"crashkernel=[^\ ]*")
except:
except (OSError, ValueError):
print("Error: no crashkernel found.")
return False
......@@ -53,7 +53,7 @@ class KdumpTest(Test):
try:
Command("systemctl restart kdump").run()
Command("systemctl status kdump").get_str(regex="Active: active", single_line=False)
except:
except (OSError, ValueError):
print("Error: kdump service not working.")
return False
......
......@@ -16,7 +16,7 @@ import os
import sys
import argparse
from hwcompatible.test import Test
from hwcompatible.command import Command
from hwcompatible.command import Command, CertCommandError
from hwcompatible.device import CertDevice, Device
......@@ -69,7 +69,7 @@ class NvmeTest(Test):
Command("nvme list").echo(ignore_errors=True)
return True
except Exception as e:
except CertCommandError as e:
print("Error: nvme cmd fail.")
print(e)
return False
......
......@@ -68,7 +68,7 @@ class SystemTest(Test):
sys.stdout.flush()
if rpm_verify.output and len(rpm_verify.output) > 0:
return_code = False
except:
except OSError as err:
print("Error: files in %s have been tampered." % cert_package)
return_code = False
return return_code
......@@ -94,7 +94,7 @@ class SystemTest(Test):
if kernel_dict.document[os_version] != self.sysinfo.kernel_version:
print("Error: kernel %s check GA status fail." % self.sysinfo.kernel_version)
return_code = False
except:
except KeyError:
print("Error: %s is not supported." % os_version)
return_code = False
......@@ -129,7 +129,7 @@ class SystemTest(Test):
print("")
tainted_file.close()
except Exception as e:
except (IOError, ValueError) as e:
print(e)
print("Error: could not determine if kernel is tainted.")
return_code = False
......@@ -142,7 +142,7 @@ class SystemTest(Test):
try:
params = Command("cat /proc/cmdline").get_str()
print("Boot Parameters: %s" % params)
except Exception as e:
except OSError as e:
print(e)
print("Error: could not determine boot parameters.")
return_code = False
......@@ -261,7 +261,7 @@ class SystemTest(Test):
if os.path.islink(modulefile):
modulefile = os.readlink(modulefile)
return modulefile
except:
except OSError:
print("Error: could no find module file for %s:" % module)
return None
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册