mirror of
https://github.com/ansible/awx.git
synced 2026-01-09 23:12:08 -03:30
AAP-29938 add force flag to refspec (#16173)
* add force flag to refspec * Development of git --amend test * Update awx/main/tests/live/tests/conftest.py Co-authored-by: Alan Rominger <arominge@redhat.com> --------- Co-authored-by: AlanCoding <arominge@redhat.com>
This commit is contained in:
parent
2fa2cd8beb
commit
b02117979d
@ -1346,7 +1346,7 @@ class RunProjectUpdate(BaseTask):
|
|||||||
extra_vars['scm_refspec'] = project_update.scm_refspec
|
extra_vars['scm_refspec'] = project_update.scm_refspec
|
||||||
elif project_update.project.allow_override:
|
elif project_update.project.allow_override:
|
||||||
# If branch is override-able, do extra fetch for all branches
|
# If branch is override-able, do extra fetch for all branches
|
||||||
extra_vars['scm_refspec'] = 'refs/heads/*:refs/remotes/origin/*'
|
extra_vars['scm_refspec'] = '+refs/heads/*:refs/remotes/origin/*'
|
||||||
|
|
||||||
if project_update.scm_type == 'archive':
|
if project_update.scm_type == 'archive':
|
||||||
# for raw archive, prevent error moving files between volumes
|
# for raw archive, prevent error moving files between volumes
|
||||||
|
|||||||
@ -139,7 +139,7 @@ def podman_image_generator():
|
|||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def project_factory(post, default_org, admin):
|
def project_factory(post, default_org, admin):
|
||||||
def _rf(scm_url=None, local_path=None):
|
def _rf(scm_url=None, local_path=None, **extra_kwargs):
|
||||||
proj_kwargs = {}
|
proj_kwargs = {}
|
||||||
if local_path:
|
if local_path:
|
||||||
# manual path
|
# manual path
|
||||||
@ -153,6 +153,9 @@ def project_factory(post, default_org, admin):
|
|||||||
else:
|
else:
|
||||||
raise RuntimeError('Need to provide scm_url or local_path')
|
raise RuntimeError('Need to provide scm_url or local_path')
|
||||||
|
|
||||||
|
if extra_kwargs:
|
||||||
|
proj_kwargs.update(extra_kwargs)
|
||||||
|
|
||||||
proj_kwargs['name'] = project_name
|
proj_kwargs['name'] = project_name
|
||||||
proj_kwargs['organization'] = default_org.id
|
proj_kwargs['organization'] = default_org.id
|
||||||
|
|
||||||
|
|||||||
@ -1,2 +1,25 @@
|
|||||||
|
import os
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from awx.main.tests.live.tests.conftest import wait_for_job
|
||||||
|
|
||||||
|
|
||||||
def test_git_file_project(live_tmp_folder, run_job_from_playbook):
|
def test_git_file_project(live_tmp_folder, run_job_from_playbook):
|
||||||
run_job_from_playbook('test_git_file_project', 'debug.yml', scm_url=f'file://{live_tmp_folder}/debug')
|
run_job_from_playbook('test_git_file_project', 'debug.yml', scm_url=f'file://{live_tmp_folder}/debug')
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('allow_override', [True, False])
|
||||||
|
def test_amend_commit(live_tmp_folder, project_factory, allow_override):
|
||||||
|
proj = project_factory(scm_url=f'file://{live_tmp_folder}/debug', allow_override=allow_override)
|
||||||
|
assert proj.current_job
|
||||||
|
wait_for_job(proj.current_job)
|
||||||
|
assert proj.allow_override is allow_override
|
||||||
|
|
||||||
|
source_dir = os.path.join(live_tmp_folder, 'debug')
|
||||||
|
subprocess.run('git commit --amend --no-edit', cwd=source_dir, shell=True)
|
||||||
|
|
||||||
|
update = proj.update()
|
||||||
|
update.signal_start()
|
||||||
|
wait_for_job(update)
|
||||||
|
|||||||
@ -1086,6 +1086,70 @@ class TestProjectUpdateCredentials(TestJobExecution):
|
|||||||
assert env['FOO'] == 'BAR'
|
assert env['FOO'] == 'BAR'
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.django_db
|
||||||
|
class TestProjectUpdateRefspec(TestJobExecution):
|
||||||
|
@pytest.fixture
|
||||||
|
def project_update(self, execution_environment):
|
||||||
|
org = Organization(pk=1)
|
||||||
|
proj = Project(pk=1, organization=org, allow_override=True)
|
||||||
|
project_update = ProjectUpdate(pk=1, project=proj, scm_type='git')
|
||||||
|
project_update.websocket_emit_status = mock.Mock()
|
||||||
|
project_update.execution_environment = execution_environment
|
||||||
|
return project_update
|
||||||
|
|
||||||
|
def test_refspec_with_allow_override_includes_plus_prefix(self, project_update, private_data_dir, mock_me):
|
||||||
|
"""Test that refspec includes + prefix to allow non-fast-forward updates when allow_override is True"""
|
||||||
|
task = jobs.RunProjectUpdate()
|
||||||
|
task.instance = project_update
|
||||||
|
|
||||||
|
# Call build_extra_vars_file which sets the refspec
|
||||||
|
with mock.patch.object(Licenser, 'validate', lambda *args, **kw: {}):
|
||||||
|
task.build_extra_vars_file(project_update, private_data_dir)
|
||||||
|
|
||||||
|
# Read the extra vars file to check the refspec
|
||||||
|
with open(os.path.join(private_data_dir, 'env', 'extravars')) as fd:
|
||||||
|
extra_vars = yaml.load(fd, Loader=SafeLoader)
|
||||||
|
|
||||||
|
# Verify the refspec includes the + prefix for force updates
|
||||||
|
assert 'scm_refspec' in extra_vars
|
||||||
|
assert extra_vars['scm_refspec'] == '+refs/heads/*:refs/remotes/origin/*'
|
||||||
|
|
||||||
|
def test_custom_refspec_not_overridden(self, project_update, private_data_dir, mock_me):
|
||||||
|
"""Test that custom user-provided refspec is not overridden"""
|
||||||
|
task = jobs.RunProjectUpdate()
|
||||||
|
task.instance = project_update
|
||||||
|
project_update.scm_refspec = 'refs/pull/*/head:refs/remotes/origin/pr/*'
|
||||||
|
|
||||||
|
with mock.patch.object(Licenser, 'validate', lambda *args, **kw: {}):
|
||||||
|
task.build_extra_vars_file(project_update, private_data_dir)
|
||||||
|
|
||||||
|
with open(os.path.join(private_data_dir, 'env', 'extravars')) as fd:
|
||||||
|
extra_vars = yaml.load(fd, Loader=SafeLoader)
|
||||||
|
|
||||||
|
# Custom refspec should be preserved
|
||||||
|
assert extra_vars['scm_refspec'] == 'refs/pull/*/head:refs/remotes/origin/pr/*'
|
||||||
|
|
||||||
|
def test_no_refspec_without_allow_override(self, execution_environment, private_data_dir, mock_me):
|
||||||
|
"""Test that no refspec is set when allow_override is False"""
|
||||||
|
org = Organization(pk=1)
|
||||||
|
proj = Project(pk=1, organization=org, allow_override=False)
|
||||||
|
project_update = ProjectUpdate(pk=1, project=proj, scm_type='git')
|
||||||
|
project_update.websocket_emit_status = mock.Mock()
|
||||||
|
project_update.execution_environment = execution_environment
|
||||||
|
|
||||||
|
task = jobs.RunProjectUpdate()
|
||||||
|
task.instance = project_update
|
||||||
|
|
||||||
|
with mock.patch.object(Licenser, 'validate', lambda *args, **kw: {}):
|
||||||
|
task.build_extra_vars_file(project_update, private_data_dir)
|
||||||
|
|
||||||
|
with open(os.path.join(private_data_dir, 'env', 'extravars')) as fd:
|
||||||
|
extra_vars = yaml.load(fd, Loader=SafeLoader)
|
||||||
|
|
||||||
|
# No refspec should be set
|
||||||
|
assert 'scm_refspec' not in extra_vars
|
||||||
|
|
||||||
|
|
||||||
class TestInventoryUpdateCredentials(TestJobExecution):
|
class TestInventoryUpdateCredentials(TestJobExecution):
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def inventory_update(self, execution_environment):
|
def inventory_update(self, execution_environment):
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user