Commit c9ca83f0 authored by Andrei Vagin's avatar Andrei Vagin Committed by Andrei Vagin

tests: fix lint warnings for zdtm.py

flake8 was updated recently and now it shows a few new warnings:

[root@fc24 criu]# make lint
flake8 --config=scripts/flake8.cfg test/zdtm.py
test/zdtm.py:181:4: E722 do not use bare except'
test/zdtm.py:304:2: E722 do not use bare except'
test/zdtm.py:325:3: E722 do not use bare except'
test/zdtm.py:445:3: E722 do not use bare except'
test/zdtm.py:573:4: E722 do not use bare except'
test/zdtm.py:1369:2: E722 do not use bare except'
test/zdtm.py:1385:3: E722 do not use bare except'
test/zdtm.py:1396:2: E722 do not use bare except'
test/zdtm.py:1420:3: E722 do not use bare except'
test/zdtm.py:1820:2: E741 ambiguous variable name 'l'
make: *** [Makefile:369: lint] Error 1
Signed-off-by: 's avatarAndrei Vagin <avagin@virtuozzo.com>
parent 6ea74dda
...@@ -171,8 +171,9 @@ class ns_flavor: ...@@ -171,8 +171,9 @@ class ns_flavor:
# run in parallel # run in parallel
try: try:
os.makedirs(self.root + os.path.dirname(fname)) os.makedirs(self.root + os.path.dirname(fname))
except: except OSError, e:
pass if e.errno != errno.EEXIST:
raise
dst = tempfile.mktemp(".tso", "", self.root + os.path.dirname(fname)) dst = tempfile.mktemp(".tso", "", self.root + os.path.dirname(fname))
shutil.copy2(fname, dst) shutil.copy2(fname, dst)
os.rename(dst, tfname) os.rename(dst, tfname)
...@@ -292,10 +293,7 @@ def encode_flav(f): ...@@ -292,10 +293,7 @@ def encode_flav(f):
def decode_flav(i): def decode_flav(i):
try: return flavors.keys().get([i - 128], "unknown")
return flavors.keys()[i - 128]
except:
return "unknown"
def tail(path): def tail(path):
...@@ -315,7 +313,8 @@ def wait_pid_die(pid, who, tmo = 30): ...@@ -315,7 +313,8 @@ def wait_pid_die(pid, who, tmo = 30):
while stime < tmo: while stime < tmo:
try: try:
os.kill(int(pid), 0) os.kill(int(pid), 0)
except: # Died except Exception, e:
print "Unable to kill %d: %s" % (pid, e)
break break
print "Wait for %s(%d) to die for %f" % (who, pid, stime) print "Wait for %s(%d) to die for %f" % (who, pid, stime)
...@@ -434,8 +433,8 @@ class zdtm_test: ...@@ -434,8 +433,8 @@ class zdtm_test:
try: try:
os.kill(int(self.getpid()), 0) os.kill(int(self.getpid()), 0)
except: except Exception, e:
raise test_fail_exc("start") raise test_fail_exc("start: %s" % e)
if not self.static(): if not self.static():
# Wait less than a second to give the test chance to # Wait less than a second to give the test chance to
...@@ -560,7 +559,8 @@ class inhfd_test: ...@@ -560,7 +559,8 @@ class inhfd_test:
os.close(start_pipe[1]) os.close(start_pipe[1])
try: try:
data = peer_file.read(16) data = peer_file.read(16)
except: except Exception, e:
print "Unable to read a peer file: %s" % e
sys.exit(1) sys.exit(1)
sys.exit(data == self.__message and 42 or 2) sys.exit(data == self.__message and 42 or 2)
...@@ -1265,7 +1265,8 @@ def pstree_each_pid(root_pid): ...@@ -1265,7 +1265,8 @@ def pstree_each_pid(root_pid):
pid_line = f_children.readline().strip(" \n") pid_line = f_children.readline().strip(" \n")
if pid_line: if pid_line:
child_pids += pid_line.split(" ") child_pids += pid_line.split(" ")
except: except Exception, e:
print "Unable to read /proc/*/children: %s" % e
return # process is dead return # process is dead
yield root_pid yield root_pid
...@@ -1281,7 +1282,8 @@ def is_proc_stopped(pid): ...@@ -1281,7 +1282,8 @@ def is_proc_stopped(pid):
for line in f_status.readlines(): for line in f_status.readlines():
if line.startswith("State:"): if line.startswith("State:"):
return line.split(":", 1)[1].strip().split(" ")[0] return line.split(":", 1)[1].strip().split(" ")[0]
except: except Exception, e:
print "Unable to read a thread status: %s" % e
pass # process is dead pass # process is dead
return None return None
...@@ -1292,7 +1294,8 @@ def is_proc_stopped(pid): ...@@ -1292,7 +1294,8 @@ def is_proc_stopped(pid):
thread_dirs = [] thread_dirs = []
try: try:
thread_dirs = os.listdir(tasks_dir) thread_dirs = os.listdir(tasks_dir)
except: except Exception, e:
print "Unable to read threads: %s" % e
pass # process is dead pass # process is dead
for thread_dir in thread_dirs: for thread_dir in thread_dirs:
...@@ -1316,7 +1319,8 @@ def pstree_signal(root_pid, signal): ...@@ -1316,7 +1319,8 @@ def pstree_signal(root_pid, signal):
for pid in pstree_each_pid(root_pid): for pid in pstree_each_pid(root_pid):
try: try:
os.kill(int(pid), signal) os.kill(int(pid), signal)
except: except Exception, e:
print "Unable to kill %d: %s" % (pid, e)
pass # process is dead pass # process is dead
...@@ -1378,7 +1382,7 @@ def do_run_test(tname, tdesc, flavs, opts): ...@@ -1378,7 +1382,7 @@ def do_run_test(tname, tdesc, flavs, opts):
print_sep("Test %s PASS" % tname) print_sep("Test %s PASS" % tname)
class launcher: class Launcher:
def __init__(self, opts, nr_tests): def __init__(self, opts, nr_tests):
self.__opts = opts self.__opts = opts
self.__total = nr_tests self.__total = nr_tests
...@@ -1700,26 +1704,26 @@ def run_tests(opts): ...@@ -1700,26 +1704,26 @@ def run_tests(opts):
# Most tests will work with 4.3 - 4.11 # Most tests will work with 4.3 - 4.11
print "[WARNING] Non-cooperative UFFD is missing, some tests might spuriously fail" print "[WARNING] Non-cooperative UFFD is missing, some tests might spuriously fail"
l = launcher(opts, len(torun)) launcher = Launcher(opts, len(torun))
try: try:
for t in torun: for t in torun:
global arch global arch
if excl and excl.match(t): if excl and excl.match(t):
l.skip(t, "exclude") launcher.skip(t, "exclude")
continue continue
tdesc = get_test_desc(t) tdesc = get_test_desc(t)
if tdesc.get('arch', arch) != arch: if tdesc.get('arch', arch) != arch:
l.skip(t, "arch %s" % tdesc['arch']) launcher.skip(t, "arch %s" % tdesc['arch'])
continue continue
if test_flag(tdesc, 'reqrst') and opts['norst']: if test_flag(tdesc, 'reqrst') and opts['norst']:
l.skip(t, "restore stage is required") launcher.skip(t, "restore stage is required")
continue continue
if run_all and test_flag(tdesc, 'noauto'): if run_all and test_flag(tdesc, 'noauto'):
l.skip(t, "manual run only") launcher.skip(t, "manual run only")
continue continue
feat = tdesc.get('feature', None) feat = tdesc.get('feature', None)
...@@ -1729,34 +1733,34 @@ def run_tests(opts): ...@@ -1729,34 +1733,34 @@ def run_tests(opts):
features[feat] = criu.check(feat) features[feat] = criu.check(feat)
if not features[feat]: if not features[feat]:
l.skip(t, "no %s feature" % feat) launcher.skip(t, "no %s feature" % feat)
continue continue
if self_checkskip(t): if self_checkskip(t):
l.skip(t, "checkskip failed") launcher.skip(t, "checkskip failed")
continue continue
if opts['user']: if opts['user']:
if test_flag(tdesc, 'suid'): if test_flag(tdesc, 'suid'):
l.skip(t, "suid test in user mode") launcher.skip(t, "suid test in user mode")
continue continue
if test_flag(tdesc, 'nouser'): if test_flag(tdesc, 'nouser'):
l.skip(t, "criu root prio needed") launcher.skip(t, "criu root prio needed")
continue continue
if opts['join_ns']: if opts['join_ns']:
if test_flag(tdesc, 'samens'): if test_flag(tdesc, 'samens'):
l.skip(t, "samens test in the same namespace") launcher.skip(t, "samens test in the same namespace")
continue continue
if opts['lazy_pages'] or opts['remote_lazy_pages']: if opts['lazy_pages'] or opts['remote_lazy_pages']:
if test_flag(tdesc, 'nolazy'): if test_flag(tdesc, 'nolazy'):
l.skip(t, "lazy pages are not supported") launcher.skip(t, "lazy pages are not supported")
continue continue
if opts['remote_lazy_pages']: if opts['remote_lazy_pages']:
if test_flag(tdesc, 'noremotelazy'): if test_flag(tdesc, 'noremotelazy'):
l.skip(t, "remote lazy pages are not supported") launcher.skip(t, "remote lazy pages are not supported")
continue continue
test_flavs = tdesc.get('flavor', 'h ns uns').split() test_flavs = tdesc.get('flavor', 'h ns uns').split()
...@@ -1778,11 +1782,11 @@ def run_tests(opts): ...@@ -1778,11 +1782,11 @@ def run_tests(opts):
run_flavs -= set(['h']) run_flavs -= set(['h'])
if run_flavs: if run_flavs:
l.run_test(t, tdesc, run_flavs) launcher.run_test(t, tdesc, run_flavs)
else: else:
l.skip(t, "no flavors") launcher.skip(t, "no flavors")
finally: finally:
l.finish() launcher.finish()
if opts['join_ns']: if opts['join_ns']:
subprocess.Popen(["ip", "netns", "delete", "zdtm_netns"]).wait() subprocess.Popen(["ip", "netns", "delete", "zdtm_netns"]).wait()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment