Merge pull request #10000 from sean-m-sullivan/project_update_fix

Fix project update

SUMMARY
Fixing bug found in #8686
Found that the on change was not triggering due to no actual changes in the Post, Set so when project update is set to true, that the wait for update is Always triggered. Also added logic from project_update to set changed status depending on if refspec changes.
ISSUE TYPE

Bugfix Pull Request

COMPONENT NAME

awx_collection

AWX VERSION
19.0.0

Reviewed-by: Bianca Henderson <beeankha@gmail.com>
Reviewed-by: John Westcott IV <None>
Reviewed-by: Sean Sullivan <None>
Reviewed-by: Alan Rominger <arominge@redhat.com>
This commit is contained in:
softwarefactory-project-zuul[bot]
2021-04-27 16:53:01 +00:00
committed by GitHub
2 changed files with 222 additions and 209 deletions

View File

@@ -204,6 +204,7 @@ def wait_for_project_update(module, last_request):
wait = module.params.get('wait')
timeout = module.params.get('timeout')
interval = module.params.get('interval')
scm_revision_original = last_request['scm_revision']
if 'current_update' in last_request['summary_fields']:
running = True
@@ -229,10 +230,15 @@ def wait_for_project_update(module, last_request):
start = time.time()
# Invoke wait function
module.wait_on_url(
result_final = module.wait_on_url(
url=result['json']['url'], object_name=module.get_item_name(last_request), object_type='Project Update', timeout=timeout, interval=interval
)
# Set Changed to correct value depending on if hash changed Also output refspec comparision
module.json_output['changed'] = True
if result_final['json']['scm_revision'] == scm_revision_original:
module.json_output['changed'] = False
module.exit_json(**module.json_output)
@@ -380,10 +386,21 @@ def main():
on_change = wait_for_project_update
# If the state was present and we can let the module build or update the existing project, this will return on its own
module.create_or_update_if_needed(
project, project_fields, endpoint='projects', item_type='project', associations=association_fields, on_create=on_change, on_update=on_change
response = module.create_or_update_if_needed(
project,
project_fields,
endpoint='projects',
item_type='project',
associations=association_fields,
on_create=on_change,
on_update=on_change,
auto_exit=not update_project,
)
if update_project:
wait_for_project_update(module, response)
module.exit_json(**module.json_output)
if __name__ == '__main__':
main()

View File

@@ -9,6 +9,7 @@
org_name: "AWX-Collection-tests-tower_project-org-{{ lookup('password', '/dev/null chars=ascii_letters length=16') }}"
cred_name: "AWX-Collection-tests-tower_project-cred-{{ lookup('password', '/dev/null chars=ascii_letters length=16') }}"
- block:
- name: Create an SCM Credential
tower_credential:
name: "{{ scm_cred_name }}"
@@ -20,13 +21,13 @@
that:
- result is changed
- name: Create a git project without credentials without waiting
- name: Create a git project without credentials and wait
tower_project:
name: "{{ project_name1 }}"
organization: Default
scm_type: git
scm_url: https://github.com/ansible/test-playbooks
wait: false
wait: true
register: result
- assert:
@@ -39,8 +40,9 @@
organization: Default
scm_type: git
scm_url: https://github.com/ansible/test-playbooks
wait: true
wait: false
register: result
ignore_errors: true
- assert:
that:
@@ -139,7 +141,7 @@
that:
- result is changed
- name: Update a git project, update the project and wait.
- name: Update the project and wait. Verify not changed as no change made to repo and refspec not changed
tower_project:
name: "{{ project_name3 }}"
organization: Default
@@ -151,16 +153,9 @@
update_project: true
register: result
- name: Update a git project, update the project without waiting.
tower_project:
name: "{{ project_name3 }}"
organization: Default
scm_type: git
scm_branch: empty_branch
scm_url: https://github.com/ansible/test-playbooks
wait: false
update_project: true
register: result
- assert:
that:
- result is not changed
- name: Create a job template that overrides the project scm_branch
tower_job_template:
@@ -188,6 +183,7 @@
that:
- job is successful
always:
- name: Delete the test job_template
tower_job_template:
name: "{{ jt1 }}"