Merge pull request #10436 from AlanCoding/installed_default

Prefer installer defaults over user-defined global EEs

The installer knows better than the user

Reviewed-by: Jeff Bradberry <None>
Reviewed-by: Bianca Henderson <beeankha@gmail.com>
Reviewed-by: Elijah DeLee <kdelee@redhat.com>
This commit is contained in:
softwarefactory-project-zuul[bot] 2021-06-15 00:59:06 +00:00 committed by GitHub
commit ef67f9c65d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 51 additions and 0 deletions

View File

@ -0,0 +1,46 @@
import pytest
from django.conf import settings
from django.test.utils import override_settings
from awx.main.models.execution_environments import ExecutionEnvironment
from awx.main.utils.execution_environments import get_default_execution_environment
from awx.main.management.commands.register_default_execution_environments import Command
@pytest.fixture
def set_up_defaults():
Command().handle()
@pytest.mark.django_db
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']
@pytest.mark.django_db
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
@pytest.mark.django_db
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

View File

@ -13,6 +13,11 @@ def get_control_plane_execution_environment():
def get_default_execution_environment():
if settings.DEFAULT_EXECUTION_ENVIRONMENT is not None:
return settings.DEFAULT_EXECUTION_ENVIRONMENT
installed_default = ExecutionEnvironment.objects.filter(
image__in=[ee['image'] for ee in settings.GLOBAL_JOB_EXECUTION_ENVIRONMENTS], organization=None, managed_by_tower=False
).first()
if installed_default:
return installed_default
return ExecutionEnvironment.objects.filter(organization=None, managed_by_tower=False).first()