/
ls.py
71 lines (61 loc) · 2.39 KB
/
ls.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import os
import yaml
import errno
import re
def main(args):
return ls(args.archive_dir, args.verbose)
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:
g = yaml.safe_load_all(f)
for new in g:
summary.update(new)
except IOError as e:
if e.errno == errno.ENOENT:
print '%s ' % j,
# pid
try:
pidfile = os.path.join(job_dir, 'pid')
found = False
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(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' % (archive_dir, j)
).read().rstrip()
print tail,
except IOError as e:
continue
print ''
continue
else:
raise
print "{job} {success} {owner} {desc} {duration}s".format(
job=j,
owner=summary.get('owner', '-'),
desc=summary.get('description', '-'),
success='pass' if summary.get('success', False) else 'FAIL',
duration=int(summary.get('duration', 0)),
)
if verbose and 'failure_reason' in summary:
print ' {reason}'.format(reason=summary['failure_reason'])
def get_jobs(archive_dir):
dir_contents = os.listdir(archive_dir)
def is_job_dir(parent, subdir):
if (os.path.isdir(os.path.join(parent, subdir)) and re.match('\d+$',
subdir)):
return True
return False
jobs = [job for job in dir_contents if is_job_dir(archive_dir, job)]
return sorted(jobs)