From 0591647333cb0e63d3704c42d3353d3056e37bdc Mon Sep 17 00:00:00 2001 From: Matthew Jones Date: Thu, 2 Jun 2016 14:58:05 -0400 Subject: [PATCH] Implement a flag that allows simulteanous job launches on job templates --- awx/api/serializers.py | 2 +- .../0024_v300_jobtemplate_allow_simul.py | 19 +++++++++++++++++++ awx/main/models/jobs.py | 6 ++++++ awx/main/tests/functional/test_jobs.py | 13 +++++++++++++ 4 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 awx/main/migrations/0024_v300_jobtemplate_allow_simul.py diff --git a/awx/api/serializers.py b/awx/api/serializers.py index 5efaed8d56..2d0de18886 100644 --- a/awx/api/serializers.py +++ b/awx/api/serializers.py @@ -1755,7 +1755,7 @@ class JobTemplateSerializer(UnifiedJobTemplateSerializer, JobOptionsSerializer): model = JobTemplate fields = ('*', 'host_config_key', 'ask_variables_on_launch', 'ask_limit_on_launch', 'ask_tags_on_launch', 'ask_job_type_on_launch', 'ask_inventory_on_launch', - 'ask_credential_on_launch', 'survey_enabled', 'become_enabled') + 'ask_credential_on_launch', 'survey_enabled', 'become_enabled', 'allow_simultaneous') def get_related(self, obj): res = super(JobTemplateSerializer, self).get_related(obj) diff --git a/awx/main/migrations/0024_v300_jobtemplate_allow_simul.py b/awx/main/migrations/0024_v300_jobtemplate_allow_simul.py new file mode 100644 index 0000000000..ef67525e4b --- /dev/null +++ b/awx/main/migrations/0024_v300_jobtemplate_allow_simul.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('main', '0023_v300_activity_stream_ordering'), + ] + + operations = [ + migrations.AddField( + model_name='jobtemplate', + name='allow_simultaneous', + field=models.BooleanField(default=False), + ), + ] diff --git a/awx/main/models/jobs.py b/awx/main/models/jobs.py index 7e02c42b07..d94f09cafc 100644 --- a/awx/main/models/jobs.py +++ b/awx/main/models/jobs.py @@ -229,6 +229,10 @@ class JobTemplate(UnifiedJobTemplate, JobOptions, ResourceMixin): read_role = ImplicitRoleField( parent_role=['project.organization.auditor_role', 'inventory.organization.auditor_role', 'execute_role', 'admin_role'], ) + allow_simultaneous = models.BooleanField( + default=False, + ) + @classmethod def _get_unified_job_class(cls): @@ -580,6 +584,8 @@ class Job(UnifiedJob, JobOptions): if obj.job_template is not None and obj.inventory is not None: if obj.job_template == self.job_template and \ obj.inventory == self.inventory: + if self.job_template.allow_simultaneous: + return False if obj.launch_type == 'callback' and self.launch_type == 'callback' and \ obj.limit != self.limit: return False diff --git a/awx/main/tests/functional/test_jobs.py b/awx/main/tests/functional/test_jobs.py index aefb4e8bb7..e65ef9edb7 100644 --- a/awx/main/tests/functional/test_jobs.py +++ b/awx/main/tests/functional/test_jobs.py @@ -22,3 +22,16 @@ def test_job_blocking(get, post, job_template, inventory, inventory_factory): assert j_callback_1.is_blocked_by(j_callback_2) j_callback_2.limit = 'b' assert not j_callback_1.is_blocked_by(j_callback_2) + +@pytest.mark.django_db +def test_job_blocking_allow_simul(get, post, job_template, inventory): + job_template.allow_simultaneous = True + j1 = Job.objects.create(job_template=job_template, + inventory=inventory) + j2 = Job.objects.create(job_template=job_template, + inventory=inventory) + assert not j1.is_blocked_by(j2) + assert not j2.is_blocked_by(j1) + job_template.allow_simultaneous = False + assert j1.is_blocked_by(j2) + assert j2.is_blocked_by(j1)