TT#190200 build: provide endpoint to check release config

/config/check/ admits POST with release config yaml

Change-Id: Iefdb4d807f600015ebb8e9074c46f483a12e4430
pull/9/head
Victor Seva 3 years ago
parent 6cf063d908
commit 6a04b32005

@ -15,6 +15,7 @@
from django.test import override_settings
from django.urls import reverse
from rest_framework import status
from rest_framework.test import APISimpleTestCase
from build import models
from repoapi.test.base import APIAuthenticatedTestCase
@ -216,3 +217,27 @@ class TestBuildPatchRest(APIAuthenticatedTestCase):
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
br = models.BuildRelease.objects.get(uuid=self.release_uuid)
self.assertEqual(br.projects, "kamailio,lua-ngcp-kamailio,ngcp-panel")
class TestCheckConfig(APISimpleTestCase):
url = reverse("check-config")
def setUp(self):
self.data = {
"jenkins-jobs": {},
"distris": ["release-trunk-buster"],
"release-trunk-buster": [],
}
def test_empty(self):
response = self.client.post(self.url, {}, format="json")
self.assertEqual(response.status_code, status.HTTP_406_NOT_ACCEPTABLE)
def test_clean(self):
response = self.client.post(self.url, self.data, format="json")
self.assertEqual(response.status_code, status.HTTP_200_OK)
def test_circular_deps(self):
self.data["jenkins-jobs"]["build_deps"] = {"A": ["A1", "A"]}
response = self.client.post(self.url, self.data, format="json")
self.assertEqual(response.status_code, status.HTTP_406_NOT_ACCEPTABLE)

@ -589,3 +589,35 @@ class WannaBuildTestCase(SimpleTestCase):
}
config = self.FakeConfig(build_deps)
config.check_circular_dependencies()
class CheckConfig(SimpleTestCase):
def setUp(self):
self.data = {
"jenkins-jobs": {},
"distris": ["release-trunk-buster"],
"release-trunk-buster": [],
}
def test_empty(self):
data = {}
with self.assertRaises(err.NoJenkinsJobsInfo):
ReleaseConfig("fake", config=data)
def test_no_distris(self):
data = {"jenkins-jobs": []}
with self.assertRaises(err.NoDistrisInfo):
ReleaseConfig("fake", config=data)
def test_no_release(self):
data = {"jenkins-jobs": [], "distris": []}
with self.assertRaises(err.NoReleaseInfo):
ReleaseConfig("fake", config=data)
def test_simple(self):
ReleaseConfig("fake", config=self.data)
def test_circular_dep(self):
self.data["jenkins-jobs"]["build_deps"] = {"A": ["A1", "A"]}
with self.assertRaises(err.CircularBuildDependencies):
ReleaseConfig("fake", config=self.data)

@ -226,7 +226,7 @@ class ReleaseConfig(object):
def check_circular_dependencies(self):
levels = self.levels_build_deps
builds = list(self.build_deps.keys())
print(f"{levels}")
print(f"builds:{builds} levels:{levels}")
for vals in levels:
for prj in vals:
builds.remove(prj)
@ -276,7 +276,7 @@ class ReleaseConfig(object):
]
return humansorted(res, lambda x: x["release"], reverse=True)
def __init__(self, name, distribution=None):
def _get_config(self, name, distribution=None):
ok, self.distribution = is_release_trunk(name)
if not ok and name == "trunk":
self.distribution = distribution
@ -288,6 +288,14 @@ class ReleaseConfig(object):
settings.BUILD_REPOS_SCRIPTS_CONFIG_DIR / self.config_file
)
self.config = self.load_config(self.config_path)
def __init__(self, name, distribution=None, config=None):
if config is None:
self._get_config(name, distribution)
else:
self.config_file = "fake.yml"
self.config_path = "/dev/null"
self.config = config
try:
self.jenkins_jobs = self.config["jenkins-jobs"]
except KeyError:

@ -16,14 +16,17 @@ import django_filters
from django.http import JsonResponse
from django.shortcuts import get_object_or_404
from rest_framework import generics
from rest_framework.parsers import JSONParser
from rest_framework.permissions import DjangoModelPermissions
from rest_framework.response import Response
from rest_framework.views import APIView
from rest_framework_api_key.permissions import HasAPIKey
from rest_framework_yaml.parsers import YAMLParser
from . import models
from . import serializers
from . import tasks
from . import utils
from repoapi.serializers import JenkinsBuildInfoSerializer as JBISerializer
@ -107,3 +110,14 @@ class ReleaseJobsUUID(APIView):
serializer = JBISerializer(jbi, context={"request": request})
res.append(serializer.data)
return Response(res)
class CheckConfig(APIView):
parser_classes = [YAMLParser, JSONParser]
def post(self, request, format=None):
try:
utils.ReleaseConfig("fake", config=request.data)
return JsonResponse({"result": "All ok"}, status=200)
except Exception as e:
return JsonResponse({"error": f"{e}"}, status=406)

@ -94,6 +94,11 @@ api_patterns = [
docker.DockerTagDetail.as_view(),
name="dockertag-detail",
),
re_path(
r"^config/check/$",
build_views.CheckConfig.as_view(),
name="check-config",
),
re_path(r"^build/", include("build.urls")),
re_path(r"^release_changed/", include("release_changed.urls")),
]

@ -13,6 +13,7 @@ django-structlog
django-timezone-field
djangorestframework>=3.6
djangorestframework-api-key==2.*
djangorestframework-yaml
drf-spectacular
flower>=0.9.5
markdown

@ -5,7 +5,7 @@ FROM docker.mgm.sipwise.com/sipwise-bullseye:latest
# is updated with the current date. It will force refresh of all
# of the base images and things like `apt-get update` won't be using
# old cached versions when the Dockerfile is built.
ENV REFRESHED_AT 2022-08-12
ENV REFRESHED_AT 2022-09-22
RUN apt-get update && apt-get install --assume-yes python3 python3-dev \
python3-pytest python3-pytest-pep8 \

Loading…
Cancel
Save