From 5fd1cd0bed95a54f510c8468eed1f0d358800ab3 Mon Sep 17 00:00:00 2001 From: Zack Cerza Date: Tue, 8 Oct 2013 11:54:41 -0500 Subject: [PATCH] Move teuthology-ls's arg parsing to scripts/ Signed-off-by: Zack Cerza --- scripts/ls.py | 23 +++++++++++++++++++++++ setup.py | 2 +- teuthology/suite.py | 28 ++++++++-------------------- 3 files changed, 32 insertions(+), 21 deletions(-) create mode 100644 scripts/ls.py diff --git a/scripts/ls.py b/scripts/ls.py new file mode 100644 index 0000000000..f3109b478a --- /dev/null +++ b/scripts/ls.py @@ -0,0 +1,23 @@ +import argparse +from teuthology.suite import ls + + +def main(): + args = parse_args() + ls(args.archive_dir, args.verbose) + + +def parse_args(): + parser = argparse.ArgumentParser(description='List teuthology job results') + parser.add_argument( + '--archive-dir', + metavar='DIR', + help='path under which to archive results', + required=True, + ) + parser.add_argument( + '-v', '--verbose', + action='store_true', default=False, + help='show reasons tests failed', + ) + return parser.parse_args() diff --git a/setup.py b/setup.py index d3df1c6acb..3b0c4bfeb9 100644 --- a/setup.py +++ b/setup.py @@ -19,7 +19,7 @@ 'teuthology = teuthology.run:main', 'teuthology-nuke = scripts.nuke:main', 'teuthology-suite = scripts.suite:main', - 'teuthology-ls = teuthology.suite:ls', + 'teuthology-ls = scripts.ls:main', 'teuthology-worker = teuthology.queue:worker', 'teuthology-lock = teuthology.lock:main', 'teuthology-schedule = teuthology.run:schedule', diff --git a/teuthology/suite.py b/teuthology/suite.py index 42cc2e37fb..49a978ef12 100644 --- a/teuthology/suite.py +++ b/teuthology/suite.py @@ -190,23 +190,10 @@ def build_matrix(path): return out return [] -def ls(): - parser = argparse.ArgumentParser(description='List teuthology job results') - parser.add_argument( - '--archive-dir', - metavar='DIR', - help='path under which to archive results', - required=True, - ) - parser.add_argument( - '-v', '--verbose', - action='store_true', default=False, - help='show reasons tests failed', - ) - args = parser.parse_args() - for j in get_jobs(args.archive_dir): - job_dir = os.path.join(args.archive_dir, j) +def ls(archive_dir, verbose): + for j in get_jobs(archive_dir): + job_dir = os.path.join(archive_dir, j) summary = {} try: with file(os.path.join(job_dir, 'summary.yaml')) as f: @@ -224,15 +211,16 @@ def ls(): if os.path.isfile(pidfile): pid = open(pidfile, 'r').read() if os.path.isdir("/proc/%s" % pid): - cmdline = open('/proc/%s/cmdline' % pid, 'r').read() - if cmdline.find(args.archive_dir) >= 0: + cmdline = open('/proc/%s/cmdline' % pid, + 'r').read() + if cmdline.find(archive_dir) >= 0: print '(pid %s)' % pid, found = True if not found: print '(no process or summary.yaml)', # tail tail = os.popen( - 'tail -1 %s/%s/teuthology.log' % (args.archive_dir, j) + 'tail -1 %s/%s/teuthology.log' % (archive_dir, j) ).read().rstrip() print tail, except IOError, e: @@ -249,7 +237,7 @@ def ls(): success='pass' if summary.get('success', False) else 'FAIL', duration=int(summary.get('duration', 0)), ) - if args.verbose and 'failure_reason' in summary: + if verbose and 'failure_reason' in summary: print ' {reason}'.format(reason=summary['failure_reason']) def generate_coverage(args):