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
This commit is contained in:
David Moreau Simard 2018-10-09 14:04:23 -04:00
parent 9f29bd3bcf
commit 515519660c
No known key found for this signature in database
GPG Key ID: CBEB466764A9E621
4 changed files with 22 additions and 4 deletions

View File

@ -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={

View File

@ -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")

View File

@ -70,6 +70,7 @@ class PlayFactory(factory.DjangoModelFactory):
name = "test play"
completed = True
uuid = "5c5f67b9-e63c-6297-80da-000000000005"
playbook = factory.SubFactory(PlaybookFactory)

View File

@ -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())