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') wait = module.params.get('wait')
timeout = module.params.get('timeout') timeout = module.params.get('timeout')
interval = module.params.get('interval') interval = module.params.get('interval')
scm_revision_original = last_request['scm_revision']
if 'current_update' in last_request['summary_fields']: if 'current_update' in last_request['summary_fields']:
running = True running = True
@@ -229,10 +230,15 @@ def wait_for_project_update(module, last_request):
start = time.time() start = time.time()
# Invoke wait function # 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 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) module.exit_json(**module.json_output)
@@ -380,10 +386,21 @@ def main():
on_change = wait_for_project_update 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 # 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( 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 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__': if __name__ == '__main__':
main() main()

View File

@@ -9,245 +9,241 @@
org_name: "AWX-Collection-tests-tower_project-org-{{ lookup('password', '/dev/null chars=ascii_letters length=16') }}" 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') }}" cred_name: "AWX-Collection-tests-tower_project-cred-{{ lookup('password', '/dev/null chars=ascii_letters length=16') }}"
- name: Create an SCM Credential - block:
tower_credential: - name: Create an SCM Credential
name: "{{ scm_cred_name }}" tower_credential:
organization: Default name: "{{ scm_cred_name }}"
kind: scm organization: Default
register: result kind: scm
register: result
- assert: - assert:
that: that:
- result is changed - result is changed
- name: Create a git project without credentials without waiting - name: Create a git project without credentials and wait
tower_project: tower_project:
name: "{{ project_name1 }}" name: "{{ project_name1 }}"
organization: Default organization: Default
scm_type: git scm_type: git
scm_url: https://github.com/ansible/test-playbooks scm_url: https://github.com/ansible/test-playbooks
wait: false wait: true
register: result register: result
- assert: - assert:
that: that:
- result is changed - result is changed
- name: Recreate the project to validate not changed - name: Recreate the project to validate not changed
tower_project: tower_project:
name: "{{ project_name1 }}" name: "{{ project_name1 }}"
organization: Default organization: Default
scm_type: git scm_type: git
scm_url: https://github.com/ansible/test-playbooks scm_url: https://github.com/ansible/test-playbooks
wait: true wait: false
register: result register: result
ignore_errors: true
- assert: - assert:
that: that:
- result is not changed - result is not changed
- name: Create organizations - name: Create organizations
tower_organization: tower_organization:
name: "{{ org_name }}" name: "{{ org_name }}"
register: result register: result
- assert: - assert:
that: that:
- result is changed - result is changed
- name: Create credential - name: Create credential
tower_credential: tower_credential:
kind: scm kind: scm
name: "{{ cred_name }}" name: "{{ cred_name }}"
organization: "{{ org_name }}" organization: "{{ org_name }}"
register: result register: result
- assert: - assert:
that: that:
- result is changed - result is changed
- name: Create a new test project in check_mode - name: Create a new test project in check_mode
tower_project: tower_project:
name: "{{ project_name2 }}" name: "{{ project_name2 }}"
organization: "{{ org_name }}" organization: "{{ org_name }}"
scm_type: git scm_type: git
scm_url: https://github.com/ansible/test-playbooks scm_url: https://github.com/ansible/test-playbooks
scm_credential: "{{ cred_name }}" scm_credential: "{{ cred_name }}"
check_mode: true check_mode: true
- name: "Copy tower project from {{ project_name1 }}" - name: "Copy tower project from {{ project_name1 }}"
tower_project: tower_project:
name: "{{ project_name2 }}" name: "{{ project_name2 }}"
copy_from: "{{ project_name1 }}" copy_from: "{{ project_name1 }}"
organization: "{{ org_name }}" organization: "{{ org_name }}"
scm_type: git scm_type: git
scm_credential: "{{ cred_name }}" scm_credential: "{{ cred_name }}"
state: present state: present
register: result register: result
# If this fails it may be because the check_mode task actually already created # If this fails it may be because the check_mode task actually already created
# the project, or it could be because the module actually failed somehow # the project, or it could be because the module actually failed somehow
- assert: - assert:
that: that:
- result.copied - result.copied
- name: Check module fails with correct msg when given non-existing org as param - name: Check module fails with correct msg when given non-existing org as param
tower_project: tower_project:
name: "{{ project_name2 }}" name: "{{ project_name2 }}"
organization: Non_Existing_Org organization: Non_Existing_Org
scm_type: git scm_type: git
scm_url: https://github.com/ansible/test-playbooks scm_url: https://github.com/ansible/test-playbooks
scm_credential: "{{ cred_name }}" scm_credential: "{{ cred_name }}"
register: result register: result
ignore_errors: true ignore_errors: true
- assert: - assert:
that: that:
- "result is failed" - "result is failed"
- "result is not changed" - "result is not changed"
- "'Non_Existing_Org' in result.msg" - "'Non_Existing_Org' in result.msg"
- "result.total_results == 0" - "result.total_results == 0"
- name: Check module fails with correct msg when given non-existing credential as param - name: Check module fails with correct msg when given non-existing credential as param
tower_project: tower_project:
name: "{{ project_name2 }}" name: "{{ project_name2 }}"
organization: "{{ org_name }}" organization: "{{ org_name }}"
scm_type: git scm_type: git
scm_url: https://github.com/ansible/test-playbooks scm_url: https://github.com/ansible/test-playbooks
scm_credential: Non_Existing_Credential scm_credential: Non_Existing_Credential
register: result register: result
ignore_errors: true ignore_errors: true
- assert: - assert:
that: that:
- "result is failed" - "result is failed"
- "result is not changed" - "result is not changed"
- "'Non_Existing_Credential' in result.msg" - "'Non_Existing_Credential' in result.msg"
- "result.total_results == 0" - "result.total_results == 0"
- name: Create a git project without credentials without waiting - name: Create a git project without credentials without waiting
tower_project: tower_project:
name: "{{ project_name3 }}" name: "{{ project_name3 }}"
organization: Default organization: Default
scm_type: git scm_type: git
scm_branch: empty_branch scm_branch: empty_branch
scm_url: https://github.com/ansible/test-playbooks scm_url: https://github.com/ansible/test-playbooks
allow_override: true allow_override: true
register: result register: result
- assert: - assert:
that: that:
- result is changed - 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: tower_project:
name: "{{ project_name3 }}" name: "{{ project_name3 }}"
organization: Default organization: Default
scm_type: git scm_type: git
scm_branch: empty_branch scm_branch: empty_branch
scm_url: https://github.com/ansible/test-playbooks scm_url: https://github.com/ansible/test-playbooks
allow_override: true allow_override: true
wait: true wait: true
update_project: true update_project: true
register: result register: result
- name: Update a git project, update the project without waiting. - assert:
tower_project: that:
name: "{{ project_name3 }}" - result is not changed
organization: Default
scm_type: git
scm_branch: empty_branch
scm_url: https://github.com/ansible/test-playbooks
wait: false
update_project: true
register: result
- name: Create a job template that overrides the project scm_branch - name: Create a job template that overrides the project scm_branch
tower_job_template: tower_job_template:
name: "{{ jt1 }}" name: "{{ jt1 }}"
project: "{{ project_name3 }}" project: "{{ project_name3 }}"
inventory: "Demo Inventory" inventory: "Demo Inventory"
scm_branch: master scm_branch: master
playbook: debug.yml playbook: debug.yml
- name: Launch "{{ jt1 }}" - name: Launch "{{ jt1 }}"
tower_job_launch: tower_job_launch:
job_template: "{{ jt1 }}" job_template: "{{ jt1 }}"
register: result register: result
- assert: - assert:
that: that:
- result is changed - result is changed
- name: "wait for job {{ result.id }}" - name: "wait for job {{ result.id }}"
tower_job_wait: tower_job_wait:
job_id: "{{ result.id }}" job_id: "{{ result.id }}"
register: job register: job
- assert: - assert:
that: that:
- job is successful - job is successful
- name: Delete the test job_template always:
tower_job_template: - name: Delete the test job_template
name: "{{ jt1 }}" tower_job_template:
project: "{{ project_name3 }}" name: "{{ jt1 }}"
inventory: "Demo Inventory" project: "{{ project_name3 }}"
state: absent inventory: "Demo Inventory"
state: absent
- name: Delete the test project 3 - name: Delete the test project 3
tower_project: tower_project:
name: "{{ project_name3 }}" name: "{{ project_name3 }}"
organization: Default organization: Default
state: absent state: absent
- name: Delete the test project 2 - name: Delete the test project 2
tower_project: tower_project:
name: "{{ project_name2 }}" name: "{{ project_name2 }}"
organization: "{{ org_name }}" organization: "{{ org_name }}"
state: absent state: absent
- name: Delete the SCM Credential - name: Delete the SCM Credential
tower_credential: tower_credential:
name: "{{ scm_cred_name }}" name: "{{ scm_cred_name }}"
organization: Default organization: Default
kind: scm kind: scm
state: absent state: absent
register: result register: result
- assert: - assert:
that: that:
- result is changed - result is changed
- name: Delete the test project 1 - name: Delete the test project 1
tower_project: tower_project:
name: "{{ project_name1 }}" name: "{{ project_name1 }}"
organization: Default organization: Default
state: absent state: absent
register: result register: result
- assert: - assert:
that: that:
- result is changed - result is changed
- name: Delete credential - name: Delete credential
tower_credential: tower_credential:
kind: scm kind: scm
name: "{{ cred_name }}" name: "{{ cred_name }}"
organization: "{{ org_name }}" organization: "{{ org_name }}"
state: absent state: absent
register: result register: result
- assert: - assert:
that: that:
- result is changed - result is changed
- name: Delete the organization - name: Delete the organization
tower_organization: tower_organization:
name: "{{ org_name }}" name: "{{ org_name }}"
state: absent state: absent
register: result register: result
- assert: - assert:
that: that:
- result is changed - result is changed