From c7e0e30f932a4c3043f59e39b31db0f7cfa4c647 Mon Sep 17 00:00:00 2001 From: Alan Rominger Date: Wed, 27 Jan 2021 11:55:32 -0500 Subject: [PATCH] Make sure project updates run in default EE (#9172) * Make sure project updates run in default EE * Remove project execution_environment field from collection --- awx/api/serializers.py | 2 +- awx/main/models/mixins.py | 14 +++++++++----- awx/main/models/projects.py | 8 ++++++++ awx_collection/plugins/modules/tower_project.py | 8 -------- 4 files changed, 18 insertions(+), 14 deletions(-) diff --git a/awx/api/serializers.py b/awx/api/serializers.py index 3a28239b0d..eb13f150d3 100644 --- a/awx/api/serializers.py +++ b/awx/api/serializers.py @@ -1394,7 +1394,7 @@ class ProjectSerializer(UnifiedJobTemplateSerializer, ProjectOptionsSerializer): class Meta: model = Project - fields = ('*', 'organization', 'scm_update_on_launch', + fields = ('*', '-execution_environment', 'organization', 'scm_update_on_launch', 'scm_update_cache_timeout', 'allow_override', 'custom_virtualenv', 'default_environment') + \ ('last_update_failed', 'last_updated') # Backwards compatibility diff --git a/awx/main/models/mixins.py b/awx/main/models/mixins.py index 459eadabcf..549c93607d 100644 --- a/awx/main/models/mixins.py +++ b/awx/main/models/mixins.py @@ -455,12 +455,17 @@ class ExecutionEnvironmentMixin(models.Model): help_text=_('The container image to be used for execution.'), ) + def get_execution_environment_default(self): + from awx.main.models.execution_environments import ExecutionEnvironment + + if settings.DEFAULT_EXECUTION_ENVIRONMENT is not None: + return settings.DEFAULT_EXECUTION_ENVIRONMENT + return ExecutionEnvironment.objects.filter(organization=None, managed_by_tower=True).first() + def resolve_execution_environment(self): """ Return the execution environment that should be used when creating a new job. """ - from awx.main.models.execution_environments import ExecutionEnvironment - 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: @@ -470,9 +475,8 @@ class ExecutionEnvironmentMixin(models.Model): if getattr(self, 'inventory', None) and self.inventory.organization is not None: if self.inventory.organization.default_environment is not None: return self.inventory.organization.default_environment - if settings.DEFAULT_EXECUTION_ENVIRONMENT is not None: - return settings.DEFAULT_EXECUTION_ENVIRONMENT - return ExecutionEnvironment.objects.filter(organization=None, managed_by_tower=True).first() + + return self.get_execution_environment_default() class CustomVirtualEnvMixin(models.Model): diff --git a/awx/main/models/projects.py b/awx/main/models/projects.py index fb948916d0..c9bf87f408 100644 --- a/awx/main/models/projects.py +++ b/awx/main/models/projects.py @@ -187,6 +187,14 @@ class ProjectOptions(models.Model): pass return cred + def resolve_execution_environment(self): + """ + Project updates, themselves, will use the default execution environment. + Jobs using the project can use the default_environment, but the project updates + are not flexible enough to allow customizing the image they use. + """ + return self.get_execution_environment_default() + def get_project_path(self, check_if_exists=True): local_path = os.path.basename(self.local_path) if local_path and not local_path.startswith('.'): diff --git a/awx_collection/plugins/modules/tower_project.py b/awx_collection/plugins/modules/tower_project.py index 1a8248c1fa..acbf3833b5 100644 --- a/awx_collection/plugins/modules/tower_project.py +++ b/awx_collection/plugins/modules/tower_project.py @@ -106,10 +106,6 @@ options: description: - Default Execution Environment to use for jobs relating to the project. type: str - execution_environment: - description: - - Execution Environment to use for project updates. - type: str organization: description: - Name of organization for project. @@ -248,7 +244,6 @@ def main(): timeout=dict(type='int', default=0, aliases=['job_timeout']), custom_virtualenv=dict(), default_environment=dict(), - execution_environment=dict(), organization=dict(), notification_templates_started=dict(type="list", elements='str'), notification_templates_success=dict(type="list", elements='str'), @@ -281,7 +276,6 @@ def main(): timeout = module.params.get('timeout') custom_virtualenv = module.params.get('custom_virtualenv') default_ee = module.params.get('default_environment') - ee = module.params.get('execution_environment') organization = module.params.get('organization') state = module.params.get('state') wait = module.params.get('wait') @@ -347,8 +341,6 @@ def main(): project_fields['credential'] = credential if default_ee is not None: project_fields['default_environment'] = module.resolve_name_to_id('execution_environments', default_ee) - if ee is not None: - project_fields['execution_environment'] = module.resolve_name_to_id('execution_environments', ee) if allow_override is not None: project_fields['allow_override'] = allow_override if scm_type == '':