]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
Move teuthology-ls's implementation to ls.py
authorZack Cerza <zack@cerza.org>
Fri, 6 Jun 2014 21:12:35 +0000 (16:12 -0500)
committerZack Cerza <zack@cerza.org>
Fri, 6 Jun 2014 21:15:15 +0000 (16:15 -0500)
Signed-off-by: Zack Cerza <zack.cerza@inktank.com>
scripts/ls.py
teuthology/ls.py [new file with mode: 0644]
teuthology/suite.py

index f3109b478a9f3321f55506d06b3ae6e15089e065..c17f7da5d30f018e7d291508833d9a9fc67ec6dd 100644 (file)
@@ -1,10 +1,9 @@
 import argparse
-from teuthology.suite import ls
+import teuthology.ls
 
 
 def main():
-    args = parse_args()
-    ls(args.archive_dir, args.verbose)
+    teuthology.ls.main(parse_args())
 
 
 def parse_args():
diff --git a/teuthology/ls.py b/teuthology/ls.py
new file mode 100644 (file)
index 0000000..57c1ef5
--- /dev/null
@@ -0,0 +1,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)
index e1fd4cb7e8c424ed378cb6446bcacb85dfe3f43c..eb211b838bdd34ff81f6a17b1d36108afa3c9b85 100644 (file)
@@ -3,11 +3,9 @@
 # https://github.com/ceph/ceph-qa-suite.git
 
 import copy
-import errno
 import itertools
 import logging
 import os
-import re
 import subprocess
 import sys
 import yaml
@@ -39,7 +37,7 @@ def main(args):
         (os.path.join(args.base, collection), collection)
         for collection in args.collections
     ]
-    
+
     count = 1
     num_jobs = 0
     for collection, collection_name in sorted(collections):
@@ -198,69 +196,6 @@ def build_matrix(path):
     return []
 
 
-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)
-
-
 def get_arch(config):
     for yamlfile in config:
         y = yaml.safe_load(file(yamlfile))