Make sure project updates run in default EE (#9172)

* Make sure project updates run in default EE

* Remove project execution_environment field from collection
This commit is contained in:
Alan Rominger 2021-01-27 11:55:32 -05:00 committed by Shane McDonald
parent 8ab7745e3a
commit c7e0e30f93
4 changed files with 18 additions and 14 deletions

View File

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

View File

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

View File

@ -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('.'):

View File

@ -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 == '':