Skip to content
Snippets Groups Projects
Commit 26b3a289 authored by Bastien Abadie's avatar Bastien Abadie
Browse files

Merge branch 'add-docker-image-workerversion' into 'master'

Add docker_image field on WorkerVersion model

See merge request !795
parents 8f1d7fea a4520e40
No related branches found
No related tags found
1 merge request!795Add docker_image field on WorkerVersion model
......@@ -6,6 +6,7 @@ from django.conf import settings
from rest_framework.generics import (
GenericAPIView, ListAPIView, CreateAPIView, RetrieveAPIView,
ListCreateAPIView, RetrieveUpdateDestroyAPIView, RetrieveDestroyAPIView,
RetrieveUpdateAPIView
)
from rest_framework.views import APIView
from rest_framework.parsers import MultiPartParser, FileUploadParser
......@@ -654,7 +655,7 @@ class WorkerVersionList(ListCreateAPIView):
return Response(WorkerVersionSerializer(version).data, status=reponse_status)
class WorkerVersionRetrieve(CorpusACLMixin, RetrieveAPIView):
class WorkerVersionRetrieve(CorpusACLMixin, RetrieveUpdateAPIView):
"""
Retrieve a specific worker version
"""
......
# Generated by Django 2.2.13 on 2020-06-18 12:52
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('ponos', '0015_task_has_docker_socket'),
('dataimport', '0009_remove_datafile_hash'),
]
operations = [
migrations.AddField(
model_name='workerversion',
name='docker_image',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='ponos.Artifact'),
),
]
......@@ -4,6 +4,7 @@ from django.conf import settings
from django.utils.functional import cached_property
from rest_framework.exceptions import ValidationError
from enumfields import EnumField, Enum
from ponos.models import Artifact
from arkindex_common.enums import DataImportMode
from arkindex_common.ml_tool import MLToolType
from arkindex.project.aws import S3FileMixin, S3FileStatus
......@@ -341,6 +342,7 @@ class WorkerVersion(models.Model):
worker = models.ForeignKey('dataimport.Worker', on_delete=models.CASCADE)
revision = models.ForeignKey('dataimport.Revision', on_delete=models.CASCADE)
configuration = JSONField()
docker_image = models.ForeignKey(Artifact, on_delete=models.CASCADE, null=True)
class Meta:
unique_together = (('worker', 'revision'),)
......
......@@ -31,6 +31,7 @@ class WorkerVersionSerializer(serializers.ModelSerializer):
'id',
'configuration',
'revision',
'docker_image',
)
def to_representation(self, instance):
......
......@@ -3,6 +3,17 @@ from rest_framework import status
from arkindex_common.ml_tool import MLToolType
from arkindex.dataimport.models import Repository, Revision, Worker, WorkerVersion
from arkindex.project.tests import FixtureAPITestCase
from ponos.models import Workflow
RECIPE = '''
tasks:
first:
image: alpine
second:
parents:
- first
image: hello-world
'''
class TestWorkersWorkerVersions(FixtureAPITestCase):
......@@ -240,3 +251,49 @@ class TestWorkersWorkerVersions(FixtureAPITestCase):
self.assertEqual(data['id'], str(self.version_1.id))
self.assertEqual(data['configuration'], {"test": "test1"})
self.assertEqual(data['revision']['id'], str(self.rev.id))
def test_update_version_requires_login(self):
response = self.client.patch(
reverse('api:version-retrieve', kwargs={'pk': str(self.version_1.id)}),
data={
'configuration': {"test": "test2"},
'docker_image': '12341234-1234-1234-1234-123412341234'
}, format='json'
)
self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
def test_update_version_invalid_id(self):
self.client.force_login(self.user)
response = self.client.patch(
reverse('api:version-retrieve', kwargs={'pk': '12341234-1234-1234-1234-123412341234'}),
data={
'configuration': {"test": "test2"},
'docker_image': '12341234-1234-1234-1234-123412341234'
}, format='json'
)
self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
def test_update_version(self):
self.assertEqual(self.version_1.docker_image, None)
workflow = Workflow.objects.create(recipe=RECIPE)
task = workflow.tasks.get(slug='first')
artifact = task.artifacts.create(
path='path/to/file.json',
size=100,
content_type='application/json',
)
self.client.force_login(self.user)
response = self.client.patch(
reverse('api:version-retrieve', kwargs={'pk': str(self.version_1.id)}),
data={
'configuration': {"test": "test2"},
'docker_image': str(artifact.id)
}, format='json'
)
self.assertEqual(response.status_code, status.HTTP_200_OK)
data = response.json()
self.assertEqual(data['id'], str(self.version_1.id))
self.assertEqual(data['configuration'], {"test": "test2"})
self.assertEqual(data['docker_image'], str(artifact.id))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment