mirror of https://github.com/sipwise/repoapi.git
check-ngcp-release-changes job will send via jbi its info. Then the app will process the data and keep it to provide /release_changed/<vmtype>/<version>/ URL to check the status. Will respond with 200 OK if the result was SUCCESS and 404 with NOT_FOUND otherwise. Change-Id: I242003cf2b01ae235e47d1a1d1a26aaabd9eb82epull/3/head
parent
44d095f510
commit
72cfecd34c
@ -0,0 +1,22 @@
|
||||
# Copyright (C) 2020 The Sipwise Team - http://sipwise.com
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License as published by the Free
|
||||
# Software Foundation, either version 3 of the License, or (at your option)
|
||||
# any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
# more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License along
|
||||
# with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
from django.contrib import admin
|
||||
|
||||
from . import models
|
||||
|
||||
|
||||
@admin.register(models.ReleaseChanged)
|
||||
class ReleaseChangedAdmin(admin.ModelAdmin):
|
||||
pass
|
@ -0,0 +1,19 @@
|
||||
# Copyright (C) 2020 The Sipwise Team - http://sipwise.com
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License as published by the Free
|
||||
# Software Foundation, either version 3 of the License, or (at your option)
|
||||
# any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
# more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License along
|
||||
# with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class ReleaseChangedConfig(AppConfig):
|
||||
name = "release_changed"
|
@ -0,0 +1,23 @@
|
||||
# Copyright (C) 2020 The Sipwise Team - http://sipwise.com
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License as published by the Free
|
||||
# Software Foundation, either version 3 of the License, or (at your option)
|
||||
# any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
# more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License along
|
||||
# with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
from django.conf import settings # noqa
|
||||
from appconf import AppConf
|
||||
|
||||
|
||||
class ReleaseChangedConf(AppConf):
|
||||
JOBS = ["check-ngcp-release-changes"]
|
||||
|
||||
class Meta:
|
||||
prefix = "release_changed"
|
@ -0,0 +1,37 @@
|
||||
{
|
||||
"_class": "org.jenkinsci.plugins.envinject.EnvInjectVarList",
|
||||
"envMap": {
|
||||
"BUILD_CAUSE": "UPSTREAMTRIGGER",
|
||||
"BUILD_CAUSE_UPSTREAMTRIGGER": "true",
|
||||
"BUILD_DISPLAY_NAME": "#222",
|
||||
"BUILD_ID": "222",
|
||||
"BUILD_NUMBER": "222",
|
||||
"BUILD_TAG": "jenkins-check-ngcp-release-changes-222",
|
||||
"BUILD_URL": "https://jenkins-dev.mgm.sipwise.com/job/check-ngcp-release-changes/222/",
|
||||
"EXECUTOR_NUMBER": "0",
|
||||
"HOME": "/var/lib/jenkins",
|
||||
"HUDSON_HOME": "/var/lib/jenkins",
|
||||
"HUDSON_SERVER_COOKIE": "a8d77173115744a9",
|
||||
"HUDSON_URL": "https://jenkins-dev.mgm.sipwise.com/",
|
||||
"INVOCATION_ID": "0ab651fd44f64180ba95cf267fb647bd",
|
||||
"JENKINS_HOME": "/var/lib/jenkins",
|
||||
"JENKINS_SERVER_COOKIE": "a8d77173115744a9",
|
||||
"JENKINS_URL": "https://jenkins-dev.mgm.sipwise.com/",
|
||||
"JOB_BASE_NAME": "check-ngcp-release-changes",
|
||||
"JOB_NAME": "check-ngcp-release-changes",
|
||||
"JOB_URL": "https://jenkins-dev.mgm.sipwise.com/job/check-ngcp-release-changes/",
|
||||
"JOURNAL_STREAM": "9:16165",
|
||||
"LANG": "C.UTF-8",
|
||||
"LOGNAME": "jenkins",
|
||||
"NODE_LABELS": "jenkins-dev1 master-swarm swarm",
|
||||
"NODE_NAME": "jenkins-dev1",
|
||||
"PATH": "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
|
||||
"ROOT_BUILD_CAUSE": "MANUALTRIGGER",
|
||||
"ROOT_BUILD_CAUSE_MANUALTRIGGER": "true",
|
||||
"RUN_DISPLAY_URL": "https://jenkins-dev.mgm.sipwise.com/job/check-ngcp-release-changes/222/display/redirect",
|
||||
"USER": "jenkins",
|
||||
"vmdone": "no",
|
||||
"vmtype": "CE",
|
||||
"vmversion": "mr8.5.1"
|
||||
}
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
{
|
||||
"_class": "org.jenkinsci.plugins.envinject.EnvInjectVarList",
|
||||
"envMap": {
|
||||
"BUILD_CAUSE": "UPSTREAMTRIGGER",
|
||||
"BUILD_CAUSE_UPSTREAMTRIGGER": "true",
|
||||
"BUILD_DISPLAY_NAME": "#222",
|
||||
"BUILD_ID": "223",
|
||||
"BUILD_NUMBER": "223",
|
||||
"BUILD_TAG": "jenkins-check-ngcp-release-changes-223",
|
||||
"BUILD_URL": "https://jenkins-dev.mgm.sipwise.com/job/check-ngcp-release-changes/223/",
|
||||
"EXECUTOR_NUMBER": "0",
|
||||
"HOME": "/var/lib/jenkins",
|
||||
"HUDSON_HOME": "/var/lib/jenkins",
|
||||
"HUDSON_SERVER_COOKIE": "a8d77173115744a9",
|
||||
"HUDSON_URL": "https://jenkins-dev.mgm.sipwise.com/",
|
||||
"INVOCATION_ID": "0ab651fd44f64180ba95cf267fb647bd",
|
||||
"JENKINS_HOME": "/var/lib/jenkins",
|
||||
"JENKINS_SERVER_COOKIE": "a8d77173115744a9",
|
||||
"JENKINS_URL": "https://jenkins-dev.mgm.sipwise.com/",
|
||||
"JOB_BASE_NAME": "check-ngcp-release-changes",
|
||||
"JOB_NAME": "check-ngcp-release-changes",
|
||||
"JOB_URL": "https://jenkins-dev.mgm.sipwise.com/job/check-ngcp-release-changes/",
|
||||
"JOURNAL_STREAM": "9:16165",
|
||||
"LANG": "C.UTF-8",
|
||||
"LOGNAME": "jenkins",
|
||||
"NODE_LABELS": "jenkins-dev1 master-swarm swarm",
|
||||
"NODE_NAME": "jenkins-dev1",
|
||||
"PATH": "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
|
||||
"ROOT_BUILD_CAUSE": "MANUALTRIGGER",
|
||||
"ROOT_BUILD_CAUSE_MANUALTRIGGER": "true",
|
||||
"RUN_DISPLAY_URL": "https://jenkins-dev.mgm.sipwise.com/job/check-ngcp-release-changes/223/display/redirect",
|
||||
"USER": "jenkins",
|
||||
"vmdone": "yes",
|
||||
"vmtype": "CE",
|
||||
"vmversion": "mr8.5.1"
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
- model: release_changed.releasechanged
|
||||
pk: 1
|
||||
fields:
|
||||
version: mr8.4
|
||||
vmtype: CE
|
||||
result: FAILURE
|
||||
date: 2020-09-09 08:50:01.671302+00:00
|
||||
- model: release_changed.releasechanged
|
||||
pk: 2
|
||||
fields:
|
||||
version: mr8.4
|
||||
vmtype: PRO
|
||||
result: SUCCESS
|
||||
date: 2020-09-09 08:54:13.908608+00:00
|
@ -0,0 +1,25 @@
|
||||
[
|
||||
{
|
||||
"fields": {
|
||||
"buildnumber": 1,
|
||||
"date": "2015-05-01T12:57:54.379Z",
|
||||
"gerrit_change": null,
|
||||
"gerrit_eventtype": null,
|
||||
"gerrit_patchset": null,
|
||||
"job_url": "https://jenkins.mgm.sipwise.com/job/check-ngcp-release-changes/",
|
||||
"param_branch": null,
|
||||
"param_distribution": null,
|
||||
"param_ppa": null,
|
||||
"param_release": null,
|
||||
"param_release_uuid": null,
|
||||
"param_tag": null,
|
||||
"projectname": "check-ngcp-release-changes",
|
||||
"jobname": "check-ngcp-release-changes",
|
||||
"repo_name": null,
|
||||
"result": "FAILED",
|
||||
"tag": null
|
||||
},
|
||||
"model": "repoapi.jenkinsbuildinfo",
|
||||
"pk": 1
|
||||
},
|
||||
]
|
@ -0,0 +1,53 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.11.29 on 2020-09-09 09:48
|
||||
from django.db import migrations
|
||||
from django.db import models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = []
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name="ReleaseChanged",
|
||||
fields=[
|
||||
(
|
||||
"id",
|
||||
models.AutoField(
|
||||
auto_created=True,
|
||||
primary_key=True,
|
||||
serialize=False,
|
||||
verbose_name="ID",
|
||||
),
|
||||
),
|
||||
("version", models.CharField(max_length=64)),
|
||||
(
|
||||
"vmtype",
|
||||
models.CharField(
|
||||
choices=[("CE", "spce"), ("PRO", "sppro")],
|
||||
max_length=3,
|
||||
),
|
||||
),
|
||||
(
|
||||
"result",
|
||||
models.CharField(
|
||||
choices=[
|
||||
("ABORTED", "ABORTED"),
|
||||
("FAILURE", "FAILURE"),
|
||||
("NOT_BUILT", "NOT_BUILT"),
|
||||
("SUCCESS", "SUCCESS"),
|
||||
("UNSTABLE", "UNSTABLE"),
|
||||
],
|
||||
max_length=50,
|
||||
),
|
||||
),
|
||||
("date", models.DateTimeField(auto_now=True)),
|
||||
],
|
||||
),
|
||||
migrations.AlterUniqueTogether(
|
||||
name="releasechanged", unique_together=set([("version", "vmtype")])
|
||||
),
|
||||
]
|
@ -0,0 +1,38 @@
|
||||
# Copyright (C) 2020 The Sipwise Team - http://sipwise.com
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License as published by the Free
|
||||
# Software Foundation, either version 3 of the License, or (at your option)
|
||||
# any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
# more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License along
|
||||
# with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
from django.db import models
|
||||
|
||||
|
||||
class ReleaseChanged(models.Model):
|
||||
VMTYPE_CHOICES = (("CE", "spce"), ("PRO", "sppro"))
|
||||
RESULT_CHOICES = (
|
||||
("ABORTED", "ABORTED"),
|
||||
("FAILURE", "FAILURE"),
|
||||
("NOT_BUILT", "NOT_BUILT"),
|
||||
("SUCCESS", "SUCCESS"),
|
||||
("UNSTABLE", "UNSTABLE"),
|
||||
)
|
||||
version = models.CharField(max_length=64, null=False)
|
||||
vmtype = models.CharField(max_length=3, null=False, choices=VMTYPE_CHOICES)
|
||||
result = models.CharField(
|
||||
max_length=50, null=False, choices=RESULT_CHOICES
|
||||
)
|
||||
date = models.DateTimeField(auto_now=True)
|
||||
|
||||
class Meta:
|
||||
unique_together = (("version", "vmtype"),)
|
||||
|
||||
def __str__(self):
|
||||
return "{0.vmtype}_{0.version}_{0.result}".format(self)
|
@ -0,0 +1,24 @@
|
||||
# Copyright (C) 2020 The Sipwise Team - http://sipwise.com
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License as published by the Free
|
||||
# Software Foundation, either version 3 of the License, or (at your option)
|
||||
# any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
# more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License along
|
||||
# with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
from rest_framework import serializers
|
||||
|
||||
from . import models
|
||||
|
||||
|
||||
class ReleaseChangedSerializer(serializers.HyperlinkedModelSerializer):
|
||||
class Meta:
|
||||
model = models.ReleaseChanged
|
||||
fields = "__all__"
|
||||
extra_kwargs = {"url": {"view_name": "release_changed:detail"}}
|
@ -0,0 +1,52 @@
|
||||
# Copyright (C) 2020 The Sipwise Team - http://sipwise.com
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License as published by the Free
|
||||
# Software Foundation, either version 3 of the License, or (at your option)
|
||||
# any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
# more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License along
|
||||
# with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
import json
|
||||
import logging
|
||||
|
||||
from celery import shared_task
|
||||
from django.apps import apps
|
||||
|
||||
from .models import ReleaseChanged
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@shared_task(ignore_result=True)
|
||||
def process_result(jbi_id, path_envVars):
|
||||
JenkinsBuildInfo = apps.get_model("repoapi", "JenkinsBuildInfo")
|
||||
jbi = JenkinsBuildInfo.objects.get(id=jbi_id)
|
||||
with open(path_envVars) as data_file:
|
||||
data = json.load(data_file)
|
||||
info = data["envMap"]
|
||||
if info["vmdone"] == "yes":
|
||||
ReleaseChanged.objects.filter(
|
||||
version=info["vmversion"], vmtype=info["vmtype"],
|
||||
).delete()
|
||||
logger.info("{}_{} deleted".format(info["vmtype"], info["vmversion"]))
|
||||
return
|
||||
r, created = ReleaseChanged.objects.get_or_create(
|
||||
version=info["vmversion"],
|
||||
vmtype=info["vmtype"],
|
||||
defaults={"result": jbi.result},
|
||||
)
|
||||
if not created:
|
||||
r.result = jbi.result
|
||||
r.save()
|
||||
if r.result == "SUCCESS":
|
||||
changed = "*NOT*"
|
||||
else:
|
||||
changed = ""
|
||||
msg = "setting {}_{} as {} changed, created:{}"
|
||||
logger.info(msg.format(r.vmtype, r.version, changed, created))
|
@ -0,0 +1,45 @@
|
||||
# Copyright (C) 2020 The Sipwise Team - http://sipwise.com
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License as published by the Free
|
||||
# Software Foundation, either version 3 of the License, or (at your option)
|
||||
# any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
# more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License along
|
||||
# with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
from django.urls import reverse
|
||||
from rest_framework import status
|
||||
from rest_framework.test import APITestCase
|
||||
|
||||
from repoapi.test.base import BaseTest
|
||||
|
||||
|
||||
class TestRest(BaseTest, APITestCase):
|
||||
fixtures = [
|
||||
"test_release_changed",
|
||||
]
|
||||
|
||||
url = "release_changed:check"
|
||||
|
||||
def setUp(self):
|
||||
super(TestRest, self).setUp()
|
||||
|
||||
def test_get_success(self):
|
||||
url = reverse(self.url, args=["PRO", "mr8.4"])
|
||||
response = self.client.get(url, format="json")
|
||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||
|
||||
def test_get_not_success(self):
|
||||
url = reverse(self.url, args=["CE", "mr8.4"])
|
||||
response = self.client.get(url, format="json")
|
||||
self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
|
||||
|
||||
def test_get_not_exist(self):
|
||||
url = reverse(self.url, args=["CE", "mr8.5"])
|
||||
response = self.client.get(url, format="json")
|
||||
self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
|
@ -0,0 +1,71 @@
|
||||
# Copyright (C) 2020 The Sipwise Team - http://sipwise.com
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License as published by the Free
|
||||
# Software Foundation, either version 3 of the License, or (at your option)
|
||||
# any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
# more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License along
|
||||
# with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
from os.path import join
|
||||
from unittest.mock import mock_open
|
||||
from unittest.mock import patch
|
||||
|
||||
from . import tasks
|
||||
from .conf import settings
|
||||
from .models import ReleaseChanged
|
||||
from repoapi.models import JenkinsBuildInfo
|
||||
from repoapi.test.base import BaseTest
|
||||
|
||||
FIXTURES_PATH = join(settings.BASE_DIR, "release_changed", "fixtures")
|
||||
FILE_PATH = join(FIXTURES_PATH, "test_envVars.json")
|
||||
FILE_PATH_DONE = join(FIXTURES_PATH, "test_envVars_done.json")
|
||||
with open(FILE_PATH) as file:
|
||||
DATA = file.read()
|
||||
with open(FILE_PATH_DONE) as file:
|
||||
DATA_DONE = file.read()
|
||||
|
||||
|
||||
class TasksTestCase(BaseTest):
|
||||
fixtures = ["test_release_changed_jbi"]
|
||||
|
||||
def test_process_create(self):
|
||||
jbi = JenkinsBuildInfo.objects.get(pk=1)
|
||||
with patch("builtins.open", mock_open(read_data=DATA)):
|
||||
tasks.process_result.delay(jbi.id, FILE_PATH)
|
||||
r = ReleaseChanged.objects.get(version="mr8.5.1", vmtype="CE")
|
||||
self.assertEqual("FAILED", r.result)
|
||||
|
||||
def test_process_modify(self):
|
||||
r = ReleaseChanged.objects.create(
|
||||
version="mr8.5.1", vmtype="CE", result="SUCCESS"
|
||||
)
|
||||
r_id = r.id
|
||||
jbi = JenkinsBuildInfo.objects.get(pk=1)
|
||||
with patch("builtins.open", mock_open(read_data=DATA)):
|
||||
tasks.process_result.delay(jbi.id, FILE_PATH)
|
||||
r = ReleaseChanged.objects.get(version="mr8.5.1", vmtype="CE")
|
||||
self.assertEqual(r_id, r.id)
|
||||
self.assertEqual("FAILED", r.result)
|
||||
|
||||
def test_process_done(self):
|
||||
ReleaseChanged.objects.create(
|
||||
version="mr8.5.1", vmtype="CE", result="FAILED"
|
||||
)
|
||||
jbi = JenkinsBuildInfo.objects.get(pk=1)
|
||||
with patch("builtins.open", mock_open(read_data=DATA_DONE)):
|
||||
tasks.process_result.delay(jbi.id, FILE_PATH)
|
||||
rs = ReleaseChanged.objects.filter(version="mr8.5.1", vmtype="CE")
|
||||
self.assertFalse(rs.exists())
|
||||
|
||||
def test_process_done_no_obj(self):
|
||||
jbi = JenkinsBuildInfo.objects.get(pk=1)
|
||||
with patch("builtins.open", mock_open(read_data=DATA_DONE)):
|
||||
tasks.process_result.delay(jbi.id, FILE_PATH)
|
||||
rs = ReleaseChanged.objects.filter(version="mr8.5.1", vmtype="CE")
|
||||
self.assertFalse(rs.exists())
|
@ -0,0 +1,32 @@
|
||||
# Copyright (C) 2020 The Sipwise Team - http://sipwise.com
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License as published by the Free
|
||||
# Software Foundation, either version 3 of the License, or (at your option)
|
||||
# any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
# more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License along
|
||||
# with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
from django.conf.urls import url
|
||||
|
||||
from . import views
|
||||
|
||||
app_name = "release_changed"
|
||||
urlpatterns = [
|
||||
url(r"^$", views.ReleaseChangedList.as_view(), name="list"),
|
||||
url(
|
||||
r"^(?P<pk>[0-9]+)/?$",
|
||||
views.ReleaseChangedDetail.as_view(),
|
||||
name="detail",
|
||||
),
|
||||
url(
|
||||
r"^(?P<vmtype>[^/]+)/(?P<release>[^/]+)/$",
|
||||
views.ReleaseChangedCheck.as_view(),
|
||||
name="check",
|
||||
),
|
||||
]
|
@ -0,0 +1,56 @@
|
||||
# Copyright (C) 2020 The Sipwise Team - http://sipwise.com
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License as published by the Free
|
||||
# Software Foundation, either version 3 of the License, or (at your option)
|
||||
# any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
# more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License along
|
||||
# with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
import django_filters
|
||||
from django.shortcuts import get_object_or_404
|
||||
from rest_framework import generics
|
||||
from rest_framework.exceptions import NotFound
|
||||
from rest_framework.response import Response
|
||||
from rest_framework.views import APIView
|
||||
|
||||
from . import models
|
||||
from .serializers import ReleaseChangedSerializer
|
||||
|
||||
|
||||
class ReleaseChangedFilter(django_filters.FilterSet):
|
||||
class Meta:
|
||||
model = models.ReleaseChanged
|
||||
fields = ["vmtype", "version", "result"]
|
||||
order_by = ["version", "vmtype"]
|
||||
|
||||
|
||||
class ReleaseChangedList(generics.ListCreateAPIView):
|
||||
queryset = models.ReleaseChanged.objects.all().order_by(
|
||||
"version", "vmtype"
|
||||
)
|
||||
serializer_class = ReleaseChangedSerializer
|
||||
filterset_class = ReleaseChangedFilter
|
||||
|
||||
|
||||
class ReleaseChangedDetail(generics.RetrieveAPIView):
|
||||
queryset = models.ReleaseChanged.objects.all().order_by(
|
||||
"version", "vmtype"
|
||||
)
|
||||
serializer_class = ReleaseChangedSerializer
|
||||
|
||||
|
||||
class ReleaseChangedCheck(APIView):
|
||||
def get(self, request, vmtype, release):
|
||||
r = get_object_or_404(
|
||||
models.ReleaseChanged, vmtype=vmtype, version=release
|
||||
)
|
||||
if r.result != "SUCCESS":
|
||||
raise NotFound("VM {}_{} has to be built".format(vmtype, release))
|
||||
serializer = ReleaseChangedSerializer(r, context={"request": request})
|
||||
return Response(serializer.data)
|
Loading…
Reference in new issue