Merge lp:~le-chi-thu/lava-scheduler/loop-health-check-job into lp:lava-scheduler

Proposed by Le Chi Thu
Status: Merged
Approved by: Michael Hudson-Doyle
Approved revision: 170
Merged at revision: 170
Proposed branch: lp:~le-chi-thu/lava-scheduler/loop-health-check-job
Merge into: lp:lava-scheduler
Diff against target: 173 lines (+56/-20)
5 files modified
lava_scheduler_app/models.py (+15/-1)
lava_scheduler_app/templates/lava_scheduler_app/_device_base.html (+5/-0)
lava_scheduler_app/urls.py (+17/-14)
lava_scheduler_app/views.py (+11/-0)
lava_scheduler_daemon/dbjobsource.py (+8/-5)
To merge this branch: bzr merge lp:~le-chi-thu/lava-scheduler/loop-health-check-job
Reviewer Review Type Date Requested Status
Michael Hudson-Doyle (community) Approve
Review via email: mp+107019@code.launchpad.net

Description of the change

Added looping state for health check job. When in this state, the health check job will run forever. Admin should then put the device to maintaining mode to terminate the looping.

Scheduler device page is updated with a button to put the device into looping mode.

To post a comment you must log in.
Revision history for this message
Michael Hudson-Doyle (mwhudson) wrote :

Nice!

I'm not sure having the button on the page is really necessary -- I would have been happy to use the admin interface for this, I think -- but since it's done, it's nice to have indeed.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lava_scheduler_app/models.py'
2--- lava_scheduler_app/models.py 2012-04-20 03:22:44 +0000
3+++ lava_scheduler_app/models.py 2012-05-23 13:56:35 +0000
4@@ -74,11 +74,12 @@
5 )
6
7 # A device health shows a device is ready to test or not
8- HEALTH_UNKNOWN, HEALTH_PASS, HEALTH_FAIL = range(3)
9+ HEALTH_UNKNOWN, HEALTH_PASS, HEALTH_FAIL, HEALTH_LOOPING = range(4)
10 HEALTH_CHOICES = (
11 (HEALTH_UNKNOWN, 'Unknown'),
12 (HEALTH_PASS, 'Pass'),
13 (HEALTH_FAIL, 'Fail'),
14+ (HEALTH_LOOPING, 'Looping'),
15 )
16
17 hostname = models.CharField(
18@@ -147,6 +148,8 @@
19 created_by=user, device=self, old_state=self.status,
20 new_state=new_status, message=reason, job=None).save()
21 self.status = new_status
22+ if self.health_status == Device.HEALTH_LOOPING:
23+ self.health_status = Device.HEALTH_UNKNOWN
24 self.save()
25
26 def put_into_online_mode(self, user, reason):
27@@ -160,6 +163,17 @@
28 self.health_status = Device.HEALTH_UNKNOWN
29 self.save()
30
31+ def put_into_looping_mode(self, user):
32+ if self.status not in [Device.OFFLINE, Device.OFFLINING]:
33+ return
34+ new_status = self.IDLE
35+ DeviceStateTransition.objects.create(
36+ created_by=user, device=self, old_state=self.status,
37+ new_state=new_status, message="Looping mode", job=None).save()
38+ self.status = new_status
39+ self.health_status = Device.HEALTH_LOOPING
40+ self.save()
41+
42 #@classmethod
43 #def find_devices_by_type(cls, device_type):
44 # return device_type.device_set.all()
45
46=== modified file 'lava_scheduler_app/templates/lava_scheduler_app/_device_base.html'
47--- lava_scheduler_app/templates/lava_scheduler_app/_device_base.html 2012-03-09 02:49:54 +0000
48+++ lava_scheduler_app/templates/lava_scheduler_app/_device_base.html 2012-05-23 13:56:35 +0000
49@@ -54,6 +54,11 @@
50 {% csrf_token %}
51 <input name="reason" style="width: 100%"/>
52 </form>
53+<form style="display:inline " method="POST"
54+ action="{% url lava.scheduler.device.looping device.pk %}">
55+ {% csrf_token %}
56+ <button id="looping-button">Put into looping mode</button>
57+</form>
58 {% endif %}
59
60 <div id="columns">
61
62=== modified file 'lava_scheduler_app/urls.py'
63--- lava_scheduler_app/urls.py 2012-03-02 04:35:51 +0000
64+++ lava_scheduler_app/urls.py 2012-05-23 13:56:35 +0000
65@@ -3,33 +3,36 @@
66
67 urlpatterns = patterns(
68 'lava_scheduler_app.views',
69- url(r'^$',
70+ url(r'^$',
71 'index',
72 name='lava.scheduler'),
73- url(r'^active_jobs_json$',
74+ url(r'^active_jobs_json$',
75 'index_active_jobs_json',
76 name='lava.scheduler.active_jobs_json'),
77- url(r'^devices_json$',
78+ url(r'^devices_json$',
79 'index_devices_json',
80 name='lava.scheduler.index_devices_json'),
81- url(r'^alljobs$',
82- 'job_list',
83+ url(r'^alljobs$',
84+ 'job_list',
85 name='lava.scheduler.job.list'),
86 url(r'^alljobs_json$',
87 'alljobs_json',
88 name='lava.scheduler.job.list_json'),
89- url(r'^device/(?P<pk>[-_a-zA-Z0-9]+)$',
90- 'device_detail',
91+ url(r'^device/(?P<pk>[-_a-zA-Z0-9]+)$',
92+ 'device_detail',
93 name='lava.scheduler.device.detail'),
94- url(r'^device/(?P<pk>[-_a-zA-Z0-9]+)/recent_jobs_json$',
95- 'recent_jobs_json',
96+ url(r'^device/(?P<pk>[-_a-zA-Z0-9]+)/recent_jobs_json$',
97+ 'recent_jobs_json',
98 name='lava.scheduler.device.recent_jobs_json'),
99- url(r'^device/(?P<pk>[-_a-zA-Z0-9]+)/transition_json$',
100- 'transition_json',
101+ url(r'^device/(?P<pk>[-_a-zA-Z0-9]+)/transition_json$',
102+ 'transition_json',
103 name='lava.scheduler.device.transition_json'),
104- url(r'^device/(?P<pk>[-_a-zA-Z0-9]+)/maintenance$',
105- 'device_maintenance_mode',
106+ url(r'^device/(?P<pk>[-_a-zA-Z0-9]+)/maintenance$',
107+ 'device_maintenance_mode',
108 name='lava.scheduler.device.maintenance'),
109+ url(r'^device/(?P<pk>[-_a-zA-Z0-9]+)/looping$',
110+ 'device_looping_mode',
111+ name='lava.scheduler.device.looping'),
112 url(r'^device/(?P<pk>[-_a-zA-Z0-9]+)/online$',
113 'device_online',
114 name='lava.scheduler.device.online'),
115@@ -64,7 +67,7 @@
116 'job_cancel',
117 name='lava.scheduler.job.cancel'),
118 url(r'^job/(?P<pk>[0-9]+)/json$',
119- 'job_json',
120+ 'job_json',
121 name='lava.scheduler.job.json'),
122 url(r'^job/(?P<pk>[0-9]+)/output$',
123 'job_output',
124
125=== modified file 'lava_scheduler_app/views.py'
126--- lava_scheduler_app/views.py 2012-03-19 02:01:59 +0000
127+++ lava_scheduler_app/views.py 2012-05-23 13:56:35 +0000
128@@ -573,3 +573,14 @@
129 else:
130 return HttpResponseForbidden(
131 "you cannot administer this device", content_type="text/plain")
132+
133+@post_only
134+def device_looping_mode(request, pk):
135+ device = Device.objects.get(pk=pk)
136+ if device.can_admin(request.user):
137+ device.put_into_looping_mode(request.user)
138+ return redirect(device)
139+ else:
140+ return HttpResponseForbidden(
141+ "you cannot administer this device", content_type="text/plain")
142+
143
144=== modified file 'lava_scheduler_daemon/dbjobsource.py'
145--- lava_scheduler_daemon/dbjobsource.py 2012-04-05 04:34:13 +0000
146+++ lava_scheduler_daemon/dbjobsource.py 2012-05-23 13:56:35 +0000
147@@ -152,6 +152,8 @@
148 run_health_check = False
149 elif device.health_status == Device.HEALTH_UNKNOWN:
150 run_health_check = True
151+ elif device.health_status == Device.HEALTH_LOOPING:
152+ run_health_check = True
153 elif not device.last_health_report_job:
154 run_health_check = True
155 else:
156@@ -238,11 +240,12 @@
157
158 if job.health_check:
159 device.last_health_report_job = job
160- if job.status == TestJob.INCOMPLETE:
161- device.health_status = Device.HEALTH_FAIL
162- device.put_into_maintenance_mode(None, "Health Check Job Failed")
163- elif job.status == TestJob.COMPLETE:
164- device.health_status = Device.HEALTH_PASS
165+ if device.health_status != Device.HEALTH_LOOPING:
166+ if job.status == TestJob.INCOMPLETE:
167+ device.health_status = Device.HEALTH_FAIL
168+ device.put_into_maintenance_mode(None, "Health Check Job Failed")
169+ elif job.status == TestJob.COMPLETE:
170+ device.health_status = Device.HEALTH_PASS
171
172 job.end_time = datetime.datetime.utcnow()
173 token = job.submit_token

Subscribers

People subscribed via source and target branches