diff mbox

[Branch,~linaro-validation/lava-scheduler/trunk] Rev 111: improvements to the job view when there is no log file

Message ID 20120112230614.20119.69051.launchpad@ackee.canonical.com
State Accepted
Headers show

Commit Message

Michael-Doyle Hudson Jan. 12, 2012, 11:06 p.m. UTC
Merge authors:
  Michael Hudson-Doyle (mwhudson)
Related merge proposals:
  https://code.launchpad.net/~mwhudson/lava-scheduler/no-log-file-bug-914731/+merge/88281
  proposed by: Michael Hudson-Doyle (mwhudson)
  review: Approve - Zygmunt Krynicki (zkrynicki)
------------------------------------------------------------
revno: 111 [merge]
committer: Michael Hudson-Doyle <michael.hudson@linaro.org>
branch nick: trunk
timestamp: Fri 2012-01-13 12:04:15 +1300
message:
  improvements to the job view when there is no log file
modified:
  lava_scheduler_app/logfile_helper.py
  lava_scheduler_app/templates/lava_scheduler_app/job.html
  lava_scheduler_app/templates/lava_scheduler_app/job_sidebar.html
  lava_scheduler_app/views.py


--
lp:lava-scheduler
https://code.launchpad.net/~linaro-validation/lava-scheduler/trunk

You are subscribed to branch lp:lava-scheduler.
To unsubscribe from this branch go to https://code.launchpad.net/~linaro-validation/lava-scheduler/trunk/+edit-subscription
diff mbox

Patch

=== modified file 'lava_scheduler_app/logfile_helper.py'
--- lava_scheduler_app/logfile_helper.py	2011-12-13 04:22:40 +0000
+++ lava_scheduler_app/logfile_helper.py	2012-01-11 22:09:33 +0000
@@ -1,9 +1,6 @@ 
-import os
 import re
 
 def getDispatcherErrors(logfile):
-    if not logfile:
-        return "Log file is missing"
     errors = ""
     for line in logfile:
         if line.find("CriticalError:") != -1 or \
@@ -12,18 +9,7 @@ 
 
     return errors
 
-def getDispatcherLogSize(logfile):
-    if not logfile:
-        return 0
-    else:
-        logfile.seek(0, os.SEEK_END)
-        size = logfile.tell()
-        return size
-
 def getDispatcherLogMessages(logfile):
-    if not logfile:
-        return ('', "Log file is missing")
-
     logs = []
     log_prefix = '<LAVA_DISPATCHER>'
     level_pattern = re.compile('....-..-.. ..:..:.. .. ([A-Z]+):')

=== modified file 'lava_scheduler_app/templates/lava_scheduler_app/job.html'
--- lava_scheduler_app/templates/lava_scheduler_app/job.html	2011-12-15 20:55:43 +0000
+++ lava_scheduler_app/templates/lava_scheduler_app/job.html	2012-01-11 22:20:43 +0000
@@ -8,6 +8,10 @@ 
 
 {% block content %}
 <h2>Dispatcher Log Summary</h2>
+{% if job.status < job.RUNNING %}
+No log file yet.
+{% else %}
+{% if job_file_present %}
 {% if job_has_error %}
 <div id="dispatcher-error">
 <h3>Dispatcher error or test failure</h3>
@@ -32,8 +36,14 @@ 
 <img src="{{ STATIC_URL }}lava_scheduler_app/images/ajax-progress.gif"/>
 {% endif %}
 </div>
+{% else %}
+<p>
+Job file missing.
+</p>
+{% endif %}
+{% endif %}
 
-<script type="text/javascript">
+</p><script type="text/javascript">
 $('.logbuttons input').button()
 function showHideLogClick () {
   var rule = rules[$(this).attr('id')];
@@ -51,7 +61,7 @@ 
 '': undefined
 }
 
-{% if job.status == job.RUNNING %}
+{% if job.status == job.RUNNING and job_file_present %}
 var pollTimer = null, logLenth = '{{ job_file_size }}';
 
 function poll (start) {

=== modified file 'lava_scheduler_app/templates/lava_scheduler_app/job_sidebar.html'
--- lava_scheduler_app/templates/lava_scheduler_app/job_sidebar.html	2011-12-15 20:55:43 +0000
+++ lava_scheduler_app/templates/lava_scheduler_app/job_sidebar.html	2012-01-11 22:04:22 +0000
@@ -61,9 +61,11 @@ 
     <li>
         <a href="{% url lava.scheduler.job.detail job.pk %}">Summary</a>
     </li>
+{% if job_file_present %}
     <li>
         <a href="{% url lava.scheduler.job.log_file job.pk %}">Complete log</a>
     </li>
+{% endif %}
     <li>
         <a href="{% url lava.scheduler.job.definition job.pk %}">Defintion</a>
     </li>

=== modified file 'lava_scheduler_app/views.py'
--- lava_scheduler_app/views.py	2011-12-13 03:58:12 +0000
+++ lava_scheduler_app/views.py	2012-01-11 22:20:27 +0000
@@ -1,11 +1,9 @@ 
 from collections import defaultdict
-import simplejson
 import logging
 import os
+import simplejson
 import StringIO
 
-from logfile_helper import formatLogFile, getDispatcherErrors
-from logfile_helper import getDispatcherLogMessages, getDispatcherLogSize
 
 from django.http import (
     HttpResponse,
@@ -19,13 +17,19 @@ 
     render_to_response,
 )
 
-from lava_scheduler_app.models import Device, TestJob
 from lava_server.views import index as lava_index
 from lava_server.bread_crumbs import (
     BreadCrumb,
     BreadCrumbTrail,
 )
 
+from lava_scheduler_app.logfile_helper import (
+    formatLogFile,
+    getDispatcherErrors,
+    getDispatcherLogMessages
+    )
+from lava_scheduler_app.models import Device, TestJob
+
 
 def post_only(func):
     def decorated(request, *args, **kwargs):
@@ -66,30 +70,39 @@ 
 @BreadCrumb("Job #{pk}", parent=index, needs=['pk'])
 def job_detail(request, pk):
     job = get_object_or_404(TestJob, pk=pk)
-    job_errors = getDispatcherErrors(job.log_file)
-    job_log_messages = getDispatcherLogMessages(job.log_file)
-
-    levels = defaultdict(int)
-    for kl in ['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL']:
-        levels[kl] = 0
-    for level, msg in job_log_messages:
-        levels[level] += 1
-    levels = sorted(levels.items(), key=lambda (k,v):logging._levelNames.get(k))
-
-    return render_to_response(
-        "lava_scheduler_app/job.html",
-        {
-            'job': TestJob.objects.get(pk=pk),
-            'show_cancel': job.status <= TestJob.RUNNING and job.can_cancel(request.user),
-            'bread_crumb_trail': BreadCrumbTrail.leading_to(job_detail, pk=pk),
+
+    data = {
+        'job': job,
+        'show_cancel': job.status <= TestJob.RUNNING and job.can_cancel(request.user),
+        'bread_crumb_trail': BreadCrumbTrail.leading_to(job_detail, pk=pk),
+        'show_reload_page' : job.status <= TestJob.RUNNING,
+    }
+
+    if job.log_file:
+        job_errors = getDispatcherErrors(job.log_file)
+        job_log_messages = getDispatcherLogMessages(job.log_file)
+
+        levels = defaultdict(int)
+        for kl in ['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL']:
+            levels[kl] = 0
+        for level, msg in job_log_messages:
+            levels[level] += 1
+        levels = sorted(levels.items(), key=lambda (k,v):logging._levelNames.get(k))
+        data.update({
+            'job_file_present': True,
             'job_errors' : job_errors,
             'job_has_error' : len(job_errors) > 0,
             'job_log_messages' : job_log_messages,
             'levels': levels,
-            'show_reload_page' : job.status <= TestJob.RUNNING,
-            'job_file_size' : getDispatcherLogSize(job.log_file),
-        },
-        RequestContext(request))
+            'job_file_size' : job.log_file.size,
+            })
+    else:
+        data.update({
+            'job_file_present': False,
+            })
+
+    return render_to_response(
+        "lava_scheduler_app/job.html", data, RequestContext(request))
 
 
 def job_definition(request, pk):
@@ -98,6 +111,7 @@ 
         "lava_scheduler_app/job_definition.html",
         {
             'job': job,
+            'job_file_present': bool(job.log_file),
         },
         RequestContext(request))
 
@@ -117,8 +131,9 @@ 
         "lava_scheduler_app/job_log_file.html",
         {
             'job': TestJob.objects.get(pk=pk),
+            'job_file_present': bool(job.log_file),
             'sections' : content,
-            'job_file_size' : getDispatcherLogSize(job.log_file),
+            'job_file_size' : job.log_file.size,
         },
         RequestContext(request))