Commit d7cba2d1 authored by Rémi Duraffort's avatar Rémi Duraffort Committed by Neil Williams

LAVA-1250 Allow admin to finish a TestJob

This should only be used when lava-run is stopped.
Only superuser are allowed to use this function.

Change-Id: Ibcba8e2d9dbf4e3d4f5d84cf1ab3115e8cf9f44e
parent ec01c5bf
......@@ -74,6 +74,17 @@ def cancel_action(modeladmin, request, queryset): # pylint: disable=unused-argu
cancel_action.short_description = 'cancel selected jobs'
def fail_action(modeladmin, request, queryset):
if request.user.is_superuser:
with transaction.atomic():
for testjob in queryset.select_for_update().filter(state=TestJob.STATE_CANCELING):
testjob.go_state_finished(TestJob.HEALTH_INCOMPLETE)
testjob.save()
fail_action.short_description = 'fail selected jobs'
class ActiveDevicesFilter(admin.SimpleListFilter):
title = 'Active devices'
parameter_name = 'state'
......@@ -244,7 +255,7 @@ class TestJobAdmin(admin.ModelAdmin):
return '' if obj.requested_device_type is None else obj.requested_device_type
requested_device_type_name.short_description = 'Request device type'
form = VisibilityForm
actions = [cancel_action]
actions = [cancel_action, fail_action]
list_filter = ('state', RequestedDeviceTypeFilter, ActualDeviceFilter)
fieldsets = (
('Owner', {
......
......@@ -262,6 +262,12 @@
{% else %}
<a class="btn btn-warning" id="cancel" href="{% url 'lava.scheduler.job.cancel' job.pk %}">Cancel</a>
{% endif %}
{% elif show_fail %}
{% if job.is_multinode %}
<a class="btn btn-danger" id="fail" title="This should not be used if lava-run is still running" href="{% url 'lava.scheduler.job.fail' job.sub_id %}">Fail</a>
{% else %}
<a class="btn btn-danger" id="fail" title="This should not be used if lava-run is still running" href="{% url 'lava.scheduler.job.fail' job.pk %}">Fail</a>
{% endif %}
{% endif %}
{% if show_resubmit %}
<a class="btn btn-primary" href="{% url 'lava.scheduler.job.resubmit' job.pk %}">Resubmit</a>
......@@ -728,6 +734,7 @@
}
if ('X-JobState' in data) {
$('#cancel').css('display', 'none');
$('#fail').css('display', 'none');
poll_status = 0;
}
if (data['failure_comment'] != null) {
......
......@@ -11,7 +11,7 @@ from lava_scheduler_app.views import (
device_type_reports, edit_worker_desc,
failure_report, favorite_jobs,
get_remote_definition, health_job_list, healthcheck, index,
job_annotate_failure, job_cancel, job_change_priority, job_complete_log,
job_annotate_failure, job_cancel, job_fail, job_change_priority, job_complete_log,
job_definition, job_definition_plain, job_description_yaml, job_detail,
job_list,
job_log_file_plain, job_log_pipeline_incremental,
......@@ -80,6 +80,8 @@ urlpatterns = [
name='lava.scheduler.job.section_log'),
url(r'^job/(?P<pk>[0-9]+|[0-9]+\.[0-9]+)/cancel$', job_cancel,
name='lava.scheduler.job.cancel'),
url(r'^job/(?P<pk>[0-9]+|[0-9]+\.[0-9]+)/fail$', job_fail,
name='lava.scheduler.job.fail'),
url(r'^job/(?P<pk>[0-9]+|[0-9]+\.[0-9]+)/resubmit$', job_resubmit,
name='lava.scheduler.job.resubmit'),
url(r'^job/(?P<pk>[0-9]+|[0-9]+\.[0-9]+)/annotate_failure$',
......
......@@ -1081,6 +1081,7 @@ def job_detail(request, pk):
data = {
'job': job,
'show_cancel': job.can_cancel(request.user),
'show_fail': job.state == TestJob.STATE_CANCELING and request.user.is_superuser,
'show_failure': job.can_annotate(request.user),
'show_resubmit': job.can_resubmit(request.user),
'bread_crumb_trail': BreadCrumbTrail.leading_to(job_detail, pk=pk),
......@@ -1572,6 +1573,21 @@ def job_cancel(request, pk):
"you cannot cancel this job", content_type="text/plain")
def job_fail(request, pk):
if not request.user.is_superuser:
return HttpResponseForbidden("Only superusers can fail a job",
content_type="text/plain")
with transaction.atomic():
job = get_restricted_job(request.user, pk, request=request, for_update=True)
if job.state != TestJob.STATE_CANCELING:
return HttpResponseForbidden("Job should be canceled before behing failed",
content_type="text/plain")
job.go_state_finished(TestJob.HEALTH_INCOMPLETE)
job.save()
return redirect(job)
def job_resubmit(request, pk):
is_resubmit = request.POST.get("is_resubmit", False)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment