From d3cc439fa8ce42c96cb3eac7c101d4585437ca91 Mon Sep 17 00:00:00 2001 From: Jeff Bradberry Date: Thu, 27 May 2021 15:22:44 -0400 Subject: [PATCH] Include the EE set on a workflow template in the resolver hierarchy This step comes immediately after checking the actual job/template for an explicitly set EE. Note that now, because of how jobs are spawned off of workflow nodes, the call to .resolve_execution_environment() no longer happens in .create_unified_job(). The job instance within .create_unified_job() doesn't yet have access to the node that it will be attached to, making it impossible to use this information in the resolver if called there. --- awx/main/models/ad_hoc_commands.py | 3 --- awx/main/models/mixins.py | 13 +++++++++++-- awx/main/models/unified_jobs.py | 2 -- awx/main/tasks.py | 4 ++-- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/awx/main/models/ad_hoc_commands.py b/awx/main/models/ad_hoc_commands.py index 5ee08857f6..94318a17da 100644 --- a/awx/main/models/ad_hoc_commands.py +++ b/awx/main/models/ad_hoc_commands.py @@ -215,9 +215,6 @@ class AdHocCommand(UnifiedJob, JobNotificationMixin): self.name = Truncator(u': '.join(filter(None, (self.module_name, self.module_args)))).chars(512) if 'name' not in update_fields: update_fields.append('name') - if not self.execution_environment_id: - self.execution_environment = self.resolve_execution_environment() - update_fields.append('execution_environment') super(AdHocCommand, self).save(*args, **kwargs) @property diff --git a/awx/main/models/mixins.py b/awx/main/models/mixins.py index 6c67f4bfe3..760cce4e47 100644 --- a/awx/main/models/mixins.py +++ b/awx/main/models/mixins.py @@ -464,11 +464,20 @@ class ExecutionEnvironmentMixin(models.Model): def resolve_execution_environment(self): """ - Return the execution environment that should be used when creating a new job. + Return the execution environment that should be used when executing a job. """ if self.execution_environment is not None: return self.execution_environment - if getattr(self, 'project_id', None) and self.project.default_environment is not None: + template = getattr(self, 'unified_job_template', None) + if template is not None and template.execution_environment is not None: + return template.execution_environment + wf_node = getattr(self, 'unified_job_node', None) + while wf_node is not None: + wf_template = wf_node.workflow_job.workflow_job_template + if wf_template.execution_environment is not None: + return wf_template.execution_environment + wf_node = getattr(wf_node.workflow_job, 'unified_job_node', None) + if getattr(self, 'project', None) and self.project.default_environment is not None: return self.project.default_environment if getattr(self, 'organization', None) and self.organization.default_environment is not None: return self.organization.default_environment diff --git a/awx/main/models/unified_jobs.py b/awx/main/models/unified_jobs.py index ddb368b57a..6627826923 100644 --- a/awx/main/models/unified_jobs.py +++ b/awx/main/models/unified_jobs.py @@ -366,8 +366,6 @@ class UnifiedJobTemplate(PolymorphicModel, CommonModelNameNotUnique, ExecutionEn for fd, val in eager_fields.items(): setattr(unified_job, fd, val) - unified_job.execution_environment = self.resolve_execution_environment() - # NOTE: slice workflow jobs _get_parent_field_name method # is not correct until this is set if not parent_field_name: diff --git a/awx/main/tasks.py b/awx/main/tasks.py index fe234d7391..e05c59eabe 100644 --- a/awx/main/tasks.py +++ b/awx/main/tasks.py @@ -3059,8 +3059,8 @@ class AWXReceptorJob: @property def pod_definition(self): - if self.task: - ee = self.task.instance.resolve_execution_environment() + if self.task and self.task.instance.execution_environment: + ee = self.task.instance.execution_environment else: ee = get_default_execution_environment()