def resolve_execution_environment(self): """ Return the execution environment that should be used when executing a job. """ if self.execution_environment is not None: return self.execution_environment 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 # NOTE: sliced workflow_jobs have a null workflow_job_template if wf_template and 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_id', None) and self.project.default_environment is not None: return self.project.default_environment if getattr(self, 'organization_id', None) and self.organization.default_environment is not None: return self.organization.default_environment if getattr(self, 'inventory_id', None) and self.inventory.organization is not None: if self.inventory.organization.default_environment is not None: return self.inventory.organization.default_environment return get_default_execution_environment()
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 get_default_execution_environment()
def test_default_to_control_plane(set_up_defaults): """If all of the job execution environments are job execution environments have gone missing then it will refuse to use the control plane execution environment as the default """ for ee in ExecutionEnvironment.objects.all(): if ee.name == 'Control Plane Execution Environment': continue ee.delete() assert get_default_execution_environment() is None
def get_base_args(self): bargs = ['podman', 'run', '--user=root', '--quiet'] bargs.extend(['-v', '{0}:{0}:Z'.format(self.source)]) for key, value in STANDARD_INVENTORY_UPDATE_ENV.items(): bargs.extend(['-e', '{0}={1}'.format(key, value)]) bargs.extend([get_default_execution_environment().image]) bargs.extend(['ansible-inventory', '-i', self.source]) bargs.extend(['--playbook-dir', functioning_dir(self.source)]) if self.verbosity: # INFO: -vvv, DEBUG: -vvvvv, for inventory, any more than 3 makes little difference bargs.append('-{}'.format('v' * min(5, self.verbosity * 2 + 1))) bargs.append('--list') logger.debug('Using base command: {}'.format(' '.join(bargs))) return bargs
def test_default_to_jobs_default(set_up_defaults, organization): """Under normal operation, the default EE should be from the list of global job EEs which are populated by the installer """ # Fill in some other unrelated EEs ExecutionEnvironment.objects.create(name='Steves environment', image='quay.io/ansible/awx-ee') ExecutionEnvironment( name=settings.GLOBAL_JOB_EXECUTION_ENVIRONMENTS[0]['name'], image='quay.io/ansible/awx-ee', organization=organization) default_ee = get_default_execution_environment() assert default_ee.image == settings.GLOBAL_JOB_EXECUTION_ENVIRONMENTS[0][ 'image'] assert default_ee.name == settings.GLOBAL_JOB_EXECUTION_ENVIRONMENTS[0][ 'name']
def resolve_execution_environment(self): """ Return the execution environment that should be used when executing a job. """ if self.execution_environment is not None: return self.execution_environment template = getattr(self, 'unified_job_template', None) if template is not None and template.execution_environment is not None: return template.execution_environment if getattr(self, 'project_id', None) and self.project.default_environment is not None: return self.project.default_environment if getattr(self, 'organization_id', None) and self.organization.default_environment is not None: return self.organization.default_environment if getattr(self, 'inventory_id', None) and self.inventory.organization is not None: if self.inventory.organization.default_environment is not None: return self.inventory.organization.default_environment return get_default_execution_environment()
def resolve_execution_environment(self): """ Return the execution environment that should be used when creating a new 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: return self.project.default_environment if getattr(self, 'organization', None) and self.organization.default_environment is not None: return self.organization.default_environment 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 return get_default_execution_environment()
def test_user_default(set_up_defaults): """If superuser has configured a default, then their preference should come first, of course""" ee = ExecutionEnvironment.objects.create(name='Steves environment', image='quay.io/ansible/awx-ee') with override_settings(DEFAULT_EXECUTION_ENVIRONMENT=ee): assert get_default_execution_environment() == ee