Rearrange the why isn't my job running logic so that it checks all of
the preconditions first before looking at the Ready state of the
machines.

Also have it list all reasons the job is not running rather
than only the first reason and dying.  That way when someone uses it
they don't think "oh, its just that, let me fix that" only to have it
not work and have to rerun it again later to see the next reason.

Signed-off-by: Gregory Smith <[email protected]>

--- autotest/cli/contrib/why_isnt_my_job_running.py     2010-01-21 
11:33:11.000000000 -0800
+++ autotest/cli/contrib/why_isnt_my_job_running.py     2010-01-21 
11:33:27.000000000 -0800
@@ -215,6 +215,9 @@
     sys.exit(1)
 host = hosts[0]
 
+# Boolean to track our findings.  We want to list all reasons it won't run,
+# not just the first.
+job_will_run = True
 
 entries_for_this_host = [entry for entry in queue_entries
                          if entry['host']
@@ -242,22 +245,40 @@
         sys.exit(0)
     is_metahost = True
 
-# host ready?
-if host['status'] != 'Ready':
-    if host['status'] == 'Pending':
-        active = proxy.run('get_host_queue_entries',
-                           host=host['id'], active=True)
-        if not active:
-            print ('Host %s seems to be in "Pending" state incorrectly; please 
'
-                   'report this to the Autotest team' % hostname)
-            sys.exit(1)
-    print 'Host not in "Ready" status (status="%s")' % host['status']
-    sys.exit(0)
+# meets atomic group requirements?
+host_labels = proxy.run('get_labels', name__in=list(host_label_names))
+host_atomic_group_labels = [label for label in host_labels
+                            if label['atomic_group']]
+host_atomic_group_name = None
+if host_atomic_group_labels:
+    atomic_groups = set()
+    for label in host_atomic_group_labels:
+        atomic_groups.add(label['atomic_group']['name'])
+    if len(atomic_groups) != 1:
+        print 'Host has more than one atomic group!'
+        print list(atomic_groups)
+        sys.exit(1)
+    host_atomic_group_label = host_atomic_group_labels[0]
+    host_atomic_group_name = host_atomic_group_label['atomic_group']['name']
+
+job_atomic_groups = set(entry['atomic_group'] for entry in queue_entries)
+assert len(job_atomic_groups) == 1, 'Job has more than one atomic group value!'
+job_atomic_group = job_atomic_groups.pop() # might be None
+job_atomic_group_name = None
+if job_atomic_group:
+    job_atomic_group_name = job_atomic_group['name']
+
+if host_atomic_group_name != job_atomic_group_name:
+    print ('Job is for atomic group %s, but host is in atomic group %s '
+           '(label %s)' %
+           (job_atomic_group_name, host_atomic_group_name,
+            host_atomic_group_label['name']))
+    job_will_run = False
 
 # host locked?
 if host['locked']:
     print 'Host is locked by', host['locked_by'], 'no jobs will schedule on 
it.'
-    sys.exit(0)
+    job_will_run = False
 
 # acl accessible?
 accessible = proxy.run('get_hosts', hostname=hostname,
@@ -268,9 +289,9 @@
     owner_acls = ', '.join(group['name'] for group in
                            proxy.run('get_acl_groups', users__login=owner))
     print 'Host not ACL-accessible to job owner', owner
-    print 'Host ACLs:', host_acls
-    print 'Owner Acls:', owner_acls
-    sys.exit(0)
+    print ' Host ACLs:', host_acls
+    print ' Owner Acls:', owner_acls
+    job_will_run = False
 
 # meets dependencies?
 job_deps_list = job['dependencies'].split(',')
@@ -281,7 +302,7 @@
 if unmet:
     print ("Host labels (%s) don't satisfy job dependencies: %s" %
            (', '.join(host_label_names), ', '.join(unmet)))
-    sys.exit(0)
+    job_will_run = False
 
 # at this point, if the job is for an unassigned atomic group, things are too
 # complicated to proceed
@@ -293,36 +314,6 @@
            "can't give you any definite answers.  Sorry.")
     sys.exit(1)
 
-# meets atomic group requirements?
-host_labels = proxy.run('get_labels', name__in=list(host_label_names))
-host_atomic_group_labels = [label for label in host_labels
-                            if label['atomic_group']]
-host_atomic_group_name = None
-if host_atomic_group_labels:
-    atomic_groups = set()
-    for label in host_atomic_group_labels:
-        atomic_groups.add(label['atomic_group']['name'])
-    if len(atomic_groups) != 1:
-        print 'Host has more than one atomic group!'
-        print list(atomic_groups)
-        sys.exit(1)
-    host_atomic_group_label = host_atomic_group_labels[0]
-    host_atomic_group_name = host_atomic_group_label['atomic_group']['name']
-
-job_atomic_groups = set(entry['atomic_group'] for entry in queue_entries)
-assert len(job_atomic_groups) == 1, 'Job has more than one atomic group value!'
-job_atomic_group = job_atomic_groups.pop() # might be None
-job_atomic_group_name = None
-if job_atomic_group:
-    job_atomic_group_name = job_atomic_group['name']
-
-if host_atomic_group_name != job_atomic_group_name:
-    print ('Job is for atomic group %s, but host is in atomic group %s '
-           '(label %s)' %
-           (job_atomic_group_name, host_atomic_group_name,
-            host_atomic_group_label['name']))
-    sys.exit(0)
-
 # meets only_if_needed labels?
 if is_metahost:
     metahost_names = set(entry['meta_host']
@@ -334,9 +325,25 @@
         if unmet_exclusive_label:
             print ('Host contains "only if needed" label %s, unused by job '
                    'dependencies and metahosts' % label['name'])
-            sys.exit(0)
+            job_will_run = False
 
-print ("Job %s should run on host %s; if you've already waited about ten "
-       "minutes or longer, it's probably a server issue or a bug." %
-       (job_id, hostname))
-sys.exit(1)
+# host ready?
+if host['status'] != 'Ready':
+    if host['status'] == 'Pending':
+        active = proxy.run('get_host_queue_entries',
+                           host=host['id'], active=True)
+        if not active:
+            print ('Host %s seems to be in "Pending" state incorrectly; please 
'
+                   'report this to the Autotest team' % hostname)
+            sys.exit(1)
+    print 'Host not in "Ready" status (status="%s")' % host['status']
+    job_will_run = False
+
+if job_will_run:
+    print ("Job %s should run on host %s; if you've already waited about ten "
+           "minutes or longer, it's probably a server issue or a bug." %
+           (job_id, hostname))
+    sys.exit(1)
+else:
+    print "All of the reasons this job is not running are listed above."
+    sys.exit(0)
_______________________________________________
Autotest mailing list
[email protected]
http://test.kernel.org/cgi-bin/mailman/listinfo/autotest

Reply via email to