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
+
+
+ 1592261845556
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/hwcompatible/command.py b/hwcompatible/command.py
index 16577ce..aa6810f 100755
--- a/hwcompatible/command.py
+++ b/hwcompatible/command.py
@@ -94,14 +94,14 @@ class Command:
def print_output(self):
if self.output:
for line in self.output:
- sys.stdout.write( line )
+ sys.stdout.write(line)
sys.stdout.write("\n")
sys.stdout.flush()
def print_errors(self):
if self.errors:
for line in self.errors:
- sys.stderr.write( line )
+ sys.stderr.write(line)
sys.stderr.write("\n")
sys.stderr.flush()
diff --git a/server/server.py b/server/server.py
index 26adee9..54b0cce 100755
--- a/server/server.py
+++ b/server/server.py
@@ -40,17 +40,17 @@ dir_files = os.path.join(dir_server, 'files')
@app.errorhandler(400)
-def bad_request(e):
+def bad_request():
return render_template('error.html', error='400 - Bad Request'), 400
@app.errorhandler(404)
-def page_not_found(e):
+def page_not_found():
return render_template('error.html', error='404 - Page Not Found'), 404
@app.errorhandler(500)
-def internal_server_error(e):
+def internal_server_error():
return render_template('error.html', error='500 - Internal Server Error'), 500
@@ -65,15 +65,15 @@ def get_results():
for host in next(os.walk(dir_results))[1]:
dir_host = os.path.join(dir_results, host)
results[host] = {}
- for id in next(os.walk(dir_host))[1]:
- dir_id = os.path.join(dir_host, id)
+ for cert_id in next(os.walk(dir_host))[1]:
+ dir_id = os.path.join(dir_host, cert_id)
results[host][id] = next(os.walk(dir_id))[1]
return render_template('results.html', results=results)
@app.route('/results///')
-def get_job(host, id, job):
- dir_job = os.path.join(dir_results, host, id, job)
+def get_job(host, cert_id, job):
+ dir_job = os.path.join(dir_results, host, cert_id, job)
json_info = os.path.join(dir_job, 'compatibility.json')
json_results = os.path.join(dir_job, 'factory.json')
try:
@@ -81,19 +81,19 @@ def get_job(host, id, job):
info = json.load(f)
with open(json_results, 'r') as f:
results = json.load(f)
- except Exception as e:
+ except (IOError, json.decoder.JSONDecodeError) as e:
abort(404)
- return render_template('job.html', host=host, id=id, job=job, info=info, results=results)
+ return render_template('job.html', host=host, id=cert_id, job=job, info=info, results=results)
@app.route('/results////devices/')
-def get_device(host, id, job, interface):
- dir_job = os.path.join(dir_results, host, id, job)
+def get_device(host, cert_id, job, interface):
+ dir_job = os.path.join(dir_results, host, cert_id, job)
json_results = os.path.join(dir_job, 'factory.json')
try:
with open(json_results, 'r') as f:
results = json.load(f)
- except Exception as e:
+ except (IOError, json.decoder.JSONDecodeError) as e:
abort(404)
for testcase in results:
device = testcase.get('device')
@@ -104,20 +104,20 @@ def get_device(host, id, job, interface):
@app.route('/results////devices')
-def get_devices(host, id, job):
- dir_job = os.path.join(dir_results, host, id, job)
+def get_devices(host, cert_id, job):
+ dir_job = os.path.join(dir_results, host, cert_id, job)
json_devices = os.path.join(dir_job, 'device.json')
try:
with open(json_devices, 'r') as f:
devices = json.load(f)
- except Exception as e:
+ except (IOError, json.decoder.JSONDecodeError) as e:
abort(404)
return render_template('devices.html', devices=devices)
@app.route('/results////attachment')
-def get_attachment(host, id, job):
- dir_job = os.path.join(dir_results, host, id, job)
+def get_attachment(host, cert_id, job):
+ dir_job = os.path.join(dir_results, host, cert_id, job)
attachment = dir_job + '.tar.gz'
filedir = os.path.dirname(attachment)
filename = os.path.basename(attachment)
@@ -125,22 +125,22 @@ def get_attachment(host, id, job):
@app.route('/results////logs/')
-def get_log(host, id, job, name):
- dir_job = os.path.join(dir_results, host, id, job)
+def get_log(host, cert_id, job, name):
+ dir_job = os.path.join(dir_results, host, cert_id, job)
logpath = os.path.join(dir_job, name + '.log')
if not os.path.exists(logpath):
logpath = os.path.join(dir_job, 'job.log')
try:
with open(logpath, 'r') as f:
log = f.read().split('\n')
- except Exception as e:
+ except IOError as e:
abort(404)
return render_template('log.html', name=name, log=log)
@app.route('/results////submit')
-def submit(host, id, job):
- dir_job = os.path.join(dir_results, host, id, job)
+def submit(host, cert_id, job):
+ dir_job = os.path.join(dir_results, host, cert_id, job)
tar_job = dir_job + '.tar.gz'
json_cert = os.path.join(dir_job, 'compatibility.json')
try:
@@ -148,7 +148,7 @@ def submit(host, id, job):
cert = json.load(f)
with open(tar_job, 'rb') as f:
attachment = base64.b64encode(f.read())
- except Exception as e:
+ except (IOError, json.decoder.JSONDecodeError) as e:
print(e)
abort(500)
@@ -181,15 +181,14 @@ def submit(host, id, job):
@app.route('/api/job/upload', methods=['GET', 'POST'])
def upload_job():
host = request.values.get('host', '').strip().replace(' ', '-')
- id = request.values.get('id', '').strip().replace(' ', '-')
+ cert_id = request.values.get('id', '').strip().replace(' ', '-')
job = request.values.get('job', '').strip().replace(' ', '-')
filetext = request.values.get('filetext', '')
-
- if not(all([host, id, job, filetext])):
- return render_template('upload.html', host=host, id=id, job=job,
+ if not(all([host, cert_id, job, filetext])):
+ return render_template('upload.html', host=host, id=cert_id, job=job,
filetext=filetext, ret='Failed'), 400
- dir_job = os.path.join(dir_results, host, id, job)
+ dir_job = os.path.join(dir_results, host, cert_id, job)
tar_job = dir_job + '.tar.gz'
if not os.path.exists(dir_job):
os.makedirs(dir_job)
@@ -197,10 +196,10 @@ def upload_job():
with open(tar_job, 'wb') as f:
f.write(base64.b64decode(filetext))
os.system("tar xf '%s' -C '%s'" % (tar_job, os.path.dirname(dir_job)))
- except Exception as e:
+ except (IOError, OSError) as e:
print(e)
abort(400)
- return render_template('upload.html', host=host, id=id, job=job,
+ return render_template('upload.html', host=host, id=cert_id, job=job,
filetext=filetext, ret='Successful')
@@ -229,7 +228,7 @@ def upload_file():
try:
with open(filepath, 'wb') as f:
f.write(base64.b64decode(filetext))
- except Exception as e:
+ except IOError as e:
print(e)
abort(400)
return render_template('upload.html', filename=filename, filetext=filetext,
@@ -303,7 +302,7 @@ def __get_ib_dev_port(ib_server_ip):
ibport = str(ibport)
return ibdev, ibport
- except Exception as e:
+ except (OSError, IndexError, ValueError) as e:
print(e)
return None, None
diff --git a/tests/acpi/acpi.py b/tests/acpi/acpi.py
index 10bacfb..5053bc9 100755
--- a/tests/acpi/acpi.py
+++ b/tests/acpi/acpi.py
@@ -26,7 +26,7 @@ class AcpiTest(Test):
try:
Command("acpidump").echo()
return True
- except Exception as e:
+ except OSError as e:
print(e)
return False
diff --git a/tests/cdrom/cdrom.py b/tests/cdrom/cdrom.py
index dc104c7..0ec79f2 100755
--- a/tests/cdrom/cdrom.py
+++ b/tests/cdrom/cdrom.py
@@ -72,26 +72,26 @@ class CDRomTest(Test):
bd_types = ["BD_RE", "BD_R", "BD"]
dvd_types = ["DVD_RW", "DVD_PLUS_RW", "DVD_R", "DVD_PLUS_R", "DVD"]
cd_types = ["CD_RW", "CD_R", "CD"]
- for type in bd_types:
- if device.get_property("ID_CDROM_" + type) == "1":
- return type
- for type in dvd_types:
- if device.get_property("ID_CDROM_" + type) == "1":
- return type
- for type in cd_types:
- if device.get_property("ID_CDROM_" + type) == "1":
- return type
+ for bd_type in bd_types:
+ if device.get_property("ID_CDROM_" + bd_type) == "1":
+ return bd_type
+ for bd_type in dvd_types:
+ if device.get_ertpropy("ID_CDROM_" + bd_type) == "1":
+ return bd_type
+ for bd_type in cd_types:
+ if device.get_property("ID_CDROM_" + bd_type) == "1":
+ return bd_type
print("Can not find pr)oper test-type for %s." % device.get_name())
return None
- def get_mode(self, type):
- if not type:
+ def get_mode(self, device_type):
+ if not device_type:
return
- if "RW" in type or "RE" in type:
+ if "RW" in device_type or "RE" in device_type:
self.method = "rw_test"
- elif "_R" in type:
+ elif "_R" in device_type:
self.method = "write_test"
else:
self.method = "read_test"
@@ -216,14 +216,14 @@ class CDRomTest(Test):
Command("eject %s" % device).run()
print("tray ejected.")
sys.stdout.flush()
- except:
+ except CertCommandError as e:
pass
try:
Command("eject -t %s" % device).run()
print("tray auto-closed.\n")
sys.stdout.flush()
- except:
+ except CertCommandError as e:
print("Could not auto-close the tray, please close the tray manually.")
self.ui.prompt_confirm("Done well?")
diff --git a/tests/disk/disk.py b/tests/disk/disk.py
index 6efd442..28cbe63 100755
--- a/tests/disk/disk.py
+++ b/tests/disk/disk.py
@@ -32,7 +32,7 @@ class DiskTest(Test):
self.filesystems = ["ext4"]
self.ui = CommandUI()
- def setup(self, args=None):
+ def setup(self):
try:
print("Disk Info:")
Command("fdisk -l").echo(ignore_errors=True)
diff --git a/tests/ipmi/ipmi.py b/tests/ipmi/ipmi.py
index 19be5d5..a26be77 100755
--- a/tests/ipmi/ipmi.py
+++ b/tests/ipmi/ipmi.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 IpmiTest(Test):
@@ -26,7 +26,7 @@ class IpmiTest(Test):
try:
Command("systemctl start ipmi").run()
Command("systemctl status ipmi.service").get_str(regex="Active: active", single_line=False)
- except:
+ except CertCommandError as e:
print("ipmi service cant't be started")
return False
return True
@@ -36,7 +36,7 @@ class IpmiTest(Test):
for cmd in cmd_list:
try:
Command(cmd).echo()
- except:
+ except CertCommandError as e:
print("%s return error." % cmd)
return False
return True
diff --git a/tests/kdump/kdump.py b/tests/kdump/kdump.py
index 1bcc8a3..0db65c3 100755
--- a/tests/kdump/kdump.py
+++ b/tests/kdump/kdump.py
@@ -79,12 +79,12 @@ class KdumpTest(Test):
if config.get_parameter("path"):
self.vmcore_path = config.get_parameter("path")
- dir_pattern = re.compile("(?P[0-9]+\.[0-9]+\.[0-9]+)-(?P[0-9]+(-|\.)[0-9]+(-|\.)[0-9]+)-(?P