From ded55778327087917048fa19257b3fdda2e58697 Mon Sep 17 00:00:00 2001 From: Caleb Boylan Date: Tue, 21 Apr 2020 09:39:16 -0700 Subject: [PATCH 1/4] Collection: Fix the tower_project scm_allow_override --- awx_collection/plugins/modules/tower_project.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/awx_collection/plugins/modules/tower_project.py b/awx_collection/plugins/modules/tower_project.py index d01b371474..d2cd3cbf9e 100644 --- a/awx_collection/plugins/modules/tower_project.py +++ b/awx_collection/plugins/modules/tower_project.py @@ -254,7 +254,7 @@ def main(): if scm_credential is not None: project_fields['credential'] = scm_credential_id if scm_allow_override is not None: - project_fields['scm_allow_override'] = scm_allow_override + project_fields['allow_override'] = scm_allow_override if scm_type == '': project_fields['local_path'] = local_path From 1e24d8b5fa5313b12aa721edfb7a734a6ff6bdfc Mon Sep 17 00:00:00 2001 From: Caleb Boylan Date: Tue, 21 Apr 2020 09:58:39 -0700 Subject: [PATCH 2/4] Collection: Add integration tests for project scm_allow_override --- .../targets/tower_project/tasks/main.yml | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/awx_collection/tests/integration/targets/tower_project/tasks/main.yml b/awx_collection/tests/integration/targets/tower_project/tasks/main.yml index 000dd62e88..dd8c0b5d96 100644 --- a/awx_collection/tests/integration/targets/tower_project/tasks/main.yml +++ b/awx_collection/tests/integration/targets/tower_project/tasks/main.yml @@ -3,6 +3,8 @@ set_fact: project_name1: "AWX-Collection-tests-tower_project-project1-{{ lookup('password', '/dev/null chars=ascii_letters length=16') }}" project_name2: "AWX-Collection-tests-tower_project-project2-{{ lookup('password', '/dev/null chars=ascii_letters length=16') }}" + project_name3: "AWX-Collection-tests-tower_project-project3-{{ lookup('password', '/dev/null chars=ascii_letters length=16') }}" + jt1: "AWX-Collection-tests-tower_project-jt1-{{ lookup('password', '/dev/null chars=ascii_letters length=16') }}" scm_cred_name: "AWX-Collection-tests-tower_project-scm-cred-{{ 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') }}" @@ -118,6 +120,54 @@ - "result.msg =='The credentials Non Existing Credential was not found on the Tower server' or result.msg =='Failed to update project, credential not found: Non Existing Credential'" +- name: Create a git project without credentials without waiting + tower_project: + name: "{{ project_name3 }}" + organization: Default + scm_type: git + scm_branch: empty_branch + scm_url: https://github.com/ansible/test-playbooks + scm_allow_override: true + register: result + +- assert: + that: + - result is changed + +- name: Create a job template that overrides the project scm_branch + tower_job_template: + name: "{{ jt1 }}" + project: "{{ project_name3 }}" + inventory: "Demo Inventory" + scm_branch: master + playbook: debug.yml + +- name: Launch "{{ jt1 }}" + tower_job_launch: + job_template: "{{ jt1 }}" + register: result + +- assert: + that: + - result is changed + +- name: wait for "{{ result.id }}" + tower_job_wait: + job_id: "{{ result.id }}" + +- name: Delete the test job_template + tower_job_template: + name: "{{ jt1 }}" + project: "{{ project_name3 }}" + inventory: "Demo Inventory" + state: absent + +- name: Delete the test project + tower_project: + name: "{{ project_name3 }}" + organization: Default + state: absent + - name: Delete the test project tower_project: name: "{{ project_name2 }}" From ba4b6bdbb7862594f51815acc816c11f722fa14d Mon Sep 17 00:00:00 2001 From: Caleb Boylan Date: Tue, 21 Apr 2020 10:08:06 -0700 Subject: [PATCH 3/4] Collection: tower_project alias allow_override to scm_allow_override --- awx_collection/plugins/modules/tower_project.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/awx_collection/plugins/modules/tower_project.py b/awx_collection/plugins/modules/tower_project.py index d2cd3cbf9e..2d84b82c0b 100644 --- a/awx_collection/plugins/modules/tower_project.py +++ b/awx_collection/plugins/modules/tower_project.py @@ -83,11 +83,13 @@ options: Only valid if scm_update_on_launch is to True, otherwise ignored. type: int default: 0 - scm_allow_override: + allow_override: description: - Allow changing the SCM branch or revision in a job template that uses this project. type: bool version_added: "3.7" + aliases: + - scm_allow_override job_timeout: version_added: "2.8" description: @@ -188,7 +190,7 @@ def main(): scm_delete_on_update=dict(type='bool', default=False), scm_update_on_launch=dict(type='bool', default=False), scm_update_cache_timeout=dict(type='int', default=0), - scm_allow_override=dict(type='bool'), + allow_override=dict(type='bool', aliases=['scm_allow_override']), job_timeout=dict(type='int', default=0), custom_virtualenv=dict(), organization=dict(required=True), @@ -214,7 +216,7 @@ def main(): scm_delete_on_update = module.params.get('scm_delete_on_update') scm_update_on_launch = module.params.get('scm_update_on_launch') scm_update_cache_timeout = module.params.get('scm_update_cache_timeout') - scm_allow_override = module.params.get('scm_allow_override') + allow_override = module.params.get('allow_override') job_timeout = module.params.get('job_timeout') custom_virtualenv = module.params.get('custom_virtualenv') organization = module.params.get('organization') @@ -253,8 +255,8 @@ def main(): project_fields['description'] = description if scm_credential is not None: project_fields['credential'] = scm_credential_id - if scm_allow_override is not None: - project_fields['allow_override'] = scm_allow_override + if allow_override is not None: + project_fields['allow_override'] = allow_override if scm_type == '': project_fields['local_path'] = local_path From f8a23f20aa00c9ebb332cc26990c16b47b4814f2 Mon Sep 17 00:00:00 2001 From: Caleb Boylan Date: Tue, 21 Apr 2020 10:08:29 -0700 Subject: [PATCH 4/4] Collection: Assert tower_project job is successful --- .../targets/tower_project/tasks/main.yml | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/awx_collection/tests/integration/targets/tower_project/tasks/main.yml b/awx_collection/tests/integration/targets/tower_project/tasks/main.yml index dd8c0b5d96..cece78acd5 100644 --- a/awx_collection/tests/integration/targets/tower_project/tasks/main.yml +++ b/awx_collection/tests/integration/targets/tower_project/tasks/main.yml @@ -127,7 +127,7 @@ scm_type: git scm_branch: empty_branch scm_url: https://github.com/ansible/test-playbooks - scm_allow_override: true + allow_override: true register: result - assert: @@ -151,9 +151,14 @@ that: - result is changed -- name: wait for "{{ result.id }}" +- name: "wait for job {{ result.id }}" tower_job_wait: job_id: "{{ result.id }}" + register: job + +- assert: + that: + - job is successful - name: Delete the test job_template tower_job_template: @@ -162,13 +167,13 @@ inventory: "Demo Inventory" state: absent -- name: Delete the test project +- name: Delete the test project 3 tower_project: name: "{{ project_name3 }}" organization: Default state: absent -- name: Delete the test project +- name: Delete the test project 2 tower_project: name: "{{ project_name2 }}" organization: "{{ org_name }}" @@ -186,7 +191,7 @@ that: - result is changed -- name: Delete the other test project +- name: Delete the test project 1 tower_project: name: "{{ project_name1 }}" organization: Default