From 872a7b4a7a54133f8a060d6fc6050d195d08c780 Mon Sep 17 00:00:00 2001 From: Ryan Petrello Date: Fri, 16 Mar 2018 13:28:19 -0400 Subject: [PATCH] add some Tower module integration tests (and fix a bug or two) (#37421) * add additional test coverage for tower modules * add test coverage for the tower_credential module * add test coverage for the tower_user module * fix a bug in py3 for tower_credential when ssh_key_data is specified * add test coverage for tower_host, tower_label, and tower_project * add test coverage for tower_inventory and tower_job_template * add more test coverage for tower modules - tower_job_launch - tower_job_list - tower_job_wait - tower_job_cancel * add a check mode/version assertion for tower module integration tests * add test coverage for the tower_role module * add test coverage for the tower_group module * add more integration test edge cases for various tower modules * give the job_wait module more time before failing * randomize passwords in the tower_user and tower_group tests --- .../ansible_tower/tower_credential.py | 25 +- .../ansible_tower/tower_group.py | 3 +- .../ansible_tower/tower_host.py | 3 +- .../ansible_tower/tower_role.py | 4 + .../targets/tower_credential/aliases | 2 + .../targets/tower_credential/tasks/main.yml | 510 ++++++++++++++++++ test/integration/targets/tower_group/aliases | 2 + .../targets/tower_group/tasks/main.yml | 34 ++ test/integration/targets/tower_host/aliases | 2 + .../targets/tower_host/tasks/main.yml | 33 ++ .../targets/tower_inventory/aliases | 2 + .../targets/tower_inventory/tasks/main.yml | 21 + .../targets/tower_job_cancel/aliases | 2 + .../targets/tower_job_cancel/tasks/main.yml | 15 + .../targets/tower_job_launch/aliases | 2 + .../targets/tower_job_launch/tasks/main.yml | 11 + .../targets/tower_job_list/aliases | 2 + .../targets/tower_job_list/tasks/main.yml | 20 + .../targets/tower_job_template/aliases | 2 + .../targets/tower_job_template/tasks/main.yml | 54 ++ .../targets/tower_job_wait/aliases | 2 + .../targets/tower_job_wait/tasks/main.yml | 16 + test/integration/targets/tower_label/aliases | 2 + .../targets/tower_label/tasks/main.yml | 7 + .../targets/tower_organization/tasks/main.yml | 10 + .../integration/targets/tower_project/aliases | 2 + .../targets/tower_project/tasks/main.yml | 27 + test/integration/targets/tower_role/aliases | 2 + .../targets/tower_role/tasks/main.yml | 39 ++ .../targets/tower_team/tasks/main.yml | 29 + test/integration/targets/tower_user/aliases | 2 + .../targets/tower_user/tasks/main.yml | 76 +++ 32 files changed, 954 insertions(+), 9 deletions(-) create mode 100644 test/integration/targets/tower_credential/aliases create mode 100644 test/integration/targets/tower_credential/tasks/main.yml create mode 100644 test/integration/targets/tower_group/aliases create mode 100644 test/integration/targets/tower_group/tasks/main.yml create mode 100644 test/integration/targets/tower_host/aliases create mode 100644 test/integration/targets/tower_host/tasks/main.yml create mode 100644 test/integration/targets/tower_inventory/aliases create mode 100644 test/integration/targets/tower_inventory/tasks/main.yml create mode 100644 test/integration/targets/tower_job_cancel/aliases create mode 100644 test/integration/targets/tower_job_cancel/tasks/main.yml create mode 100644 test/integration/targets/tower_job_launch/aliases create mode 100644 test/integration/targets/tower_job_launch/tasks/main.yml create mode 100644 test/integration/targets/tower_job_list/aliases create mode 100644 test/integration/targets/tower_job_list/tasks/main.yml create mode 100644 test/integration/targets/tower_job_template/aliases create mode 100644 test/integration/targets/tower_job_template/tasks/main.yml create mode 100644 test/integration/targets/tower_job_wait/aliases create mode 100644 test/integration/targets/tower_job_wait/tasks/main.yml create mode 100644 test/integration/targets/tower_label/aliases create mode 100644 test/integration/targets/tower_label/tasks/main.yml create mode 100644 test/integration/targets/tower_project/aliases create mode 100644 test/integration/targets/tower_project/tasks/main.yml create mode 100644 test/integration/targets/tower_role/aliases create mode 100644 test/integration/targets/tower_role/tasks/main.yml create mode 100644 test/integration/targets/tower_user/aliases create mode 100644 test/integration/targets/tower_user/tasks/main.yml diff --git a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py index 37380d13301..6932d3ad69f 100644 --- a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py +++ b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py @@ -73,6 +73,14 @@ options: client: description: - Client or application ID for azure_rm type. + required: False + default: null + security_token: + description: + - STS token for aws type. + required: False + default: null + version_added: "2.6" secret: description: - Secret token for azure_rm type. @@ -119,6 +127,7 @@ EXAMPLES = ''' import os +from ansible.module_utils._text import to_text from ansible.module_utils.ansible_tower import tower_argument_spec, tower_auth_config, tower_check_mode, HAS_TOWER_CLI try: @@ -184,6 +193,7 @@ def main(): authorize=dict(type='bool', default=False), authorize_password=dict(no_log=True), client=dict(), + security_token=dict(), secret=dict(), tenant=dict(), subscription=dict(), @@ -254,13 +264,14 @@ def main(): if os.path.isdir(filename): module.fail_json(msg='attempted to read contents of directory: %s' % filename) with open(filename, 'rb') as f: - module.params['ssh_key_data'] = f.read() - - for key in ('authorize', 'authorize_password', 'client', 'secret', - 'tenant', 'subscription', 'domain', 'become_method', - 'become_username', 'become_password', 'vault_password', - 'project', 'host', 'username', 'password', - 'ssh_key_data', 'ssh_key_unlock'): + module.params['ssh_key_data'] = to_text(f.read()) + + for key in ('authorize', 'authorize_password', 'client', + 'security_token', 'secret', 'tenant', 'subscription', + 'domain', 'become_method', 'become_username', + 'become_password', 'vault_password', 'project', 'host', + 'username', 'password', 'ssh_key_data', + 'ssh_key_unlock'): if 'kind' in params: params[key] = module.params.get(key) elif module.params.get(key): diff --git a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_group.py b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_group.py index 0afdeeace10..7818c92b04e 100644 --- a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_group.py +++ b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_group.py @@ -140,7 +140,8 @@ def main(): if variables: if variables.startswith('@'): filename = os.path.expanduser(variables[1:]) - variables = module.contents_from_file(filename) + with open(filename, 'r') as f: + variables = f.read() json_output = {'group': name, 'state': state} diff --git a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_host.py b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_host.py index 8f028c8755a..05eec7556c5 100644 --- a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_host.py +++ b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_host.py @@ -100,7 +100,8 @@ def main(): if variables: if variables.startswith('@'): filename = os.path.expanduser(variables[1:]) - variables = module.contents_from_file(filename) + with open(filename, 'r') as f: + variables = f.read() json_output = {'host': name, 'state': state} diff --git a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_role.py b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_role.py index 46940ab1ecc..096f6173f59 100644 --- a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_role.py +++ b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_role.py @@ -87,6 +87,10 @@ def update_resources(module, p): by name using their unique field (identity) ''' params = p.copy() + for key in p: + if key.startswith('tower_'): + params.pop(key) + params.pop('state', None) identity_map = { 'user': 'username', 'team': 'name', diff --git a/test/integration/targets/tower_credential/aliases b/test/integration/targets/tower_credential/aliases new file mode 100644 index 00000000000..42b2b7300b9 --- /dev/null +++ b/test/integration/targets/tower_credential/aliases @@ -0,0 +1,2 @@ +cloud/tower +posix/ci/cloud/group4/tower diff --git a/test/integration/targets/tower_credential/tasks/main.yml b/test/integration/targets/tower_credential/tasks/main.yml new file mode 100644 index 00000000000..77abf5a5ca4 --- /dev/null +++ b/test/integration/targets/tower_credential/tasks/main.yml @@ -0,0 +1,510 @@ +- name: create a tempdir for an SSH key + local_action: shell mktemp -d + register: tempdir + +- name: Generate a local SSH key + local_action: "shell ssh-keygen -b 2048 -t rsa -f {{ tempdir.stdout }}/id_rsa -q -N 'passphrase'" + +- name: Create a User-specific credential + tower_credential: + name: SSH Credential + organization: Default + user: admin + state: present + kind: ssh + register: result + +- assert: + that: + - "result is changed" + +- name: Delete a User-specific credential + tower_credential: + name: SSH Credential + organization: Default + user: admin + state: absent + kind: ssh + register: result + +- assert: + that: + - "result is changed" + +- name: Create a valid SSH credential + tower_credential: + name: SSH Credential + organization: Default + state: present + kind: ssh + description: An example SSH credential + username: joe + password: secret + become_method: sudo + become_username: superuser + become_password: supersecret + ssh_key_data: "{{ tempdir.stdout }}/id_rsa" + ssh_key_unlock: "passphrase" + register: result + +- assert: + that: + - "result is changed" + +- name: Create an invalid SSH credential (passphrase required) + tower_credential: + name: SSH Credential + organization: Default + state: present + kind: ssh + username: joe + ssh_key_data: "{{ tempdir.stdout }}/id_rsa" + ignore_errors: yes + register: result + +- assert: + that: + - "result is failed" + - "'must be set when SSH key is encrypted' in result.module_stderr" + +- name: Create an invalid SSH credential (ssh_key_data file is missing) + tower_credential: + name: SSH Credential + organization: Default + state: present + kind: ssh + username: joe + ssh_key_data: "{{ tempdir.stdout }}/not_a_valid_file" + ignore_errors: yes + register: result + +- assert: + that: + - "result is failed" + - "'file not found' in result.msg" + +- name: Create an invalid SSH credential (ssh_key_data is a directory) + tower_credential: + name: SSH Credential + organization: Default + state: present + kind: ssh + username: joe + ssh_key_data: "{{ tempdir.stdout }}" + ignore_errors: yes + register: result + +- assert: + that: + - "result is failed" + - "'attempted to read contents of directory' in result.msg" + +- name: Create an invalid SSH credential (Organization not found) + tower_credential: + name: SSH Credential + organization: Missing Organization + state: present + kind: ssh + username: joe + ignore_errors: yes + register: result + +- assert: + that: + - "result is failed" + - "'The requested object could not be found' in result.module_stderr" + +- name: Delete an SSH credential + tower_credential: + name: SSH Credential + organization: Default + state: absent + kind: ssh + register: result + +- assert: + that: + - "result is changed" + +- name: Create a valid Vault credential + tower_credential: + name: Vault Credential + organization: Default + state: present + kind: vault + description: An example Vault credential + vault_password: secret-vault + register: result + +- assert: + that: + - "result is changed" + +- name: Create a valid Vault credential w/ kind=ssh (deprecated) + tower_credential: + name: Vault Credential + organization: Default + state: present + kind: ssh + description: An example Vault credential + vault_password: secret-vault + register: result + +- assert: + that: + - "result is changed" + +- name: Delete a Vault credential + tower_credential: + name: Vault Credential + organization: Default + state: absent + kind: vault + register: result + +- assert: + that: + - "result is changed" + +- name: Create a valid Network credential + tower_credential: + name: Network Credential + organization: Default + state: present + kind: net + username: joe + password: secret + authorize: true + authorize_password: authorize-me + register: result + +- assert: + that: + - "result is changed" + +- name: Delete a Network credential + tower_credential: + name: Network Credential + organization: Default + state: absent + kind: net + register: result + +- assert: + that: + - "result is changed" + +- name: Create a valid SCM credential + tower_credential: + name: SCM Credential + organization: Default + state: present + kind: scm + username: joe + password: secret + ssh_key_data: "{{ tempdir.stdout }}/id_rsa" + ssh_key_unlock: "passphrase" + register: result + +- assert: + that: + - "result is changed" + +- name: Delete an SCM credential + tower_credential: + name: SCM Credential + organization: Default + state: absent + kind: scm + register: result + +- assert: + that: + - "result is changed" + +- name: Create a valid AWS credential + tower_credential: + name: AWS Credential + organization: Default + state: present + kind: aws + username: joe + password: secret + security_token: aws-token + register: result + +- assert: + that: + - "result is changed" + +- name: Delete an AWS credential + tower_credential: + name: AWS Credential + organization: Default + state: absent + kind: aws + register: result + +- assert: + that: + - "result is changed" + +- name: Create a valid VMWare credential + tower_credential: + name: VMWare Credential + organization: Default + state: present + kind: vmware + host: https://example.org + username: joe + password: secret + register: result + +- assert: + that: + - "result is changed" + +- name: Delete an VMWare credential + tower_credential: + name: VMWare Credential + organization: Default + state: absent + kind: vmware + register: result + +- assert: + that: + - "result is changed" + +- name: Create a valid Satellite6 credential + tower_credential: + name: Satellite6 Credential + organization: Default + state: present + kind: satellite6 + host: https://example.org + username: joe + password: secret + register: result + +- assert: + that: + - "result is changed" + +- name: Delete a Satellite6 credential + tower_credential: + name: Satellite6 Credential + organization: Default + state: absent + kind: satellite6 + register: result + +- assert: + that: + - "result is changed" + +- name: Create a valid CloudForms credential + tower_credential: + name: CloudForms Credential + organization: Default + state: present + kind: cloudforms + host: https://example.org + username: joe + password: secret + register: result + +- assert: + that: + - "result is changed" + +- name: Delete a CloudForms credential + tower_credential: + name: CloudForms Credential + organization: Default + state: absent + kind: cloudforms + register: result + +- assert: + that: + - "result is changed" + +- name: Create a valid GCE credential + tower_credential: + name: GCE Credential + organization: Default + state: present + kind: gce + username: joe + project: ABC123 + ssh_key_data: "{{ tempdir.stdout }}/id_rsa" + register: result + +- assert: + that: + - "result is changed" + +- name: Delete a GCE credential + tower_credential: + name: GCE Credential + organization: Default + state: absent + kind: gce + register: result + +- assert: + that: + - "result is changed" + +- name: Create a valid AzureRM credential + tower_credential: + name: AzureRM Credential + organization: Default + state: present + kind: azure_rm + username: joe + password: secret + subscription: some-subscription + register: result + +- assert: + that: + - "result is changed" + +- name: Create a valid AzureRM credential with a tenant + tower_credential: + name: AzureRM Credential + organization: Default + state: present + kind: azure_rm + client: some-client + secret: some-secret + tenant: some-tenant + subscription: some-subscription + register: result + +- assert: + that: + - "result is changed" + +- name: Delete an AzureRM credential + tower_credential: + name: AzureRM Credential + organization: Default + state: absent + kind: azure_rm + register: result + +- assert: + that: + - "result is changed" + +- name: Create a valid OpenStack credential + tower_credential: + name: OpenStack Credential + organization: Default + state: present + kind: openstack + host: https://keystone.example.org + username: joe + password: secret + project: tenant123 + domain: some-domain + register: result + +- assert: + that: + - "result is changed" + +- name: Delete a OpenStack credential + tower_credential: + name: OpenStack Credential + organization: Default + state: absent + kind: openstack + register: result + +- assert: + that: + - "result is changed" + +- name: Create a valid RHV credential + tower_credential: + name: RHV Credential + organization: Default + state: present + kind: rhv + host: https://example.org + username: joe + password: secret + register: result + +- assert: + that: + - "result is changed" + +- name: Delete an RHV credential + tower_credential: + name: RHV Credential + organization: Default + state: absent + kind: rhv + register: result + +- assert: + that: + - "result is changed" + +- name: Create a valid Insights credential + tower_credential: + name: Insights Credential + organization: Default + state: present + kind: insights + username: joe + password: secret + register: result + +- assert: + that: + - "result is changed" + +- name: Delete an Insights credential + tower_credential: + name: Insights Credential + organization: Default + state: absent + kind: insights + register: result + +- assert: + that: + - "result is changed" + +- name: Create a valid Tower-to-Tower credential + tower_credential: + name: Tower Credential + organization: Default + state: present + kind: tower + host: https://tower.example.org + username: joe + password: secret + register: result + +- assert: + that: + - "result is changed" + +- name: Delete a Tower-to-Tower credential + tower_credential: + name: Tower Credential + organization: Default + state: absent + kind: tower + register: result + +- assert: + that: + - "result is changed" diff --git a/test/integration/targets/tower_group/aliases b/test/integration/targets/tower_group/aliases new file mode 100644 index 00000000000..42b2b7300b9 --- /dev/null +++ b/test/integration/targets/tower_group/aliases @@ -0,0 +1,2 @@ +cloud/tower +posix/ci/cloud/group4/tower diff --git a/test/integration/targets/tower_group/tasks/main.yml b/test/integration/targets/tower_group/tasks/main.yml new file mode 100644 index 00000000000..d559ba69192 --- /dev/null +++ b/test/integration/targets/tower_group/tasks/main.yml @@ -0,0 +1,34 @@ +- name: create a tempdir for hostvars + local_action: shell mktemp -d + register: tempdir + +- name: write a file w/ hostvars + local_action: + module: lineinfile + dest: "{{ tempdir.stdout }}/vars" + line: '{"foo": "bar"}' + create: true + +- name: Create a Group + tower_group: + name: Some Group + inventory: Demo Inventory + state: present + source: ec2 + variables: "@{{ tempdir.stdout }}/vars" + register: result + +- assert: + that: + - "result is changed" + +- name: Delete a Group + tower_group: + name: Some Group + inventory: Demo Inventory + state: absent + register: result + +- assert: + that: + - "result is changed" diff --git a/test/integration/targets/tower_host/aliases b/test/integration/targets/tower_host/aliases new file mode 100644 index 00000000000..42b2b7300b9 --- /dev/null +++ b/test/integration/targets/tower_host/aliases @@ -0,0 +1,2 @@ +cloud/tower +posix/ci/cloud/group4/tower diff --git a/test/integration/targets/tower_host/tasks/main.yml b/test/integration/targets/tower_host/tasks/main.yml new file mode 100644 index 00000000000..b56553f14ee --- /dev/null +++ b/test/integration/targets/tower_host/tasks/main.yml @@ -0,0 +1,33 @@ +- name: create a tempdir for hostvars + local_action: shell mktemp -d + register: tempdir + +- name: write a file w/ hostvars + local_action: + module: lineinfile + dest: "{{ tempdir.stdout }}/vars" + line: '{"foo": "bar"}' + create: true + +- name: Create a Host + tower_host: + name: "some-host" + inventory: "Demo Inventory" + state: present + variables: "@{{ tempdir.stdout }}/vars" + register: result + +- assert: + that: + - "result is changed" + +- name: Delete a Host + tower_host: + name: "some-host" + inventory: "Demo Inventory" + state: absent + register: result + +- assert: + that: + - "result is changed" diff --git a/test/integration/targets/tower_inventory/aliases b/test/integration/targets/tower_inventory/aliases new file mode 100644 index 00000000000..42b2b7300b9 --- /dev/null +++ b/test/integration/targets/tower_inventory/aliases @@ -0,0 +1,2 @@ +cloud/tower +posix/ci/cloud/group4/tower diff --git a/test/integration/targets/tower_inventory/tasks/main.yml b/test/integration/targets/tower_inventory/tasks/main.yml new file mode 100644 index 00000000000..0d45bb8c723 --- /dev/null +++ b/test/integration/targets/tower_inventory/tasks/main.yml @@ -0,0 +1,21 @@ +- name: Create an Inventory + tower_inventory: + name: my-inventory + organization: Default + state: present + register: result + +- assert: + that: + - "result is changed" + +- name: Delete an Inventory + tower_inventory: + name: my-inventory + organization: Default + state: absent + register: result + +- assert: + that: + - "result is changed" diff --git a/test/integration/targets/tower_job_cancel/aliases b/test/integration/targets/tower_job_cancel/aliases new file mode 100644 index 00000000000..42b2b7300b9 --- /dev/null +++ b/test/integration/targets/tower_job_cancel/aliases @@ -0,0 +1,2 @@ +cloud/tower +posix/ci/cloud/group4/tower diff --git a/test/integration/targets/tower_job_cancel/tasks/main.yml b/test/integration/targets/tower_job_cancel/tasks/main.yml new file mode 100644 index 00000000000..4d795d6096d --- /dev/null +++ b/test/integration/targets/tower_job_cancel/tasks/main.yml @@ -0,0 +1,15 @@ +- name: Launch a Job Template + tower_job_launch: + job_template: "Demo Job Template" + inventory: "Demo Inventory" + credential: "Demo Credential" + register: job + +- assert: + that: + - "job is changed" + - "job.status == 'pending'" + +- name: Cancel the job + tower_job_cancel: + job_id: "{{ job.id }}" diff --git a/test/integration/targets/tower_job_launch/aliases b/test/integration/targets/tower_job_launch/aliases new file mode 100644 index 00000000000..42b2b7300b9 --- /dev/null +++ b/test/integration/targets/tower_job_launch/aliases @@ -0,0 +1,2 @@ +cloud/tower +posix/ci/cloud/group4/tower diff --git a/test/integration/targets/tower_job_launch/tasks/main.yml b/test/integration/targets/tower_job_launch/tasks/main.yml new file mode 100644 index 00000000000..f619368d238 --- /dev/null +++ b/test/integration/targets/tower_job_launch/tasks/main.yml @@ -0,0 +1,11 @@ +- name: Launch a Job Template + tower_job_launch: + job_template: "Demo Job Template" + inventory: "Demo Inventory" + credential: "Demo Credential" + register: result + +- assert: + that: + - "result is changed" + - "result.status == 'pending'" diff --git a/test/integration/targets/tower_job_list/aliases b/test/integration/targets/tower_job_list/aliases new file mode 100644 index 00000000000..42b2b7300b9 --- /dev/null +++ b/test/integration/targets/tower_job_list/aliases @@ -0,0 +1,2 @@ +cloud/tower +posix/ci/cloud/group4/tower diff --git a/test/integration/targets/tower_job_list/tasks/main.yml b/test/integration/targets/tower_job_list/tasks/main.yml new file mode 100644 index 00000000000..63c6061f465 --- /dev/null +++ b/test/integration/targets/tower_job_list/tasks/main.yml @@ -0,0 +1,20 @@ +- name: Launch a Job Template + tower_job_launch: + job_template: "Demo Job Template" + inventory: "Demo Inventory" + credential: "Demo Credential" + register: job + +- assert: + that: + - "job is changed" + - "job.status == 'pending'" + +- name: List jobs w/ a matching primary key + tower_job_list: + query: {"id": "{{ job.id }}"} + register: matching_jobs + +- assert: + that: + - "{{ matching_jobs.count }} == 1" diff --git a/test/integration/targets/tower_job_template/aliases b/test/integration/targets/tower_job_template/aliases new file mode 100644 index 00000000000..42b2b7300b9 --- /dev/null +++ b/test/integration/targets/tower_job_template/aliases @@ -0,0 +1,2 @@ +cloud/tower +posix/ci/cloud/group4/tower diff --git a/test/integration/targets/tower_job_template/tasks/main.yml b/test/integration/targets/tower_job_template/tasks/main.yml new file mode 100644 index 00000000000..b86a9a6f525 --- /dev/null +++ b/test/integration/targets/tower_job_template/tasks/main.yml @@ -0,0 +1,54 @@ +- name: Create an SCM Credential + tower_credential: + name: SCM Credential for JT + organization: Default + kind: scm + +- name: Create a Demo Project + tower_project: + name: Job Template Test Project + organization: Default + state: present + scm_type: git + scm_url: https://github.com/ansible/ansible-tower-samples.git + scm_credential: SCM Credential for JT + register: result + +- name: Update the project (to clone the git repo) + uri: + url: "https://{{ lookup('env', 'TOWER_HOST') }}/api/v2/projects/{{ result.id }}/update/" + method: POST + user: "{{ lookup('env', 'TOWER_USERNAME') }}" + password: "{{ lookup('env', 'TOWER_PASSWORD') }}" + validate_certs: false + status_code: 202 + force_basic_auth: true + +- name: Wait for the project to be status=successful + uri: + url: "https://{{ lookup('env', 'TOWER_HOST') }}/api/v2/projects/{{ result.id }}/" + method: GET + user: "{{ lookup('env', 'TOWER_USERNAME') }}" + password: "{{ lookup('env', 'TOWER_PASSWORD') }}" + validate_certs: false + force_basic_auth: true + return_content: true + register: result + until: result.json.status == "successful" + retries: 15 + delay: 1 + +- name: Create a Job Template + tower_job_template: + name: hello-world + project: Job Template Test Project + inventory: Demo Inventory + playbook: hello_world.yml + machine_credential: Demo Credential + job_type: run + state: present + register: result + +- assert: + that: + - "result is changed" diff --git a/test/integration/targets/tower_job_wait/aliases b/test/integration/targets/tower_job_wait/aliases new file mode 100644 index 00000000000..42b2b7300b9 --- /dev/null +++ b/test/integration/targets/tower_job_wait/aliases @@ -0,0 +1,2 @@ +cloud/tower +posix/ci/cloud/group4/tower diff --git a/test/integration/targets/tower_job_wait/tasks/main.yml b/test/integration/targets/tower_job_wait/tasks/main.yml new file mode 100644 index 00000000000..904e6a5169f --- /dev/null +++ b/test/integration/targets/tower_job_wait/tasks/main.yml @@ -0,0 +1,16 @@ +- name: Launch a Job Template + tower_job_launch: + job_template: "Demo Job Template" + inventory: "Demo Inventory" + credential: "Demo Credential" + register: job + +- assert: + that: + - "job is changed" + - "job.status == 'pending'" + +- name: Wait for the Job to finish + tower_job_wait: + job_id: "{{ job.id }}" + timeout: 60 diff --git a/test/integration/targets/tower_label/aliases b/test/integration/targets/tower_label/aliases new file mode 100644 index 00000000000..42b2b7300b9 --- /dev/null +++ b/test/integration/targets/tower_label/aliases @@ -0,0 +1,2 @@ +cloud/tower +posix/ci/cloud/group4/tower diff --git a/test/integration/targets/tower_label/tasks/main.yml b/test/integration/targets/tower_label/tasks/main.yml new file mode 100644 index 00000000000..f580c7c690b --- /dev/null +++ b/test/integration/targets/tower_label/tasks/main.yml @@ -0,0 +1,7 @@ +- name: Create a Label + tower_label: + name: important + organization: Default + state: present + +# TODO: Deleting labels doesn't seem to work currently diff --git a/test/integration/targets/tower_organization/tasks/main.yml b/test/integration/targets/tower_organization/tasks/main.yml index ac05ed5fa9b..1bc06c81167 100644 --- a/test/integration/targets/tower_organization/tasks/main.yml +++ b/test/integration/targets/tower_organization/tasks/main.yml @@ -1,3 +1,13 @@ +- name: confirm Tower version w/ check mode + tower_organization: + name: Default + check_mode: yes + register: result + +- assert: + that: + - "result.tower_version == '{{ lookup('env', 'TOWER_VERSION') }}'" + - name: Make sure the default Default organization exists tower_organization: name: Default diff --git a/test/integration/targets/tower_project/aliases b/test/integration/targets/tower_project/aliases new file mode 100644 index 00000000000..42b2b7300b9 --- /dev/null +++ b/test/integration/targets/tower_project/aliases @@ -0,0 +1,2 @@ +cloud/tower +posix/ci/cloud/group4/tower diff --git a/test/integration/targets/tower_project/tasks/main.yml b/test/integration/targets/tower_project/tasks/main.yml new file mode 100644 index 00000000000..0353977003c --- /dev/null +++ b/test/integration/targets/tower_project/tasks/main.yml @@ -0,0 +1,27 @@ +- name: Create an SCM Credential + tower_credential: + name: SCM Credential for Project + organization: Default + kind: scm + +- name: Create a Project + tower_project: + name: my-project + organization: Default + state: present + scm_credential: SCM Credential for Project + register: result + +- assert: + that: + - "result is changed" + +- name: Delete a Project + tower_project: + name: my-project + state: absent + register: result + +- assert: + that: + - "result is changed" diff --git a/test/integration/targets/tower_role/aliases b/test/integration/targets/tower_role/aliases new file mode 100644 index 00000000000..42b2b7300b9 --- /dev/null +++ b/test/integration/targets/tower_role/aliases @@ -0,0 +1,2 @@ +cloud/tower +posix/ci/cloud/group4/tower diff --git a/test/integration/targets/tower_role/tasks/main.yml b/test/integration/targets/tower_role/tasks/main.yml new file mode 100644 index 00000000000..eb1602f9b60 --- /dev/null +++ b/test/integration/targets/tower_role/tasks/main.yml @@ -0,0 +1,39 @@ +- name: Create a User + tower_user: + first_name: Joe + last_name: User + username: joe + password: "{{ 65535 | random | to_uuid }}" + email: joe@example.org + state: present + register: result + +- assert: + that: + - "result is changed" + +- name: Add Joe to the update role of the default Project + tower_role: + user: joe + role: update + project: Demo Project + state: "{{ item }}" + register: result + with_items: + - "present" + - "absent" + +- assert: + that: + - "result is changed" + +- name: Delete a User + tower_user: + username: joe + email: joe@example.org + state: absent + register: result + +- assert: + that: + - "result is changed" diff --git a/test/integration/targets/tower_team/tasks/main.yml b/test/integration/targets/tower_team/tasks/main.yml index 82ca5d9481a..40fa7e05e40 100644 --- a/test/integration/targets/tower_team/tasks/main.yml +++ b/test/integration/targets/tower_team/tasks/main.yml @@ -1,4 +1,33 @@ +- name: Attempt to add a Tower team to a non-existant Organization + tower_team: + name: Test Team + organization: Missing Organization + state: present + register: result + ignore_errors: yes + +- name: Assert a meaningful error was provided for the failed Tower team creation + assert: + that: + - "'The requested object could not be found.' in result.exception" + - name: Create a Tower team tower_team: name: Test Team organization: Default + register: result + +- assert: + that: + - "result is changed" + +- name: Delete a Tower team + tower_team: + name: Test Team + organization: Default + state: absent + register: result + +- assert: + that: + - "result is changed" diff --git a/test/integration/targets/tower_user/aliases b/test/integration/targets/tower_user/aliases new file mode 100644 index 00000000000..42b2b7300b9 --- /dev/null +++ b/test/integration/targets/tower_user/aliases @@ -0,0 +1,2 @@ +cloud/tower +posix/ci/cloud/group4/tower diff --git a/test/integration/targets/tower_user/tasks/main.yml b/test/integration/targets/tower_user/tasks/main.yml new file mode 100644 index 00000000000..05d231eb4bf --- /dev/null +++ b/test/integration/targets/tower_user/tasks/main.yml @@ -0,0 +1,76 @@ +- name: Create a User + tower_user: + first_name: Joe + last_name: User + username: joe + password: "{{ 65535 | random | to_uuid }}" + email: joe@example.org + state: present + register: result + +- assert: + that: + - "result is changed" + +- name: Delete a User + tower_user: + username: joe + email: joe@example.org + state: absent + register: result + +- assert: + that: + - "result is changed" + +- name: Create an Auditor + tower_user: + first_name: Joe + last_name: Auditor + username: joe + password: "{{ 65535 | random | to_uuid }}" + email: joe@example.org + state: present + auditor: true + register: result + +- assert: + that: + - "result is changed" + +- name: Delete an Auditor + tower_user: + username: joe + email: joe@example.org + state: absent + register: result + +- assert: + that: + - "result is changed" + +- name: Create a Superuser + tower_user: + first_name: Joe + last_name: Super + username: joe + password: "{{ 65535 | random | to_uuid }}" + email: joe@example.org + state: present + superuser: true + register: result + +- assert: + that: + - "result is changed" + +- name: Delete a Superuser + tower_user: + username: joe + email: joe@example.org + state: absent + register: result + +- assert: + that: + - "result is changed"