From 515519660c6198ddce385d22fb047424999b1031 Mon Sep 17 00:00:00 2001 From: David Moreau Simard Date: Tue, 9 Oct 2018 14:04:23 -0400 Subject: [PATCH] Add an uuid field for the play model and API Ansible generates a unique uuid for every play and this uuid is supplied to the callbacks as well as the action plugins. This will allow action plugins to find the play they are running in. Since the play references the playbook that is running, it will allow action plugins to positively identify the playbook by querying the API for the play by searching for the uuid. Change-Id: I599ea9150649db5eb5d2eaab503b47a58ea27c4f --- ara/api/migrations/0001_initial.py | 5 +++-- ara/api/models.py | 1 + ara/api/tests/factories.py | 1 + ara/api/tests/tests_play.py | 19 +++++++++++++++++-- 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/ara/api/migrations/0001_initial.py b/ara/api/migrations/0001_initial.py index 81088a7..5e778d8 100644 --- a/ara/api/migrations/0001_initial.py +++ b/ara/api/migrations/0001_initial.py @@ -1,8 +1,8 @@ -# Generated by Django 2.1.1 on 2018-09-07 17:53 +# Generated by Django 2.1.1 on 2018-10-09 15:35 +from django.db import migrations, models import django.db.models.deletion import django.utils.timezone -from django.db import migrations, models class Migration(migrations.Migration): @@ -74,6 +74,7 @@ class Migration(migrations.Migration): ('started', models.DateTimeField(default=django.utils.timezone.now)), ('ended', models.DateTimeField(blank=True, null=True)), ('name', models.CharField(blank=True, max_length=255, null=True)), + ('uuid', models.UUIDField()), ('completed', models.BooleanField(default=False)), ], options={ diff --git a/ara/api/models.py b/ara/api/models.py index 628beba..f6494a3 100644 --- a/ara/api/models.py +++ b/ara/api/models.py @@ -150,6 +150,7 @@ class Play(Duration): db_table = "plays" name = models.CharField(max_length=255, blank=True, null=True) + uuid = models.UUIDField() completed = models.BooleanField(default=False) playbook = models.ForeignKey(Playbook, on_delete=models.CASCADE, related_name="plays") diff --git a/ara/api/tests/factories.py b/ara/api/tests/factories.py index ff92627..680a59c 100644 --- a/ara/api/tests/factories.py +++ b/ara/api/tests/factories.py @@ -70,6 +70,7 @@ class PlayFactory(factory.DjangoModelFactory): name = "test play" completed = True + uuid = "5c5f67b9-e63c-6297-80da-000000000005" playbook = factory.SubFactory(PlaybookFactory) diff --git a/ara/api/tests/tests_play.py b/ara/api/tests/tests_play.py index a7bec6f..d9eb28e 100644 --- a/ara/api/tests/tests_play.py +++ b/ara/api/tests/tests_play.py @@ -31,7 +31,14 @@ class PlayTestCase(APITestCase): def test_play_serializer(self): playbook = factories.PlaybookFactory() - serializer = serializers.PlaySerializer(data={"name": "serializer", "completed": True, "playbook": playbook.id}) + serializer = serializers.PlaySerializer( + data={ + "name": "serializer", + "completed": True, + "uuid": "5c5f67b9-e63c-6297-80da-000000000005", + "playbook": playbook.id, + } + ) serializer.is_valid() play = serializer.save() play.refresh_from_db() @@ -57,7 +64,15 @@ class PlayTestCase(APITestCase): def test_create_play(self): playbook = factories.PlaybookFactory() self.assertEqual(0, models.Play.objects.count()) - request = self.client.post("/api/v1/plays", {"name": "create", "completed": False, "playbook": playbook.id}) + request = self.client.post( + "/api/v1/plays", + { + "name": "create", + "completed": False, + "uuid": "5c5f67b9-e63c-6297-80da-000000000005", + "playbook": playbook.id, + }, + ) self.assertEqual(201, request.status_code) self.assertEqual(1, models.Play.objects.count())