mirror of
https://github.com/ansible/awx.git
synced 2026-03-26 21:35:01 -02:30
don't run ansible-galaxy installs if there are no Galaxy credentials
This commit is contained in:
@@ -2117,6 +2117,16 @@ class RunProjectUpdate(BaseTask):
|
|||||||
raise RuntimeError('Could not determine a revision to run from project.')
|
raise RuntimeError('Could not determine a revision to run from project.')
|
||||||
elif not scm_branch:
|
elif not scm_branch:
|
||||||
scm_branch = {'hg': 'tip'}.get(project_update.scm_type, 'HEAD')
|
scm_branch = {'hg': 'tip'}.get(project_update.scm_type, 'HEAD')
|
||||||
|
|
||||||
|
galaxy_creds_are_defined = project_update.project.organization.galaxy_credentials.exists()
|
||||||
|
if not galaxy_creds_are_defined and (
|
||||||
|
settings.AWX_ROLES_ENABLED or settings.AWX_COLLECTIONS_ENABLED
|
||||||
|
):
|
||||||
|
logger.debug(
|
||||||
|
'Galaxy role/collection syncing is enabled, but no '
|
||||||
|
f'credentials are configured for {project_update.project.organization}.'
|
||||||
|
)
|
||||||
|
|
||||||
extra_vars.update({
|
extra_vars.update({
|
||||||
'projects_root': settings.PROJECTS_ROOT.rstrip('/'),
|
'projects_root': settings.PROJECTS_ROOT.rstrip('/'),
|
||||||
'local_path': os.path.basename(project_update.project.local_path),
|
'local_path': os.path.basename(project_update.project.local_path),
|
||||||
@@ -2127,8 +2137,8 @@ class RunProjectUpdate(BaseTask):
|
|||||||
'scm_url': scm_url,
|
'scm_url': scm_url,
|
||||||
'scm_branch': scm_branch,
|
'scm_branch': scm_branch,
|
||||||
'scm_clean': project_update.scm_clean,
|
'scm_clean': project_update.scm_clean,
|
||||||
'roles_enabled': settings.AWX_ROLES_ENABLED,
|
'roles_enabled': galaxy_creds_are_defined and settings.AWX_ROLES_ENABLED,
|
||||||
'collections_enabled': settings.AWX_COLLECTIONS_ENABLED,
|
'collections_enabled': galaxy_creds_are_defined and settings.AWX_COLLECTIONS_ENABLED,
|
||||||
})
|
})
|
||||||
# apply custom refspec from user for PR refs and the like
|
# apply custom refspec from user for PR refs and the like
|
||||||
if project_update.scm_refspec:
|
if project_update.scm_refspec:
|
||||||
|
|||||||
@@ -66,7 +66,8 @@ def patch_Organization():
|
|||||||
credentials_mock = mock.Mock(**{
|
credentials_mock = mock.Mock(**{
|
||||||
'all': lambda: _credentials,
|
'all': lambda: _credentials,
|
||||||
'add': _credentials.append,
|
'add': _credentials.append,
|
||||||
'spec_set': ['all', 'add'],
|
'exists': lambda: len(_credentials) > 0,
|
||||||
|
'spec_set': ['all', 'add', 'exists'],
|
||||||
})
|
})
|
||||||
with mock.patch.object(Organization, 'galaxy_credentials', credentials_mock):
|
with mock.patch.object(Organization, 'galaxy_credentials', credentials_mock):
|
||||||
yield
|
yield
|
||||||
@@ -1799,7 +1800,7 @@ class TestProjectUpdateGalaxyCredentials(TestJobExecution):
|
|||||||
def project_update(self):
|
def project_update(self):
|
||||||
org = Organization(pk=1)
|
org = Organization(pk=1)
|
||||||
proj = Project(pk=1, organization=org)
|
proj = Project(pk=1, organization=org)
|
||||||
project_update = ProjectUpdate(pk=1, project=proj)
|
project_update = ProjectUpdate(pk=1, project=proj, scm_type='git')
|
||||||
project_update.websocket_emit_status = mock.Mock()
|
project_update.websocket_emit_status = mock.Mock()
|
||||||
return project_update
|
return project_update
|
||||||
|
|
||||||
@@ -1820,19 +1821,38 @@ class TestProjectUpdateGalaxyCredentials(TestJobExecution):
|
|||||||
assert 'ANSIBLE_GALAXY_IGNORE' not in env
|
assert 'ANSIBLE_GALAXY_IGNORE' not in env
|
||||||
|
|
||||||
def test_galaxy_credentials_empty(self, private_data_dir, project_update):
|
def test_galaxy_credentials_empty(self, private_data_dir, project_update):
|
||||||
task = tasks.RunProjectUpdate()
|
|
||||||
|
class RunProjectUpdate(tasks.RunProjectUpdate):
|
||||||
|
__vars__ = {}
|
||||||
|
|
||||||
|
def _write_extra_vars_file(self, private_data_dir, extra_vars, *kw):
|
||||||
|
self.__vars__ = extra_vars
|
||||||
|
|
||||||
|
task = RunProjectUpdate()
|
||||||
env = task.build_env(project_update, private_data_dir)
|
env = task.build_env(project_update, private_data_dir)
|
||||||
|
task.build_extra_vars_file(project_update, private_data_dir)
|
||||||
|
assert task.__vars__['roles_enabled'] is False
|
||||||
|
assert task.__vars__['collections_enabled'] is False
|
||||||
for k in env:
|
for k in env:
|
||||||
assert not k.startswith('ANSIBLE_GALAXY_SERVER')
|
assert not k.startswith('ANSIBLE_GALAXY_SERVER')
|
||||||
|
|
||||||
def test_single_public_galaxy(self, private_data_dir, project_update):
|
def test_single_public_galaxy(self, private_data_dir, project_update):
|
||||||
|
class RunProjectUpdate(tasks.RunProjectUpdate):
|
||||||
|
__vars__ = {}
|
||||||
|
|
||||||
|
def _write_extra_vars_file(self, private_data_dir, extra_vars, *kw):
|
||||||
|
self.__vars__ = extra_vars
|
||||||
|
|
||||||
credential_type = CredentialType.defaults['galaxy_api_token']()
|
credential_type = CredentialType.defaults['galaxy_api_token']()
|
||||||
public_galaxy = Credential(pk=1, credential_type=credential_type, inputs={
|
public_galaxy = Credential(pk=1, credential_type=credential_type, inputs={
|
||||||
'url': 'https://galaxy.ansible.com/',
|
'url': 'https://galaxy.ansible.com/',
|
||||||
})
|
})
|
||||||
project_update.project.organization.galaxy_credentials.add(public_galaxy)
|
project_update.project.organization.galaxy_credentials.add(public_galaxy)
|
||||||
task = tasks.RunProjectUpdate()
|
task = RunProjectUpdate()
|
||||||
env = task.build_env(project_update, private_data_dir)
|
env = task.build_env(project_update, private_data_dir)
|
||||||
|
task.build_extra_vars_file(project_update, private_data_dir)
|
||||||
|
assert task.__vars__['roles_enabled'] is True
|
||||||
|
assert task.__vars__['collections_enabled'] is True
|
||||||
assert sorted([
|
assert sorted([
|
||||||
(k, v) for k, v in env.items()
|
(k, v) for k, v in env.items()
|
||||||
if k.startswith('ANSIBLE_GALAXY')
|
if k.startswith('ANSIBLE_GALAXY')
|
||||||
|
|||||||
Reference in New Issue
Block a user