From 1d417fe573900c622c2ac9867b88a4a52eb6ff08 Mon Sep 17 00:00:00 2001 From: Chris Church Date: Mon, 14 Apr 2014 23:40:06 -0400 Subject: [PATCH] AC-1191 Fix limit parameter on callback jobs to intersect with any limit specified on the job template. --- awx/api/views.py | 2 +- awx/main/tests/jobs.py | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/awx/api/views.py b/awx/api/views.py index 346c2c7d50..e0fb47a57b 100644 --- a/awx/api/views.py +++ b/awx/api/views.py @@ -1224,7 +1224,7 @@ class JobTemplateCallback(GenericAPIView): data = dict(msg='Cannot start automatically, user input required!') # FIXME: Log! return Response(data, status=status.HTTP_400_BAD_REQUEST) - limit = ':'.join(filter(None, [job_template.limit, host.name])) + limit = ':&'.join(filter(None, [job_template.limit, host.name])) job = job_template.create_job(limit=limit, launch_type='callback') result = job.signal_start() if not result: diff --git a/awx/main/tests/jobs.py b/awx/main/tests/jobs.py index 5aa0455bdb..1845b66154 100644 --- a/awx/main/tests/jobs.py +++ b/awx/main/tests/jobs.py @@ -1272,6 +1272,11 @@ class JobTemplateCallbackTest(BaseJobTestMixin, django.test.LiveServerTestCase): self.assertEqual(job.hosts.count(), 1) self.assertEqual(job.hosts.all()[0], host) + # Set a limit on the job template to verify the callback job limit is + # set to the intersection of this limit and the host name. + job_template.limit = 'bakers:slicers:packagers' + job_template.save(update_fields=['limit']) + # Try when hostname is also an IP address, even if a different one is # specified via ansible_ssh_host. host_qs = job_template.inventory.hosts.order_by('pk') @@ -1295,7 +1300,7 @@ class JobTemplateCallbackTest(BaseJobTestMixin, django.test.LiveServerTestCase): self.assertEqual(jobs_qs.count(), 5) job = jobs_qs[0] self.assertEqual(job.launch_type, 'callback') - self.assertEqual(job.limit, host.name) + self.assertEqual(job.limit, ':&'.join([job_template.limit, host.name])) self.assertEqual(job.hosts.count(), 1) self.assertEqual(job.hosts.all()[0], host)