From b3e872d460d0942e06788d057332ca7fe491fbc5 Mon Sep 17 00:00:00 2001 From: cuixucui <350255958@qq.com> Date: Tue, 16 Jun 2020 16:47:12 +0800 Subject: [PATCH 01/10] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=BC=96=E7=A0=81?= =?UTF-8?q?=E8=A7=84=E8=8C=83=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/misc.xml | 7 + .idea/modules.xml | 8 + .idea/oec-hardware.iml | 12 ++ .idea/vcs.xml | 6 + .idea/workspace.xml | 376 ++++++++++++++++++++++++++++++++++++++++ hwcompatible/command.py | 4 +- server/server.py | 63 ++++--- tests/acpi/acpi.py | 2 +- tests/cdrom/cdrom.py | 30 ++-- tests/disk/disk.py | 2 +- tests/ipmi/ipmi.py | 6 +- tests/kdump/kdump.py | 8 +- tests/memory/memory.py | 8 +- tests/system/system.py | 2 +- 14 files changed, 471 insertions(+), 63 deletions(-) create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/oec-hardware.iml create mode 100644 .idea/vcs.xml create mode 100644 .idea/workspace.xml diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..7da51bc --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..e6eb0b6 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/oec-hardware.iml b/.idea/oec-hardware.iml new file mode 100644 index 0000000..7c9d48f --- /dev/null +++ b/.idea/oec-hardware.iml @@ -0,0 +1,12 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..c65076c --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,376 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + CertCommandError + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - 1592261845556 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file -- Gitee From 837e64887859e55c31916a82b9929ce521835666 Mon Sep 17 00:00:00 2001 From: cuixucui <350255958@qq.com> Date: Thu, 18 Jun 2020 11:05:38 +0800 Subject: [PATCH 03/10] =?UTF-8?q?=E7=BC=96=E7=A0=81=E8=A7=84=E8=8C=83?= =?UTF-8?q?=E6=95=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/misc.xml | 7 + .idea/modules.xml | 8 + .idea/oec-hardware.iml | 12 ++ .idea/vcs.xml | 6 + .idea/workspace.xml | 364 ++++++++++++++++++++++++++++++++++ hwcompatible/compatibility.py | 10 +- server/server.py | 46 ++--- 7 files changed, 425 insertions(+), 28 deletions(-) create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/oec-hardware.iml create mode 100644 .idea/vcs.xml create mode 100644 .idea/workspace.xml diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..7da51bc --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..e6eb0b6 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/oec-hardware.iml b/.idea/oec-hardware.iml new file mode 100644 index 0000000..7c9d48f --- /dev/null +++ b/.idea/oec-hardware.iml @@ -0,0 +1,12 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..67b8a26 --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,364 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + CertCommandError + cert_id + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - 1592261845556 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file -- Gitee From d4afcbc51e745edae12993c4c44fb97081a709d0 Mon Sep 17 00:00:00 2001 From: cuixucui <350255958@qq.com> Date: Fri, 19 Jun 2020 06:38:44 +0800 Subject: [PATCH 05/10] =?UTF-8?q?=E8=A7=A3=E5=86=B3id=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E4=B8=8D=E5=88=B0=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hwcompatible/command.py | 2 +- hwcompatible/compatibility.py | 5 +++-- server/server.py | 12 ++++++------ tests/memory/memory.py | 1 + tests/system/system.py | 8 ++++---- 5 files changed, 15 insertions(+), 13 deletions(-) diff --git a/hwcompatible/command.py b/hwcompatible/command.py index aa6810f..ab850f8 100755 --- a/hwcompatible/command.py +++ b/hwcompatible/command.py @@ -124,7 +124,7 @@ class Command: if self.pipe: return self.pipe.poll() - def _get_str(self, regex=None, regex_group=None, single_line=True, return_list=False, ignore_errors=False): + def _get_str(self, regex=None, regex_group=None, single_line=True, return_list=False): self.regex = regex self.single_line = single_line self.regex_group = regex_group diff --git a/hwcompatible/compatibility.py b/hwcompatible/compatibility.py index 09576cc..f7221d6 100755 --- a/hwcompatible/compatibility.py +++ b/hwcompatible/compatibility.py @@ -146,6 +146,7 @@ class EulerCertification(): def submit(self): packages = list() pattern = re.compile("^oech-[0-9]{14}-[0-9a-zA-Z]{10}.tar$") + files = [] for (root, dirs, files) in os.walk(CertEnv.datadirectory): break packages.extend(filter(pattern.search, files)) @@ -268,8 +269,8 @@ class EulerCertification(): if device.get_property("ID_CDROM") == "1": types = ["DVD_RW", "DVD_PLUS_RW", "DVD_R", "DVD_PLUS_R", "DVD", \ "BD_RE", "BD_R", "BD", "CD_RW", "CD_R", "CD"] - for type in types: - if device.get_property("ID_CDROM_" + type) == "1": + for dev_type in types: + if device.get_property("ID_CDROM_" + dev_type) == "1": try: sort_devices["cdrom"].extend([device]) except KeyError: diff --git a/server/server.py b/server/server.py index 677db18..858c4f4 100755 --- a/server/server.py +++ b/server/server.py @@ -71,7 +71,7 @@ def get_results(): return render_template('results.html', results=results) -@app.route('/results///') +@app.route('/results///') def get_job(host, oec_id, job): dir_job = os.path.join(dir_results, host, oec_id, job) json_info = os.path.join(dir_job, 'compatibility.json') @@ -86,7 +86,7 @@ def get_job(host, oec_id, job): return render_template('job.html', host=host, id=oec_id, job=job, info=info, results=results) -@app.route('/results////devices/') +@app.route('/results////devices/') def get_device(host, oec_id, job, interface): dir_job = os.path.join(dir_results, host, oec_id, job) json_results = os.path.join(dir_job, 'factory.json') @@ -103,7 +103,7 @@ def get_device(host, oec_id, job, interface): abort(404) -@app.route('/results////devices') +@app.route('/results////devices') def get_devices(host, oec_id, job): dir_job = os.path.join(dir_results, host, oec_id, job) json_devices = os.path.join(dir_job, 'device.json') @@ -115,7 +115,7 @@ def get_devices(host, oec_id, job): return render_template('devices.html', devices=devices) -@app.route('/results////attachment') +@app.route('/results////attachment') def get_attachment(host, oec_id, job): dir_job = os.path.join(dir_results, host, oec_id, job) attachment = dir_job + '.tar.gz' @@ -124,7 +124,7 @@ def get_attachment(host, oec_id, job): return send_from_directory(filedir, filename, as_attachment=True) -@app.route('/results////logs/') +@app.route('/results////logs/') def get_log(host, oec_id, job, name): dir_job = os.path.join(dir_results, host, oec_id, job) logpath = os.path.join(dir_job, name + '.log') @@ -138,7 +138,7 @@ def get_log(host, oec_id, job, name): return render_template('log.html', name=name, log=log) -@app.route('/results////submit') +@app.route('/results////submit') def submit(host, oec_id, job): dir_job = os.path.join(dir_results, host, oec_id, job) tar_job = dir_job + '.tar.gz' diff --git a/tests/memory/memory.py b/tests/memory/memory.py index 8464c15..fe2eac1 100755 --- a/tests/memory/memory.py +++ b/tests/memory/memory.py @@ -58,6 +58,7 @@ class MemoryTest(Test): self.free_memory = 0 self.system_memory = 0 self.swap_memory = 0 + self.hugepage_size = 0 self.hugepage_total = 0 self.hugepage_free = 0 while True: diff --git a/tests/system/system.py b/tests/system/system.py index f27cd06..2935443 100755 --- a/tests/system/system.py +++ b/tests/system/system.py @@ -161,10 +161,10 @@ class SystemTest(Test): def abi_check(self, module): whitelist_path = [("/lib/modules/kabi-current/kabi_whitelist_" + self.sysinfo.arch), - ("/lib/modules/kabi/kabi_whitelist_" + self.sysinfo.arch), - ("/usr/src/kernels/%s/kabi_whitelist" % self.sysinfo.kernel) - ] - + ("/lib/modules/kabi/kabi_whitelist_" + self.sysinfo.arch), + ("/usr/src/kernels/%s/kabi_whitelist" % self.sysinfo.kernel) + ] + whitelist = "" for whitelist in whitelist_path: if os.path.exists(whitelist): break -- Gitee From 9a4eb383d336a543f1f0dca9d2211bc00d59b9a4 Mon Sep 17 00:00:00 2001 From: cuixucui <350255958@qq.com> Date: Mon, 22 Jun 2020 10:17:00 +0800 Subject: [PATCH 06/10] Defect scanning and rectification --- hwcompatible/command.py | 1 + server/server.py | 2 +- tests/cdrom/cdrom.py | 1 + tests/kdump/kdump.py | 2 +- tests/memory/memory.py | 1 + tests/system/system.py | 2 ++ 6 files changed, 7 insertions(+), 2 deletions(-) diff --git a/hwcompatible/command.py b/hwcompatible/command.py index ab850f8..908bf32 100755 --- a/hwcompatible/command.py +++ b/hwcompatible/command.py @@ -205,6 +205,7 @@ class CertCommandError(Exception): def __init__(self, command, message): self.message = message self.command = command + self.__message = None def __str__(self): return "\"%s\" %s" % (self.command.command, self.message) diff --git a/server/server.py b/server/server.py index 858c4f4..a284838 100755 --- a/server/server.py +++ b/server/server.py @@ -186,7 +186,7 @@ def upload_job(): filetext = request.values.get('filetext', '') if not(all([host, oec_id, job, filetext])): return render_template('upload.html', host=host, id=id, job=job, - filetext=filetext, ret='Failed'), 400 + filetext=filetext, ret='Failed'), 400 dir_job = os.path.join(dir_results, host, oec_id, job) tar_job = dir_job + '.tar.gz' diff --git a/tests/cdrom/cdrom.py b/tests/cdrom/cdrom.py index 0ec79f2..086924c 100755 --- a/tests/cdrom/cdrom.py +++ b/tests/cdrom/cdrom.py @@ -31,6 +31,7 @@ class CDRomTest(Test): self.method = None self.device = None self.type = None + self.args = None self.ui = CommandUI() self.test_dir = "/usr/share/doc" diff --git a/tests/kdump/kdump.py b/tests/kdump/kdump.py index 0db65c3..882ac26 100755 --- a/tests/kdump/kdump.py +++ b/tests/kdump/kdump.py @@ -35,7 +35,7 @@ class KdumpTest(Test): def test(self): try: - Command("cat /proc/cmdline").get_str("crashkernel=[^\ ]*") + Command("cat /proc/cmdline").get_str(r"crashkernel=[^\ ]*") except: print("Error: no crashkernel found.") return False diff --git a/tests/memory/memory.py b/tests/memory/memory.py index fe2eac1..d1a8882 100755 --- a/tests/memory/memory.py +++ b/tests/memory/memory.py @@ -30,6 +30,7 @@ class MemoryTest(Test): self.system_memory = 0 self.swap_memory = 0 self.huge_pages = 1000 + self.hugepage_size = 0 self.hugepage_total = 0 self.hugepage_free = 0 self.retry_list = list() diff --git a/tests/system/system.py b/tests/system/system.py index 2935443..4f7b4e2 100755 --- a/tests/system/system.py +++ b/tests/system/system.py @@ -31,6 +31,8 @@ class SystemTest(Test): Test.__init__(self) self.pri = 1 self.sysinfo = SysInfo(CertEnv.releasefile) + self.args = None + self.logdir = None def setup(self, args=None): self.args = args or argparse.Namespace() -- Gitee From b908d3bd202c117e272a60664a4275e940b6226d Mon Sep 17 00:00:00 2001 From: cuixucui <350255958@qq.com> Date: Mon, 22 Jun 2020 11:56:17 +0800 Subject: [PATCH 07/10] Rectification specification scanning --- hwcompatible/command.py | 24 +++++++++++++++-- hwcompatible/compatibility.py | 37 ++++++++++++++------------ server/server.py | 49 +++++++++++++++++++++++++++++++++++ 3 files changed, 92 insertions(+), 18 deletions(-) diff --git a/hwcompatible/command.py b/hwcompatible/command.py index 908bf32..78ba791 100755 --- a/hwcompatible/command.py +++ b/hwcompatible/command.py @@ -42,7 +42,7 @@ class Command: stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, - encoding='utf8') + encoding='utf-8') (output, errors) = self.pipe.communicate() if output: #Strip new line character/s if any from the end of output string @@ -64,7 +64,7 @@ class Command: stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, - encoding='utf8') + encoding='utf-8') def run(self, ignore_errors=False): """ run the command @@ -92,6 +92,10 @@ class Command: return def print_output(self): + ''' + 结果显示 + :return: + ''' if self.output: for line in self.output: sys.stdout.write(line) @@ -99,6 +103,10 @@ class Command: sys.stdout.flush() def print_errors(self): + ''' + 页面显示错误信息 + :return: + ''' if self.errors: for line in self.errors: sys.stderr.write(line) @@ -106,14 +114,26 @@ class Command: sys.stderr.flush() def pid(self): + ''' + 获取管道pid值 + :return: + ''' if self.pipe: return self.pipe.pid def readline(self): + ''' + 按行读取输出信息 + :return + ''' if self.pipe: return self.pipe.stdout.readline() def read(self): + ''' + 执行命令,并读取结果 + :return: + ''' self.pipe = subprocess.Popen(self.command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) diff --git a/hwcompatible/compatibility.py b/hwcompatible/compatibility.py index f7221d6..4c50651 100755 --- a/hwcompatible/compatibility.py +++ b/hwcompatible/compatibility.py @@ -127,7 +127,7 @@ class EulerCertification(): cwd = os.getcwd() os.chdir(os.path.dirname(doc_dir)) dir_name = "oech-" + datetime.datetime.now().strftime("%Y%m%d%H%M%S") + "-" + job.job_id - pack_name = dir_name +".tar" + pack_name = dir_name + ".tar" cmd = Command("tar -cf %s %s" % (pack_name, dir_name)) try: os.rename(job.job_id, dir_name) @@ -175,6 +175,11 @@ class EulerCertification(): return self.client.upload(path, server) def get_tests(self, devices): + ''' + 获取测试项 + :param devices: + :return: + ''' nodevice = ["cpufreq", "memory", "clock", "profiler", "system", "stress", "kdump", "perf", "acpi", "watchdog"] ethernet = ["ethernet"] infiniband = ["infiniband"] @@ -215,9 +220,9 @@ class EulerCertification(): empty_device = Device() for device in devices: if device.get_property("SUBSYSTEM") == "usb" and \ - device.get_property("ID_VENDOR_FROM_DATABASE") == "Linux Foundation" and \ - ("2." in device.get_property("ID_MODEL_FROM_DATABASE") or \ - "3." in device.get_property("ID_MODEL_FROM_DATABASE")): + device.get_property("ID_VENDOR_FROM_DATABASE") == "Linux Foundation" and \ + ("2." in device.get_property("ID_MODEL_FROM_DATABASE") or \ + "3." in device.get_property("ID_MODEL_FROM_DATABASE")): sort_devices["usb"] = [empty_device] continue if device.get_property("PCI_CLASS") == "30000" or device.get_property("PCI_CLASS") == "38000": @@ -230,7 +235,7 @@ class EulerCertification(): sort_devices["tape"] = [device] continue if (device.get_property("DEVTYPE") == "disk" and not device.get_property("ID_TYPE")) or \ - device.get_property("ID_TYPE") == "disk": + device.get_property("ID_TYPE") == "disk": if "nvme" in device.get_property("DEVPATH"): sort_devices["disk"] = [empty_device] try: @@ -268,7 +273,7 @@ class EulerCertification(): continue if device.get_property("ID_CDROM") == "1": types = ["DVD_RW", "DVD_PLUS_RW", "DVD_R", "DVD_PLUS_R", "DVD", \ - "BD_RE", "BD_R", "BD", "CD_RW", "CD_R", "CD"] + "BD_RE", "BD_R", "BD", "CD_RW", "CD_R", "CD"] for dev_type in types: if device.get_property("ID_CDROM_" + dev_type) == "1": try: @@ -318,11 +323,11 @@ class EulerCertification(): continue if num > 0 and num <= len(self.test_factory): - self.test_factory[num-1]["run"] = not self.test_factory[num-1]["run"] + self.test_factory[num - 1]["run"] = not self.test_factory[num - 1]["run"] continue def show_tests(self): - print("\033[1;35m" + "No.".ljust(4) + "Run-Now?".ljust(10) \ + print("\033[1;35m" + "No.".ljust(4) + "Run-Now?".ljust(10) \ + "Status".ljust(8) + "Class".ljust(14) + "Device\033[0m") num = 0 for test in self.test_factory: @@ -340,17 +345,17 @@ class EulerCertification(): num = num + 1 if status == "PASS": - print("%-6d"%num + run.ljust(8) + "\033[0;32mPASS \033[0m" \ - + name.ljust(14) + "%s"%device) + print("%-6d" % num + run.ljust(8) + "\033[0;32mPASS \033[0m" \ + + name.ljust(14) + "%s" % device) elif status == "FAIL": - print("%-6d"%num + run.ljust(8) + "\033[0;31mFAIL \033[0m" \ - + name.ljust(14) + "%s"%device) + print("%-6d" % num + run.ljust(8) + "\033[0;31mFAIL \033[0m" \ + + name.ljust(14) + "%s" % device) elif status == "Force": - print("%-6d"%num + run.ljust(8) + "\033[0;33mForce \033[0m" \ - + name.ljust(14) + "%s"%device) + print("%-6d" % num + run.ljust(8) + "\033[0;33mForce \033[0m" \ + + name.ljust(14) + "%s" % device) else: - print("%-6d"%num + run.ljust(8) + "\033[0;34mNotRun \033[0m" \ - + name.ljust(14) + "%s"%device) + print("%-6d" % num + run.ljust(8) + "\033[0;34mNotRun \033[0m" \ + + name.ljust(14) + "%s" % device) def choose_tests(self): for test in self.test_factory: diff --git a/server/server.py b/server/server.py index a284838..a7970c4 100755 --- a/server/server.py +++ b/server/server.py @@ -73,6 +73,14 @@ def get_results(): @app.route('/results///') def get_job(host, oec_id, job): + ''' + 获取job信息 + :param host: + :param oec_id: + :param job: + :return: + ''' + dir_job = os.path.join(dir_results, host, oec_id, job) json_info = os.path.join(dir_job, 'compatibility.json') json_results = os.path.join(dir_job, 'factory.json') @@ -88,6 +96,14 @@ def get_job(host, oec_id, job): @app.route('/results////devices/') def get_device(host, oec_id, job, interface): + ''' + 获取硬件设备信息 + :param host: + :param oec_id: + :param job: + :param interface: + :return: + ''' dir_job = os.path.join(dir_results, host, oec_id, job) json_results = os.path.join(dir_job, 'factory.json') try: @@ -105,6 +121,13 @@ def get_device(host, oec_id, job, interface): @app.route('/results////devices') def get_devices(host, oec_id, job): + ''' + 获取设备信息 + :param host: + :param oec_id: + :param job: + :return: + ''' dir_job = os.path.join(dir_results, host, oec_id, job) json_devices = os.path.join(dir_job, 'device.json') try: @@ -117,6 +140,13 @@ def get_devices(host, oec_id, job): @app.route('/results////attachment') def get_attachment(host, oec_id, job): + ''' + 发送结果附件 + :param host: + :param oec_id: + :param job: + :return: + ''' dir_job = os.path.join(dir_results, host, oec_id, job) attachment = dir_job + '.tar.gz' filedir = os.path.dirname(attachment) @@ -126,6 +156,14 @@ def get_attachment(host, oec_id, job): @app.route('/results////logs/') def get_log(host, oec_id, job, name): + ''' + 获取日志 + :param host: + :param oec_id: + :param job: + :param name: + :return: + ''' dir_job = os.path.join(dir_results, host, oec_id, job) logpath = os.path.join(dir_job, name + '.log') if not os.path.exists(logpath): @@ -140,6 +178,13 @@ def get_log(host, oec_id, job, name): @app.route('/results////submit') def submit(host, oec_id, job): + ''' + 提交测试结果 + :param host: + :param oec_id: + :param job: + :return: + ''' dir_job = os.path.join(dir_results, host, oec_id, job) tar_job = dir_job + '.tar.gz' json_cert = os.path.join(dir_job, 'compatibility.json') @@ -180,6 +225,10 @@ def submit(host, oec_id, job): @app.route('/api/job/upload', methods=['GET', 'POST']) def upload_job(): + ''' + 上传job + :return: + ''' host = request.values.get('host', '').strip().replace(' ', '-') oec_id = request.values.get('id', '').strip().replace(' ', '-') job = request.values.get('job', '').strip().replace(' ', '-') -- Gitee From b7d464a9d211e268c111d48a8c299f64960d8778 Mon Sep 17 00:00:00 2001 From: cuixucui <350255958@qq.com> Date: Mon, 22 Jun 2020 14:14:06 +0800 Subject: [PATCH 08/10] Rectification specification scanning --- hwcompatible/command.py | 24 ++++++++++++------------ hwcompatible/compatibility.py | 12 ++++++++++-- server/server.py | 28 ++++++++++++++-------------- 3 files changed, 36 insertions(+), 28 deletions(-) diff --git a/hwcompatible/command.py b/hwcompatible/command.py index 78ba791..cacfbca 100755 --- a/hwcompatible/command.py +++ b/hwcompatible/command.py @@ -42,7 +42,7 @@ class Command: stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, - encoding='utf-8') + encoding='utf8') (output, errors) = self.pipe.communicate() if output: #Strip new line character/s if any from the end of output string @@ -64,7 +64,7 @@ class Command: stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, - encoding='utf-8') + encoding='utf8') def run(self, ignore_errors=False): """ run the command @@ -92,10 +92,10 @@ class Command: return def print_output(self): - ''' + """ 结果显示 :return: - ''' + """ if self.output: for line in self.output: sys.stdout.write(line) @@ -103,10 +103,10 @@ class Command: sys.stdout.flush() def print_errors(self): - ''' + """ 页面显示错误信息 :return: - ''' + """ if self.errors: for line in self.errors: sys.stderr.write(line) @@ -114,26 +114,26 @@ class Command: sys.stderr.flush() def pid(self): - ''' + """ 获取管道pid值 :return: - ''' + """ if self.pipe: return self.pipe.pid def readline(self): - ''' + """ 按行读取输出信息 :return - ''' + """ if self.pipe: return self.pipe.stdout.readline() def read(self): - ''' + """ 执行命令,并读取结果 :return: - ''' + """ self.pipe = subprocess.Popen(self.command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) diff --git a/hwcompatible/compatibility.py b/hwcompatible/compatibility.py index 4c50651..66415d2 100755 --- a/hwcompatible/compatibility.py +++ b/hwcompatible/compatibility.py @@ -175,11 +175,11 @@ class EulerCertification(): return self.client.upload(path, server) def get_tests(self, devices): - ''' + """ 获取测试项 :param devices: :return: - ''' + """ nodevice = ["cpufreq", "memory", "clock", "profiler", "system", "stress", "kdump", "perf", "acpi", "watchdog"] ethernet = ["ethernet"] infiniband = ["infiniband"] @@ -327,6 +327,10 @@ class EulerCertification(): continue def show_tests(self): + """ + 显示测试用例 + :return: + """ print("\033[1;35m" + "No.".ljust(4) + "Run-Now?".ljust(10) \ + "Status".ljust(8) + "Class".ljust(14) + "Device\033[0m") num = 0 @@ -358,6 +362,10 @@ class EulerCertification(): + name.ljust(14) + "%s" % device) def choose_tests(self): + """ + 选择测试用例 + :return: + """ for test in self.test_factory: if test["status"] == "PASS": test["run"] = False diff --git a/server/server.py b/server/server.py index a7970c4..566c4a9 100755 --- a/server/server.py +++ b/server/server.py @@ -73,13 +73,13 @@ def get_results(): @app.route('/results///') def get_job(host, oec_id, job): - ''' + """ 获取job信息 :param host: :param oec_id: :param job: :return: - ''' + """ dir_job = os.path.join(dir_results, host, oec_id, job) json_info = os.path.join(dir_job, 'compatibility.json') @@ -96,14 +96,14 @@ def get_job(host, oec_id, job): @app.route('/results////devices/') def get_device(host, oec_id, job, interface): - ''' + """ 获取硬件设备信息 :param host: :param oec_id: :param job: :param interface: :return: - ''' + """ dir_job = os.path.join(dir_results, host, oec_id, job) json_results = os.path.join(dir_job, 'factory.json') try: @@ -121,13 +121,13 @@ def get_device(host, oec_id, job, interface): @app.route('/results////devices') def get_devices(host, oec_id, job): - ''' + """ 获取设备信息 :param host: :param oec_id: :param job: :return: - ''' + """ dir_job = os.path.join(dir_results, host, oec_id, job) json_devices = os.path.join(dir_job, 'device.json') try: @@ -140,13 +140,13 @@ def get_devices(host, oec_id, job): @app.route('/results////attachment') def get_attachment(host, oec_id, job): - ''' + """ 发送结果附件 :param host: :param oec_id: :param job: :return: - ''' + """ dir_job = os.path.join(dir_results, host, oec_id, job) attachment = dir_job + '.tar.gz' filedir = os.path.dirname(attachment) @@ -156,14 +156,14 @@ def get_attachment(host, oec_id, job): @app.route('/results////logs/') def get_log(host, oec_id, job, name): - ''' + """ 获取日志 :param host: :param oec_id: :param job: :param name: :return: - ''' + """ dir_job = os.path.join(dir_results, host, oec_id, job) logpath = os.path.join(dir_job, name + '.log') if not os.path.exists(logpath): @@ -178,13 +178,13 @@ def get_log(host, oec_id, job, name): @app.route('/results////submit') def submit(host, oec_id, job): - ''' + """ 提交测试结果 :param host: :param oec_id: :param job: :return: - ''' + """ dir_job = os.path.join(dir_results, host, oec_id, job) tar_job = dir_job + '.tar.gz' json_cert = os.path.join(dir_job, 'compatibility.json') @@ -225,10 +225,10 @@ def submit(host, oec_id, job): @app.route('/api/job/upload', methods=['GET', 'POST']) def upload_job(): - ''' + """ 上传job :return: - ''' + """ host = request.values.get('host', '').strip().replace(' ', '-') oec_id = request.values.get('id', '').strip().replace(' ', '-') job = request.values.get('job', '').strip().replace(' ', '-') -- Gitee From f8769a2928bdfb4509d31556c6e56cc17fae1ac9 Mon Sep 17 00:00:00 2001 From: cuixucui <350255958@qq.com> Date: Tue, 23 Jun 2020 15:18:51 +0800 Subject: [PATCH 09/10] Code specification rectification --- hwcompatible/compatibility.py | 4 ++-- hwcompatible/device.py | 2 +- hwcompatible/document.py | 6 +++--- hwcompatible/reboot.py | 4 ++-- hwcompatible/sysinfo.py | 2 +- tests/acpi/acpi.py | 4 ++-- tests/disk/disk.py | 4 ++-- tests/kdump/kdump.py | 4 ++-- tests/nvme/nvme.py | 4 ++-- tests/system/system.py | 10 +++++----- 10 files changed, 22 insertions(+), 22 deletions(-) diff --git a/hwcompatible/compatibility.py b/hwcompatible/compatibility.py index 66415d2..badf806 100755 --- a/hwcompatible/compatibility.py +++ b/hwcompatible/compatibility.py @@ -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): diff --git a/hwcompatible/device.py b/hwcompatible/device.py index 4355e6b..50ef89c 100755 --- a/hwcompatible/device.py +++ b/hwcompatible/device.py @@ -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) diff --git a/hwcompatible/document.py b/hwcompatible/document.py index f8725e6..7991c9e 100755 --- a/hwcompatible/document.py +++ b/hwcompatible/document.py @@ -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) diff --git a/hwcompatible/reboot.py b/hwcompatible/reboot.py index 1cf0875..2506d32 100755 --- a/hwcompatible/reboot.py +++ b/hwcompatible/reboot.py @@ -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 diff --git a/hwcompatible/sysinfo.py b/hwcompatible/sysinfo.py index 458d90c..158c8d9 100755 --- a/hwcompatible/sysinfo.py +++ b/hwcompatible/sysinfo.py @@ -35,7 +35,7 @@ class SysInfo: f = open(file) text = f.read() f.close() - except: + except IOError: print("Release file not found.") return diff --git a/tests/acpi/acpi.py b/tests/acpi/acpi.py index 5053bc9..098c7ad 100755 --- a/tests/acpi/acpi.py +++ b/tests/acpi/acpi.py @@ -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 diff --git a/tests/disk/disk.py b/tests/disk/disk.py index 28cbe63..7bf4c98 100755 --- a/tests/disk/disk.py +++ b/tests/disk/disk.py @@ -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 diff --git a/tests/kdump/kdump.py b/tests/kdump/kdump.py index 882ac26..d60b3f8 100755 --- a/tests/kdump/kdump.py +++ b/tests/kdump/kdump.py @@ -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 diff --git a/tests/nvme/nvme.py b/tests/nvme/nvme.py index d43b320..a795a5e 100755 --- a/tests/nvme/nvme.py +++ b/tests/nvme/nvme.py @@ -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 diff --git a/tests/system/system.py b/tests/system/system.py index 4f7b4e2..449987a 100755 --- a/tests/system/system.py +++ b/tests/system/system.py @@ -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 -- Gitee From 9386cc934df207815b9a7730a60a9fe669d16b15 Mon Sep 17 00:00:00 2001 From: cuixucui <350255958@qq.com> Date: Wed, 24 Jun 2020 16:35:07 +0800 Subject: [PATCH 10/10] =?UTF-8?q?=E6=95=B4=E6=94=B9=E7=BC=96=E7=A0=81?= =?UTF-8?q?=E8=A7=84=E8=8C=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hwcompatible/command.py | 1 + hwcompatible/compatibility.py | 23 ++++++++++++----------- hwcompatible/device.py | 2 ++ hwcompatible/document.py | 29 ++++++++++++++++++----------- hwcompatible/job.py | 3 ++- hwcompatible/log.py | 1 + tests/acpi/acpi.py | 3 ++- tests/cdrom/cdrom.py | 6 ++++-- tests/clock/clock.py | 3 ++- tests/cpufreq/cpufreq.py | 17 +++++++++++------ tests/disk/disk.py | 3 ++- tests/ipmi/ipmi.py | 7 +++++-- tests/memory/memory.py | 9 ++++++--- tests/network/network.py | 9 ++++++--- tests/nvme/nvme.py | 3 ++- tests/perf/perf.py | 1 + tests/system/system.py | 15 ++++++++++----- tests/usb/usb.py | 9 +++++---- tests/watchdog/watchdog.py | 3 ++- 19 files changed, 94 insertions(+), 53 deletions(-) diff --git a/hwcompatible/command.py b/hwcompatible/command.py index cacfbca..731ac91 100755 --- a/hwcompatible/command.py +++ b/hwcompatible/command.py @@ -223,6 +223,7 @@ class Command: class CertCommandError(Exception): def __init__(self, command, message): + super(CertCommandError, self).__init__() self.message = message self.command = command self.__message = None diff --git a/hwcompatible/compatibility.py b/hwcompatible/compatibility.py index badf806..a221a14 100755 --- a/hwcompatible/compatibility.py +++ b/hwcompatible/compatibility.py @@ -29,7 +29,7 @@ from .reboot import Reboot from .client import Client -class EulerCertification(): +class EulerCertification: def __init__(self): self.certification = None @@ -50,12 +50,12 @@ class EulerCertification(): print("All cases are passed, test end.") return True - devices = certdevice.get_devices() - self.devices = DeviceDocument(CertEnv.devicefile, devices) + oec_devices = certdevice.get_devices() + self.devices = DeviceDocument(CertEnv.devicefile, oec_devices) self.devices.save() # test_factory format example: [{"name":"nvme", "device":device, "run":True, "status":"PASS", "reboot":False}] - test_factory = self.get_tests(devices) + test_factory = self.get_tests(oec_devices) self.update_factory(test_factory) if not self.choose_tests(): return True @@ -76,7 +76,7 @@ class EulerCertification(): reboot.clean() self.save(job) return True - except Exception as e: + except (IOError, OSError, TypeError) as e: print(e) return False @@ -86,7 +86,7 @@ class EulerCertification(): Command("rm -rf %s" % CertEnv.certificationfile).run() Command("rm -rf %s" % CertEnv.factoryfile).run() Command("rm -rf %s" % CertEnv.devicefile).run() - except Exception as e: + except CertCommandError as e: print(e) return False return True @@ -176,7 +176,7 @@ class EulerCertification(): def get_tests(self, devices): """ - 获取测试项 + get test items :param devices: :return: """ @@ -221,7 +221,7 @@ class EulerCertification(): for device in devices: if device.get_property("SUBSYSTEM") == "usb" and \ device.get_property("ID_VENDOR_FROM_DATABASE") == "Linux Foundation" and \ - ("2." in device.get_property("ID_MODEL_FROM_DATABASE") or \ + ("2." in device.get_property("ID_MODEL_FROM_DATABASE") or "3." in device.get_property("ID_MODEL_FROM_DATABASE")): sort_devices["usb"] = [empty_device] continue @@ -328,7 +328,7 @@ class EulerCertification(): def show_tests(self): """ - 显示测试用例 + show test items :return: """ print("\033[1;35m" + "No.".ljust(4) + "Run-Now?".ljust(10) \ @@ -344,7 +344,7 @@ class EulerCertification(): status = test["status"] device = test["device"].get_name() run = "no" - if test["run"] == True: + if test["run"] is True: run = "yes" num = num + 1 @@ -410,7 +410,8 @@ class EulerCertification(): self.test_factory.sort(key=lambda k: k["name"]) FactoryDocument(CertEnv.factoryfile, self.test_factory).save() - def search_factory(self, obj_test, test_factory): + @staticmethod + def search_factory(obj_test, test_factory): for test in test_factory: if test["name"] == obj_test["name"] and test["device"].path == obj_test["device"].path: return True diff --git a/hwcompatible/device.py b/hwcompatible/device.py index 50ef89c..88a666d 100755 --- a/hwcompatible/device.py +++ b/hwcompatible/device.py @@ -28,6 +28,7 @@ def filter_char(str): filtered += str[start:] return filtered + class CertDevice: def __init__(self): self.devices = None @@ -66,6 +67,7 @@ class CertDevice: self.devices.sort(key=lambda k: k.path) return self.devices + class Device: def __init__(self, properties=None): self.path = "" diff --git a/hwcompatible/document.py b/hwcompatible/document.py index 7991c9e..bede231 100755 --- a/hwcompatible/document.py +++ b/hwcompatible/document.py @@ -21,8 +21,8 @@ from .sysinfo import SysInfo from .env import CertEnv -class Document(): - def __init__(self, filename, document=dict()): +class Document: + def __init__(self, filename, document={}): self.document = document self.filename = filename @@ -49,8 +49,10 @@ class Document(): except (IOError, json.decoder.JSONDecodeError): return False + class CertDocument(Document): - def __init__(self, filename, document=dict()): + def __init__(self, filename, document={}): + super(CertDocument, self).__init__() self.document = dict() self.filename = filename if not document: @@ -103,8 +105,10 @@ class CertDocument(Document): def get_kernel(self): return self.document["kernel"] + class DeviceDocument(Document): - def __init__(self, filename, devices=list()): + def __init__(self, filename, devices=[]): + super(DeviceDocument, self).__init__() self.filename = filename self.document = list() if not devices: @@ -113,8 +117,10 @@ class DeviceDocument(Document): for device in devices: self.document.append(device.properties) + class FactoryDocument(Document): - def __init__(self, filename, factory=list()): + def __init__(self, filename, factory=[]): + super(FactoryDocument, self).__init__() self.document = list() self.filename = filename if not factory: @@ -143,21 +149,22 @@ class FactoryDocument(Document): class ConfigFile: def __init__(self, filename): + super(ConfigFile, self).__init__() self.filename = filename self.parameters = dict() self.config = list() self.load() def load(self): - file = open(self.filename) - self.config = file.readlines() + fp = open(self.filename) + self.config = fp.readlines() for line in self.config: if line.strip() and line.strip()[0] == "#": continue words = line.strip().split(" ") if words[0]: self.parameters[words[0]] = " ".join(words[1:]) - file.close() + fp.close() def get_parameter(self, name): if self.parameters: @@ -199,7 +206,7 @@ class ConfigFile: self.save() def save(self): - file = open(self.filename, "w") + fp = open(self.filename, "w") for line in self.config: - file.write(line) - file.close() + fp.write(line) + fp.close() diff --git a/hwcompatible/job.py b/hwcompatible/job.py index 6088506..482b229 100755 --- a/hwcompatible/job.py +++ b/hwcompatible/job.py @@ -50,7 +50,8 @@ class Job(object): for parameter_name, parameter_value in self.args.test_parameters: self.test_parameters[parameter_name] = parameter_value - def discover(self, testname, device, subtests_filter=None): + @staticmethod + def discover(testname, device, subtests_filter=None): if not testname: print("testname not specified, discover test failed") return None diff --git a/hwcompatible/log.py b/hwcompatible/log.py index cae0add..c3c3725 100755 --- a/hwcompatible/log.py +++ b/hwcompatible/log.py @@ -50,6 +50,7 @@ class Log(object): self.log.close() self.log = None + class Logger(): def __init__(self, logname, logdir, out, err): self.log = Log(logname, logdir) diff --git a/tests/acpi/acpi.py b/tests/acpi/acpi.py index 098c7ad..0b4745e 100755 --- a/tests/acpi/acpi.py +++ b/tests/acpi/acpi.py @@ -22,7 +22,8 @@ class AcpiTest(Test): Test.__init__(self) self.requirements = ["acpica-tools"] - def test(self): + @staticmethod + def test(): try: Command("acpidump").echo() return True diff --git a/tests/cdrom/cdrom.py b/tests/cdrom/cdrom.py index 086924c..698d090 100755 --- a/tests/cdrom/cdrom.py +++ b/tests/cdrom/cdrom.py @@ -66,7 +66,8 @@ class CDRomTest(Test): return False return True - def get_type(self, device): + @staticmethod + def get_type(device): if not device: return None @@ -196,7 +197,8 @@ class CDRomTest(Test): print(e) return False - def cmp_tree(self, dir1, dir2): + @staticmethod + def cmp_tree(dir1, dir2): if not (dir1 and dir2): print("Error: invalid input dir.") return False diff --git a/tests/clock/clock.py b/tests/clock/clock.py index c91cf9d..7a304d8 100755 --- a/tests/clock/clock.py +++ b/tests/clock/clock.py @@ -21,7 +21,8 @@ clock_dir = os.path.dirname(os.path.realpath(__file__)) class ClockTest(Test): - def test(self): + @staticmethod + def test(): return 0 == os.system("cd %s; ./clock" % clock_dir) diff --git a/tests/cpufreq/cpufreq.py b/tests/cpufreq/cpufreq.py index d950cfb..7dcf38d 100644 --- a/tests/cpufreq/cpufreq.py +++ b/tests/cpufreq/cpufreq.py @@ -59,7 +59,8 @@ class CPU: return True - def set_freq(self, freq, cpu='all'): + @staticmethod + def set_freq(freq, cpu='all'): cmd = Command("cpupower -c %s frequency-set --freq %s" % (cpu, freq)) try: cmd.run() @@ -68,7 +69,8 @@ class CPU: print(e) return False - def get_freq(self, cpu): + @staticmethod + def get_freq(cpu): cmd = Command("cpupower -c %s frequency-info -w" % cpu) try: return int(cmd.get_str(r'.* frequency: (?P\d+) .*', 'freq', False)) @@ -76,7 +78,8 @@ class CPU: print(e) return False - def set_governor(self, governor, cpu='all'): + @staticmethod + def set_governor(governor, cpu='all'): cmd = Command("cpupower -c %s frequency-set --governor %s" % (cpu, governor)) try: cmd.run() @@ -85,7 +88,8 @@ class CPU: print(e) return False - def get_governor(self, cpu): + @staticmethod + def get_governor(cpu): cmd = Command("cpupower -c %s frequency-info -p" % cpu) try: return cmd.get_str(r'.* governor "(?P\w+)".*', 'governor', False) @@ -93,7 +97,8 @@ class CPU: print(e) return False - def find_path(self, parent_dir, target_name): + @staticmethod + def find_path(parent_dir, target_name): cmd = Command("find %s -name %s" % (parent_dir, target_name)) try: cmd.run() @@ -262,7 +267,7 @@ class CPUFreqTest(Test): (target_cpu, target_cpu_governor)) return False print("[.] The governor of CPU%s is %s." % - (target_cpu, target_cpu_governor)) + (target_cpu, target_cpu_governor)) load_test = Load(target_cpu) load_test.run() diff --git a/tests/disk/disk.py b/tests/disk/disk.py index 7bf4c98..250e177 100755 --- a/tests/disk/disk.py +++ b/tests/disk/disk.py @@ -205,7 +205,8 @@ class DiskTest(Test): print("#############") return return_code - def do_fio(self, filepath, size, option): + @staticmethod + def do_fio(filepath, size, option): if os.path.isdir(filepath): file_opt = "-directory=%s" % filepath else: diff --git a/tests/ipmi/ipmi.py b/tests/ipmi/ipmi.py index a26be77..4f0b949 100755 --- a/tests/ipmi/ipmi.py +++ b/tests/ipmi/ipmi.py @@ -22,7 +22,8 @@ class IpmiTest(Test): Test.__init__(self) self.requirements = ["OpenIPMI", "ipmitool"] - def start_ipmi(self): + @staticmethod + def start_ipmi(): try: Command("systemctl start ipmi").run() Command("systemctl status ipmi.service").get_str(regex="Active: active", single_line=False) @@ -31,7 +32,8 @@ class IpmiTest(Test): return False return True - def ipmitool(self): + @staticmethod + def ipmitool(): cmd_list = ["ipmitool fru","ipmitool sensor"] for cmd in cmd_list: try: @@ -48,6 +50,7 @@ class IpmiTest(Test): return False return True + if __name__ == "__main__": i = IpmiTest() i.test() diff --git a/tests/memory/memory.py b/tests/memory/memory.py index d1a8882..691f22a 100755 --- a/tests/memory/memory.py +++ b/tests/memory/memory.py @@ -162,7 +162,8 @@ class MemoryTest(Test): return False return True - def hot_plug_verify(self): + @staticmethod + def hot_plug_verify(): kernel = Command("uname -r").read() config_file = "/boot/config-" + kernel if not os.path.exists(config_file): @@ -198,7 +199,8 @@ class MemoryTest(Test): if total_mem_3 != total_mem_1: return False - def online_memory(self, memory_path): + @staticmethod + def online_memory(memory_path): try: Command("echo 1 > %s/online" % memory_path).run() Command("cat %s/state" % memory_path).get_str("online") @@ -207,7 +209,8 @@ class MemoryTest(Test): print("Error: fail to online %s." % memory_path) return False - def offline_memory(self, memory_path): + @staticmethod + def offline_memory(memory_path): try: Command("echo 0 > %s/online" % memory_path).run() Command("cat %s/state" % memory_path).get_str("offline") diff --git a/tests/network/network.py b/tests/network/network.py index 3d72d63..7a495b4 100755 --- a/tests/network/network.py +++ b/tests/network/network.py @@ -48,7 +48,8 @@ class NetworkTest(Test): self.target_bandwidth_percent = 0.8 self.testfile = 'testfile' - def ifdown(self, interface): + @staticmethod + def ifdown(interface): os.system("ip link set down %s" % interface) for _ in range(5): if 0 == os.system("ip link show %s | grep 'state DOWN'" % interface): @@ -56,7 +57,8 @@ class NetworkTest(Test): time.sleep(1) return False - def ifup(self, interface): + @staticmethod + def ifup(interface): os.system("ip link set up %s" % interface) for _ in range(5): time.sleep(1) @@ -64,7 +66,8 @@ class NetworkTest(Test): return True return False - def get_other_interfaces(self): + @staticmethod + def get_other_interfaces(): ignore_interfaces = ['^lo', '^v', 'docker', 'br', 'bond'] cmd = "ip route show default | awk '/default/ {print $5}'" c = Command(cmd) diff --git a/tests/nvme/nvme.py b/tests/nvme/nvme.py index a795a5e..44c3e70 100755 --- a/tests/nvme/nvme.py +++ b/tests/nvme/nvme.py @@ -74,7 +74,8 @@ class NvmeTest(Test): print(e) return False - def in_use(self, disk): + @staticmethod + def in_use(disk): os.system("swapon -a 2>/dev/null") swap_file = open("/proc/swaps", "r") swap = swap_file.read() diff --git a/tests/perf/perf.py b/tests/perf/perf.py index 76a6e3a..2c7bd94 100755 --- a/tests/perf/perf.py +++ b/tests/perf/perf.py @@ -60,6 +60,7 @@ class PerfTest(Test): return False return True + if __name__ == "__main__": main = PerfTest() main.test() diff --git a/tests/system/system.py b/tests/system/system.py index 449987a..4a7bbff 100755 --- a/tests/system/system.py +++ b/tests/system/system.py @@ -58,7 +58,8 @@ class SystemTest(Test): return return_code - def check_certrpm(self): + @staticmethod + def check_certrpm(): print("\nChecking installed cert package...") return_code = True for cert_package in ["oec-hardware"]: @@ -149,7 +150,8 @@ class SystemTest(Test): return return_code - def get_modules(self, sign): + @staticmethod + def get_modules(sign): pattern = re.compile(r"^(?P\w+)[\s\S]+\((?P[A-Z]+)\)") proc_modules = open("/proc/modules") modules = list() @@ -208,7 +210,8 @@ class SystemTest(Test): print("") return True - def read_abi_whitelist(self, whitelist): + @staticmethod + def read_abi_whitelist(whitelist): symbols = list() if not os.path.isfile(whitelist): print("Error: Cannot read whitelist file") @@ -255,7 +258,8 @@ class SystemTest(Test): nm.close() return self.readSymbols(symbols) - def get_modulefile(self, module): + @staticmethod + def get_modulefile(module): try: modulefile = Command("modinfo -F filename %s" % module).get_str() if os.path.islink(modulefile): @@ -265,7 +269,8 @@ class SystemTest(Test): print("Error: could no find module file for %s:" % module) return None - def check_selinux(self): + @staticmethod + def check_selinux(): print("\nChecking selinux...") status = os.system("/usr/sbin/sestatus | grep 'SELinux status' | grep -qw 'enabled'") mode = os.system("/usr/sbin/sestatus | grep 'Current mode' | grep -qw 'enforcing'") diff --git a/tests/usb/usb.py b/tests/usb/usb.py index 4f51938..88adfb7 100755 --- a/tests/usb/usb.py +++ b/tests/usb/usb.py @@ -96,10 +96,11 @@ class UsbTest(Test): devices = CertDevice().get_devices() usb_devices = list() for device in devices: - if (device.get_property("SUBSYSTEM") != "usb" or \ - device.get_property("DEVTYPE") != "usb_device" or \ - device.get_property("ID_BUS") != "usb" or \ - device.get_property("BUSNUM") == "" or device.get_property("DEVNUM") == ""): + if (device.get_property("SUBSYSTEM") != "usb" or + device.get_property("DEVTYPE") != "usb_device" or + device.get_property("ID_BUS") != "usb" or + device.get_property("BUSNUM") == "" or + device.get_property("DEVNUM") == ""): continue else: usb_devices.append(device.path) diff --git a/tests/watchdog/watchdog.py b/tests/watchdog/watchdog.py index be1eb8a..98fcbb4 100755 --- a/tests/watchdog/watchdog.py +++ b/tests/watchdog/watchdog.py @@ -59,6 +59,7 @@ class WatchDogTest(Test): print("") return False - def startup(self): + @staticmethod + def startup(): print("Recover from watchdog.") return True -- Gitee