Commit cd5a1e32 authored by Milosz Wasilewski's avatar Milosz Wasilewski

Merge branch 'rest-api-jobs-part2' into 'master'

api: Add validate as extra routing action for TestJobs REST API.

See merge request !999
parents f06bee8f 5ede97e1
Pipeline #7088 passed with stages
in 8 minutes and 6 seconds
......@@ -21,7 +21,9 @@ import csv
import io
import os
import pathlib
import voluptuous
import yaml
import lava_common.schemas as schemas
from django.conf import settings
from django.http.response import HttpResponse
......@@ -49,7 +51,7 @@ from lava_scheduler_app.models import Alias, Tag
from . import serializers
from rest_framework.decorators import detail_route
from rest_framework.decorators import detail_route, action
except ImportError:
from rest_framework.decorators import action
......@@ -65,6 +67,10 @@ class TestJobViewSet(base_views.TestJobViewSet):
* `/jobs/`
You can alidate the given job definition against the schema validator via POST request on:
* `/jobs/validate/`
The logs, test results and test suites of a specific TestJob are available at:
* `/jobs/<job_id>/logs/`
......@@ -127,6 +133,26 @@ class TestJobViewSet(base_views.TestJobViewSet):
def metadata(self, request, **kwargs):
return Response({"metadata": self.get_object().get_metadata_dict()})
@action(methods=["post"], detail=False, suffix="validate")
def validate(self, request, **kwargs):
definition ="definition", None)
strict ="strict", False)
if not definition:
raise ValidationError({"definition": "Test job definition is required."})
data = yaml_safe_load(definition)
return Response({"message": "Job valid."}, status=status.HTTP_200_OK)
except voluptuous.Invalid as exc:
return Response(
{"message": "Job invalid: %s" % exc.msg}, status=status.HTTP_200_OK
class TestSuiteViewSet(NestedViewSetMixin, viewsets.ReadOnlyModelViewSet):
queryset = TestSuite.objects
......@@ -470,6 +470,15 @@ ok 2 bar
data[0]["suite"] == self.public_testjob1.testsuite_set.first().name
) # nosec - unit test support
def test_testjob_validate(self):
response =
reverse("api-root", args=[self.version]) + "jobs/validate/",
{"definition": EXAMPLE_WORKING_JOB},
assert response.status_code == 200 # nosec - unit test support
msg = json.loads(response.content)
assert msg["message"] == "Job valid."
def test_devices_list(self):
data = self.hit(
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