提交 050833aa 编写于 作者: C cuixucui

Modify exception capture method

上级 e5fb0586
......@@ -44,7 +44,7 @@ class Client(object):
job = filename.split('.')[0]
with open(files, 'rb') as f:
filetext = base64.b64encode(f.read())
except IOError as e:
except Exception as e:
print(e)
return False
......@@ -70,7 +70,7 @@ class Client(object):
print("Error: upload failed, %s" % res.msg)
return False
return True
except HTTPError as e:
except Exception as e:
print(e)
return False
......
......@@ -86,7 +86,7 @@ class EulerCertification(object):
reboot.clean()
self.save(job)
return True
except (IOError, OSError, TypeError) as e:
except Exception as e:
print(e)
return False
......@@ -100,7 +100,7 @@ class EulerCertification(object):
Command("rm -rf %s" % CertEnv.certificationfile).run()
Command("rm -rf %s" % CertEnv.factoryfile).run()
Command("rm -rf %s" % CertEnv.devicefile).run()
except CertCommandError as e:
except Exception as e:
print(e)
return False
return True
......@@ -324,7 +324,7 @@ class EulerCertification(object):
try:
Command("dmidecode").get_str("IPMI Device Information", single_line=False)
sort_devices["ipmi"] = [empty_device]
except OSError as e:
except:
pass
return sort_devices
......@@ -361,7 +361,7 @@ class EulerCertification(object):
try:
num = int(reply)
except ValueError:
except:
continue
if num > 0 and num <= len(self.test_factory):
......
......@@ -73,7 +73,7 @@ class CertDevice(object):
properties["INFO"] = attribute
else:
break
except CertCommandError as e:
except Exception as e:
print("Warning: get devices fail")
print(e)
self.devices.sort(key=lambda k: k.path)
......
......@@ -37,7 +37,7 @@ class Document(object):
with open(self.filename, "w+") as save_f:
json.dump(self.document, save_f, indent=4)
save_f.close()
except (IOError, ValueError) as e:
except Exception as e:
print("Error: doc save fail.")
print(e)
return False
......@@ -49,7 +49,7 @@ class Document(object):
self.document = json.load(load_f)
load_f.close()
return True
except (IOError, ValueError):
except:
return False
......@@ -86,7 +86,7 @@ class CertDocument(Document):
self.document[key] = value
else:
break
except OSError as e:
except Exception as e:
print("Error: get hardware info fail.")
print(e)
......
......@@ -75,7 +75,7 @@ class Job(object):
sys.path.insert(0, dirpath)
try:
module = __import__(testname, globals(), locals())
except ImportError as e:
except Exception as e:
print("Error: module import failed for %s" % testname)
print(e)
return None
......@@ -183,7 +183,7 @@ class Job(object):
return_code = test.test()
else:
return_code = test.test()
except (IOError, KeyError, AttributeError) as e:
except Exception as e:
print(e)
return_code = False
......
......@@ -73,7 +73,7 @@ class Reboot(object):
try:
Command("systemctl daemon-reload").run_quiet()
Command("systemctl enable oech").run_quiet()
except OSError as e:
except:
print("Error: enable oech.service fail.")
return False
......@@ -95,7 +95,7 @@ class Reboot(object):
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 KeyError:
except:
print("Error: reboot file format not as expect.")
return False
......
......@@ -43,7 +43,7 @@ class SysInfo(object):
f = open(filename)
text = f.read()
f.close()
except IOError:
except:
print("Release file not found.")
return
......
......@@ -89,7 +89,7 @@ def get_job(host, oec_id, job):
info = json.load(f)
with open(json_results, 'r') as f:
results = json.load(f)
except (IOError, ValueError):
except Exception as e:
abort(404)
return render_template('job.html', host=host, id=oec_id, job=job, info=info, results=results)
......@@ -109,7 +109,7 @@ def get_device(host, oec_id, job, interface):
try:
with open(json_results, 'r') as f:
results = json.load(f)
except (IOError, ValueError):
except Exception as e:
abort(404)
for testcase in results:
device = testcase.get('device')
......@@ -133,7 +133,7 @@ def get_devices(host, oec_id, job):
try:
with open(json_devices, 'r') as f:
devices = json.load(f)
except (IOError, ValueError):
except Exception as e:
abort(404)
return render_template('devices.html', devices=devices)
......@@ -171,7 +171,7 @@ def get_log(host, oec_id, job, name):
try:
with open(logpath, 'r') as f:
log = f.read().split('\n')
except IOError as e:
except Exception as e:
abort(404)
return render_template('log.html', name=name, log=log)
......@@ -193,7 +193,7 @@ def submit(host, oec_id, job):
cert = json.load(f)
with open(tar_job, 'rb') as f:
attachment = base64.b64encode(f.read())
except (IOError, ValueError) as e:
except Exception as e:
print(e)
abort(500)
......@@ -245,7 +245,7 @@ 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 (IOError, OSError) as e:
except Exception as e:
print(e)
abort(400)
return render_template('upload.html', host=host, id=oec_id, job=job,
......@@ -277,7 +277,7 @@ def upload_file():
try:
with open(filepath, 'wb') as f:
f.write(base64.b64decode(filetext))
except IOError as e:
except Exception as e:
print(e)
abort(400)
return render_template('upload.html', filename=filename, filetext=filetext,
......@@ -351,7 +351,7 @@ def __get_ib_dev_port(ib_server_ip):
ibport = str(ibport)
return ibdev, ibport
except (OSError, IndexError, ValueError) as e:
except Exception as e:
print(e)
return None, None
......
......@@ -13,7 +13,7 @@
# Create: 2020-04-01
from hwcompatible.test import Test
from hwcompatible.command import Command, CertCommandError
from hwcompatible.command import Command
class AcpiTest(Test):
......@@ -29,6 +29,6 @@ class AcpiTest(Test):
try:
Command("acpidump").echo()
return True
except CertCommandError as e:
except Exception as e:
print(e)
return False
......@@ -149,7 +149,7 @@ class CDRomTest(Test):
self.reload_disc(devname)
sys.stdout.flush()
return self.write_test()
except CertCommandError:
except CertCommandError as e:
return False
def write_test(self):
......@@ -190,7 +190,7 @@ class CDRomTest(Test):
self.reload_disc(devname)
sys.stdout.flush()
return True
except CertCommandError:
except CertCommandError as e:
return False
def read_test(self):
......@@ -248,7 +248,7 @@ class CDRomTest(Test):
try:
Command("diff -r %s %s" % (dir1, dir2)).run()
return True
except CertCommandError:
except CertCommandError as e:
print("Error: file comparison failed.")
return False
......@@ -267,14 +267,14 @@ class CDRomTest(Test):
Command("eject %s" % device).run()
print("tray ejected.")
sys.stdout.flush()
except CertCommandError:
except:
pass
try:
Command("eject -t %s" % device).run()
print("tray auto-closed.\n")
sys.stdout.flush()
except CertCommandError:
except:
print("Could not auto-close the tray, please close the tray manually.")
self.ui.prompt_confirm("Done well?")
......
......@@ -17,7 +17,7 @@ from time import sleep
from hwcompatible.env import CertEnv
from hwcompatible.test import Test
from hwcompatible.command import Command, CertCommandError
from hwcompatible.command import Command
class CPU(object):
......@@ -39,7 +39,7 @@ class CPU(object):
cmd = Command("lscpu")
try:
nums = cmd.get_str(r'^CPU\S*:\s+(?P<cpus>\d+)$', 'cpus', False)
except CertCommandError as e:
except Exception as e:
print(e)
return False
self.nums = int(nums)
......@@ -48,7 +48,7 @@ class CPU(object):
cmd = Command("cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq")
try:
max_freq = cmd.get_str()
except CertCommandError as e:
except Exception as e:
print(e)
return False
self.max_freq = int(max_freq)
......@@ -56,7 +56,7 @@ class CPU(object):
cmd = Command("cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq")
try:
min_freq = cmd.get_str()
except CertCommandError as e:
except Exception as e:
print(e)
return False
self.min_freq = int(min_freq)
......@@ -75,7 +75,7 @@ class CPU(object):
try:
cmd.run()
return cmd.returncode
except CertCommandError as e:
except Exception as e:
print(e)
return False
......@@ -89,7 +89,7 @@ class CPU(object):
cmd = Command("cpupower -c %s frequency-info -w" % cpu)
try:
return int(cmd.get_str(r'.* frequency: (?P<freq>\d+) .*', 'freq', False))
except CertCommandError as e:
except Exception as e:
print(e)
return False
......@@ -105,7 +105,7 @@ class CPU(object):
try:
cmd.run()
return cmd.returncode
except CertCommandError as e:
except Exception as e:
print(e)
return False
......@@ -119,7 +119,7 @@ class CPU(object):
cmd = Command("cpupower -c %s frequency-info -p" % cpu)
try:
return cmd.get_str(r'.* governor "(?P<governor>\w+)".*', 'governor', False)
except CertCommandError as e:
except Exception as e:
print(e)
return False
......@@ -135,7 +135,7 @@ class CPU(object):
try:
cmd.run()
return cmd.returncode
except CertCommandError as e:
except Exception as e:
print(e)
return False
......
......@@ -52,7 +52,7 @@ class DiskTest(Test):
Command("cat /proc/mdstat").echo(ignore_errors=True)
sys.stdout.flush()
print("\n")
except CertCommandError as e:
except Exception as e:
print("Warning: could not get disk info")
print(e)
......@@ -197,7 +197,7 @@ class DiskTest(Test):
if not self.do_fio(path, size, opts):
return_code = False
break
except CertCommandError as e:
except Exception as e:
print(e)
return_code = False
break
......
......@@ -13,7 +13,7 @@
# Create: 2020-04-01
from hwcompatible.test import Test
from hwcompatible.command import Command, CertCommandError
from hwcompatible.command import Command
class IpmiTest(Test):
......@@ -33,7 +33,7 @@ class IpmiTest(Test):
try:
Command("systemctl start ipmi").run()
Command("systemctl status ipmi.service").get_str(regex="Active: active", single_line=False)
except CertCommandError:
except:
print("ipmi service cant't be started")
return False
return True
......@@ -48,7 +48,7 @@ class IpmiTest(Test):
for cmd in cmd_list:
try:
Command(cmd).echo()
except CertCommandError:
except:
print("%s return error." % cmd)
return False
return True
......
......@@ -42,7 +42,7 @@ class KdumpTest(Test):
"""
try:
Command("cat /proc/cmdline").get_str(r"crashkernel=[^\ ]*")
except (OSError, ValueError):
except:
print("Error: no crashkernel found.")
return False
......@@ -59,7 +59,7 @@ class KdumpTest(Test):
try:
Command("systemctl restart kdump").run()
Command("systemctl status kdump").get_str(regex="Active: active", single_line=False)
except (OSError, ValueError):
except:
print("Error: kdump service not working.")
return False
......
......@@ -243,7 +243,7 @@ class MemoryTest(Test):
Command("echo 1 > %s/online" % memory_path).run()
Command("cat %s/state" % memory_path).get_str("online")
return True
except CertCommandError:
except:
print("Error: fail to online %s." % memory_path)
return False
......@@ -258,7 +258,7 @@ class MemoryTest(Test):
Command("echo 0 > %s/online" % memory_path).run()
Command("cat %s/state" % memory_path).get_str("offline")
return True
except CertCommandError:
except:
print("Error: fail to online %s." % memory_path)
return False
......@@ -294,7 +294,7 @@ class MemoryTest(Test):
Command("cat %s/removable" % memory_path).get_str("1")
print("%s is removable, start testing..." % os.path.basename(memory_path))
test_flag = 1
except CertCommandError:
except:
continue
if not self.hotplug_memory_test(memory_path):
print("%s hotplug test fail." % os.path.basename(memory_path))
......
......@@ -25,7 +25,7 @@ except ImportError:
from urllib2 import urlopen, Request, HTTPError
from hwcompatible.test import Test
from hwcompatible.command import Command, CertCommandError
from hwcompatible.command import Command
from hwcompatible.document import CertDocument
from hwcompatible.env import CertEnv
......@@ -101,7 +101,7 @@ class NetworkTest(Test):
try:
c.run()
return c.output
except CertCommandError as e:
except Exception as e:
print(e)
return []
......@@ -136,7 +136,7 @@ class NetworkTest(Test):
try:
speed = c.get_str(pattern, 'speed', False)
return int(speed)
except CertCommandError:
except Exception as e:
print("[X] No speed found on the interface.")
return None
......@@ -150,7 +150,7 @@ class NetworkTest(Test):
try:
ip = c.get_str(pattern, 'ip', False)
return ip
except CertCommandError:
except Exception as e:
print("[X] No available ip on the interface.")
return None
......@@ -170,7 +170,7 @@ class NetworkTest(Test):
c.print_output()
if float(loss) == 0:
return True
except CertCommandError as e:
except Exception as e:
print(e)
return False
......@@ -194,7 +194,7 @@ class NetworkTest(Test):
try:
request = Request(url, data=data, headers=headers)
response = urlopen(request)
except HTTPError as e:
except Exception as e:
print(e)
return False
print("Status: %u %s" % (response.code, response.msg))
......@@ -243,7 +243,7 @@ class NetworkTest(Test):
(bandwidth, target_bandwidth))
if bandwidth > target_bandwidth:
return True
except CertCommandError as e:
except Exception as e:
print(e)
return False
......@@ -269,7 +269,7 @@ class NetworkTest(Test):
try:
with open(self.testfile, 'rb') as f:
filetext = base64.b64encode(f.read())
except IOError as e:
except Exception as e:
print(e)
return False
......@@ -286,7 +286,7 @@ class NetworkTest(Test):
try:
request = Request(url, data=data, headers=headers)
response = urlopen(request)
except HTTPError as e:
except Exception as e:
print(e)
return False
time_stop = time.time()
......@@ -309,7 +309,7 @@ class NetworkTest(Test):
time_start = time.time()
try:
response = urlopen(url)
except HTTPError as e:
except Exception as e:
print(e)
return False
time_stop = time.time()
......@@ -321,7 +321,7 @@ class NetworkTest(Test):
try:
with open(self.testfile, 'wb') as f:
f.write(filetext)
except IOError as e:
except Exception as e:
print(e)
return False
......
......@@ -16,7 +16,7 @@ import os
import re
import argparse
from hwcompatible.command import Command, CertCommandError
from hwcompatible.command import Command
from hwcompatible.document import CertDocument
from hwcompatible.env import CertEnv
from network import NetworkTest
......@@ -61,7 +61,7 @@ class RDMATest(NetworkTest):
c = Command(cmd)
try:
self.ib_device = c.read()
except CertCommandError as e:
except Exception as e:
print(e)
return False
......@@ -70,7 +70,7 @@ class RDMATest(NetworkTest):
c = Command(cmd)
try:
self.ib_port = int(c.read(), 16) + 1
except CertCommandError as e:
except Exception as e:
print(e)
return False
......@@ -93,7 +93,7 @@ class RDMATest(NetworkTest):
self.phys_state = re.search(r"phys state:\s+(.*)", info).group(1)
self.link_layer = re.search(r"link_layer:\s+(.*)", info).group(1)
self.speed = int(re.search(r"rate:\s+(\d*)", info).group(1)) * 1024
except CertCommandError as e:
except Exception as e:
print(e)
return False
......@@ -156,7 +156,7 @@ class RDMATest(NetworkTest):
print("Current bandwidth is %.2fMb/s, target is %.2fMb/s" %
(avg_bw, tgt_bw))
return avg_bw > tgt_bw
except CertCommandError as e:
except Exception as e:
print(e)
self.call_remote_server(cmd, 'stop')
return False
......
......@@ -16,7 +16,7 @@ import os
import sys
import argparse
from hwcompatible.test import Test
from hwcompatible.command import Command, CertCommandError
from hwcompatible.command import Command
class NvmeTest(Test):
......@@ -81,7 +81,7 @@ class NvmeTest(Test):
Command("nvme list").echo(ignore_errors=True)
return True
except CertCommandError as e:
except Exception as e:
print("Error: nvme cmd fail.")
print(e)
return False
......
......@@ -83,7 +83,7 @@ class SystemTest(Test):
sys.stdout.flush()
if rpm_verify.output and len(rpm_verify.output) > 0:
return_code = False
except OSError:
except:
print("Error: files in %s have been tampered." % cert_package)
return_code = False
return return_code
......@@ -113,7 +113,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 KeyError:
except:
print("Error: %s is not supported." % os_version)
return_code = False
......@@ -148,7 +148,7 @@ class SystemTest(Test):
print("")
tainted_file.close()
except (IOError, ValueError) as e:
except Exception as e:
print(e)
print("Error: could not determine if kernel is tainted.")
return_code = False
......@@ -161,7 +161,7 @@ class SystemTest(Test):
try:
params = Command("cat /proc/cmdline").get_str()
print("Boot Parameters: %s" % params)
except OSError as e:
except Exception as e:
print(e)
print("Error: could not determine boot parameters.")
return_code = False
......@@ -308,7 +308,7 @@ class SystemTest(Test):
if os.path.islink(modulefile):
modulefile = os.readlink(modulefile)
return modulefile
except OSError:
except:
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.
先完成此消息的编辑!
想要评论请 注册