Fix up the collection integration tests

This commit is contained in:
Caleb Boylan 2020-02-28 13:49:55 -08:00
parent fc80cf5241
commit afbeacf499
24 changed files with 179 additions and 156 deletions

View File

@ -1,3 +1,4 @@
---
- name: create a tempdir for an SSH key
local_action: shell mktemp -d
register: tempdir
@ -105,7 +106,7 @@
kind: ssh
username: joe
ssh_key_data: "{{ ssh_key_data }}"
ignore_errors: yes
ignore_errors: true
register: result
- assert:
@ -120,7 +121,7 @@
state: present
kind: ssh
username: joe
ignore_errors: yes
ignore_errors: true
register: result
- assert:

View File

@ -4,7 +4,7 @@
description: Credential type for Test
name: test-credential-type
kind: cloud
inputs: {"fields": [{"type": "string", "id": "username", "label": "Username"}, {"secret": True, "type": "string", "id": "password", "label": "Password"}], "required": ["username", "password"]}
inputs: {"fields": [{"type": "string", "id": "username", "label": "Username"}, {"secret": true, "type": "string", "id": "password", "label": "Password"}], "required": ["username", "password"]}
injectors: {"extra_vars": {"test": "foo"}}
register: result

View File

@ -1,14 +1,4 @@
- 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: Generate an inventory name
set_fact:
inv_name: "inv-for-group-{{ lookup('password', '/dev/null chars=ascii_letters length=16') }}"
@ -24,8 +14,8 @@
name: Some Group
inventory: "{{ inv_name }}"
state: present
source: ec2
variables: "@{{ tempdir.stdout }}/vars"
variables:
foo: bar
register: result
- assert:
@ -54,4 +44,5 @@
- assert:
that:
- "result.msg =='Failed to update the group, inventory not found: The requested object could not be found.'"
- "result.msg =='Failed to update the group, inventory not found: The requested object could not be found.' or
result.msg =='The inventories test-non-existing-inventory was not found on the Tower server'"

View File

@ -1,14 +1,4 @@
- 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: Generate an inventory name
set_fact:
inv_name: "inv-for-group-{{ lookup('password', '/dev/null chars=ascii_letters length=16') }}"
@ -24,7 +14,8 @@
name: "some-host"
inventory: "{{ inv_name }}"
state: present
variables: "@{{ tempdir.stdout }}/vars"
variables:
foo: bar
register: result
- assert:
@ -53,4 +44,5 @@
- assert:
that:
- "result.msg =='Failed to update host, inventory not found: The requested object could not be found.'"
- "result.msg =='The inventories test-non-existing-inventory was not found on the Tower server' or
result.msg =='Failed to update host, inventory not found: The requested object could not be found.'"

View File

@ -1,9 +1,10 @@
---
- name: Clean up any pre-existing test Inventory
tower_inventory:
name: my-inventory
organization: Default
state: absent
ignore_errors: True
ignore_errors: true
- name: Create an Inventory
@ -34,7 +35,7 @@
organization: Default
kind: smart
register: result
ignore_errors: True
ignore_errors: true
- assert:
that:

View File

@ -14,8 +14,8 @@
- name: Add a Tower inventory
tower_inventory:
description: Test inventory
name: openstack-test-inventory
organization: Default
name: openstack-test-inventory
- name: Create a source inventory
tower_inventory_source:
@ -23,12 +23,27 @@
description: Source for Test inventory
inventory: openstack-test-inventory
credential: openstack-test-credential
overwrite: True
update_on_launch: True
source_vars: "---\nprivate: false"
overwrite: true
update_on_launch: true
source_vars:
private: false
source: openstack
register: result
- assert:
that:
- "result is changed"
- name: Delete the source inventory
tower_inventory_source:
name: "{{ result.name }}"
description: Source for Test inventory
inventory: openstack-test-inventory
credential: openstack-test-credential
overwrite: true
update_on_launch: true
source_vars:
private: false
source: openstack
state: absent
ignore_errors: true

View File

@ -1,3 +1,4 @@
---
- name: Launch a Job Template
tower_job_launch:
job_template: "Demo Job Template"
@ -19,9 +20,9 @@
- name: Cancel an already canceled job (assert failure)
tower_job_cancel:
job_id: "{{ job.id }}"
fail_if_not_running: True
fail_if_not_running: true
register: results
ignore_errors: True
ignore_errors: true
- assert:
that:

View File

@ -1,3 +1,4 @@
---
- name: Launch a Job Template
tower_job_launch:
job_template: "Demo Job Template"
@ -22,9 +23,9 @@
- name: Check module fails with correct msg
tower_job_launch:
job_template: "Non Existing Job Template"
inventory: "Test Inventory"
credential: "Test Credential"
job_template: "Non Existing Job Template"
inventory: "Test Inventory"
credential: "Test Credential"
register: result
ignore_errors: true
@ -39,8 +40,8 @@
project: Demo Project
playbook: hello_world.yml
job_type: run
ask_credential: yes
ask_inventory: yes
ask_credential: true
ask_inventory: true
state: present
register: result
@ -86,7 +87,7 @@
- name: Get the job
tower_job_list:
query: {"id": "{{result.id}}" }
query: {"id": "{{result.id}}"}
register: result
- assert:
@ -98,4 +99,4 @@
name: "Demo Job Template - extra_vars"
organization: Default
state: absent
ignore_errors: True
ignore_errors: true

View File

@ -1,3 +1,4 @@
---
- name: Launch a Job Template
tower_job_launch:
job_template: "Demo Job Template"
@ -29,7 +30,7 @@
- name: Get ALL result pages!
tower_job_list:
all_pages: True
all_pages: true
register: all_page_query
- assert:

View File

@ -1,3 +1,4 @@
---
- name: Create an SCM Credential
tower_credential:
name: SCM Credential for JT
@ -14,20 +15,6 @@
scm_credential: SCM Credential for JT
register: result
- name: Wait for the project to be status=successful
uri:
url: "{{ 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.summary_fields.last_update is defined and result.json.summary_fields.last_update.status == "successful"
retries: 60
delay: 1
- name: Create a Job Template
tower_job_template:
name: "hello-world {{ lookup('password', '/dev/null chars=ascii_letters length=16') }}"

View File

@ -1,3 +1,4 @@
---
- name: Launch a Job Template
tower_job_launch:
job_template: "Demo Job Template"

View File

@ -1,3 +1,4 @@
---
- name: Create a Label
tower_label:
name: important

View File

@ -1,3 +1,4 @@
---
- name: Create Slack notification
tower_notification:
name: notification1
@ -64,8 +65,8 @@
- user1@example.com
host: smtp.example.com
port: 25
use_tls: no
use_ssl: no
use_tls: false
use_ssl: false
state: present
register: result
@ -153,7 +154,7 @@
color: red
rooms:
- room-A
notify: yes
notify: true
state: present
register: result
@ -184,7 +185,7 @@
- user1
port: 8080
server: irc.example.com
use_ssl: no
use_ssl: false
state: present
register: result

View File

@ -1,6 +1,7 @@
---
- name: Generate an org name
set_fact:
org_name: "org-{{ lookup('randstr') }}"
org_name: "org-{{ lookup('password', '/dev/null chars=ascii_letters length=16') }}"
- name: Make sure {{ org_name }} is not there
tower_organization:
@ -30,7 +31,7 @@
name: "{{ org_name }}"
custom_virtualenv: "/does/not/exit"
register: result
ignore_errors: True
ignore_errors: true
- assert:
that:
@ -90,9 +91,9 @@
- name: Check that SSL is available and verify_ssl is enabled (task must fail)
tower_organization:
name: Default
validate_certs: true
environment:
TOWER_CERTIFICATE: /dev/null # force check failure
TOWER_VERIFY_SSL: True
ignore_errors: true
register: check_ssl_is_used
@ -101,22 +102,9 @@
that:
- check_ssl_is_used is failed
- name: Disable verify_ssl in ~/.tower_cli.cfg
copy:
dest: ~/.tower_cli.cfg
content: |
[general]
verify_ssl = False
force: false # ensure remote file doesn't exist
- block:
- name: Check that verify_ssl is disabled (task must not fail)
tower_organization:
name: Default
environment:
TOWER_CERTIFICATE: /dev/null # should not fail because verify_ssl is disabled
always:
- name: Delete ~/.tower_cli.cfg
file:
path: ~/.tower_cli.cfg
state: absent
- name: Check that verify_ssl is disabled (task must not fail)
tower_organization:
name: Default
validate_certs: false
environment:
TOWER_CERTIFICATE: /dev/null # should not fail because verify_ssl is disabled

View File

@ -1,95 +1,115 @@
---
- name: Delete old git project from any previous test runs
tower_project:
name: "git project"
organization: Default
state: absent
ignore_errors: true
- name: Create an SCM Credential
tower_credential:
name: SCM Credential for Project
organization: Default
kind: scm
- name: Create a Project
- name: Create a git project without credentials without waiting
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"
- name: Create a git project without credentials
tower_project:
name: git project
name: "git project"
organization: Default
scm_type: git
scm_url: https://github.com/ansible/ansible
scm_url: https://github.com/ansible/test-playbooks
wait: false
register: result
- name: "Create {{ item }}"
- assert:
that:
- result is changed
- name: Recreate the project to validate not changed
tower_project:
name: "git project"
organization: Default
scm_type: git
scm_url: https://github.com/ansible/test-playbooks
wait: true
register: result
- assert:
that:
- result is not changed
- name: Create organizations
tower_organization:
name: "{{ item }}"
loop:
- TestOrg1
- TestOrg2
name: TestOrg
- name: "Create credential"
- name: Create credential
tower_credential:
kind: scm
name: TestCred1
organization: "{{ item }}"
loop:
- TestOrg2
- TestOrg1
name: TestCred
organization: TestOrg
register: new_credentials
- name: Generate random project name appender
set_fact:
project_name_rand: "{{ lookup('password', '/dev/null chars=ascii_letters length=16') }}"
- name: Create project TestProject
- name: Create a new test project in check_mode
tower_project:
name: "TestProject {{ project_name_rand }}"
organization: TestOrg1
organization: TestOrg
scm_type: git
scm_url: "https://github.com/ansible/ansible"
scm_credential: TestCred1
register: multi_org_cred_project
scm_url: https://github.com/ansible/test-playbooks
scm_credential: TestCred
check_mode: true
- name: Create a new test project
tower_project:
name: "TestProject {{ project_name_rand }}"
organization: TestOrg
scm_type: git
scm_url: https://github.com/ansible/test-playbooks
scm_credential: TestCred
register: result
# 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
- assert:
that:
- "multi_org_cred_project is changed"
- "result is changed"
- name: Check module fails with correct msg
- name: Check module fails with correct msg when given non-existing org as param
tower_project:
name: "TestProject {{ project_name_rand }}"
organization: Non Existing Org
scm_type: git
scm_url: "https://github.com/ansible/ansible"
scm_credential: TestCred1
scm_url: https://github.com/ansible/test-playbooks
scm_credential: TestCred
register: result
ignore_errors: true
- assert:
that:
- "result.msg == 'Failed to update project, organization not found: Non Existing Org'"
- "result.msg == 'The organizations Non Existing Org was not found on the Tower server' or
result.msg == 'Failed to update project, organization not found: Non Existing Org'"
- name: Check module fails with correct msg
- name: Check module fails with correct msg when given non-existing credential as param
tower_project:
name: "TestProject {{ project_name_rand }}"
organization: TestOrg1
organization: TestOrg
scm_type: git
scm_url: "https://github.com/ansible/ansible"
scm_url: https://github.com/ansible/test-playbooks
scm_credential: Non Existing Credential
register: result
ignore_errors: true
- assert:
that:
- "result.msg =='Failed to update project, credential not found: Non Existing Credential'"
- "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: Delete the test project
tower_project:
name: "TestProject {{ project_name_rand }}"
organization: TestOrg
state: absent

View File

@ -1,8 +1,21 @@
---
- name: get tower host variable
shell: tower-cli config host | cut -d ' ' -f2
register: host
- name: get tower username variable
shell: tower-cli config username | cut -d ' ' -f2
register: username
- name: get tower password variable
shell: tower-cli config password | cut -d ' ' -f2
register: password
- name: Fetch project_base_dir
uri:
url: "{{ lookup('env', 'TOWER_HOST') }}/api/v2/config/"
user: "{{ lookup('env', 'TOWER_USERNAME') }}"
password: "{{ lookup('env', 'TOWER_PASSWORD') }}"
url: "{{ host.stdout }}/api/v2/config/"
user: "{{ username.stdout }}"
password: "{{ password.stdout }}"
validate_certs: false
return_content: true
force_basic_auth: true
@ -38,8 +51,8 @@
vars:
project_base_dir: "{{ awx_config.json.project_base_dir }}"
command: tower-cli ad_hoc launch --wait --inventory localhost
--credential dummy --module-name shell
--module-args "mkdir -p {{ project_base_dir }}/{{ project_dir_name }} || true"
--credential dummy --module-name command
--module-args "mkdir -p {{ project_base_dir }}/{{ project_dir_name }}"
always:
- name: enable bubblewrap
command: tower-cli setting modify AWX_PROOT_ENABLED true

View File

@ -1,10 +1,14 @@
---
- name: generate random string for project
set_fact:
rand_string: "{{ lookup('password', '/dev/null chars=ascii_letters length=16') }}"
- name: Generate manual project dir name
set_fact:
project_name: "manual project {{ lookup('password', '/dev/null chars=ascii_letters length=16') }}"
project_name: "manual project {{ rand_string }}"
- name: Generate manual project dir name
set_fact:
project_dir_name: "proj {{ lookup('password', '/dev/null chars=ascii_letters length=16') }}"
project_dir_name: "proj_{{ rand_string }}"
- name: create a project directory for manual project
import_tasks: create_project_dir.yml
@ -24,6 +28,7 @@
- name: Delete a manual project
tower_project:
name: "{{ project_name }}"
organization: Default
state: absent
register: result

View File

@ -1,6 +1,7 @@
---
- name: Export all Tower assets
tower_receive:
all: True
all: true
register: result
- assert:

View File

@ -1,3 +1,4 @@
---
- name: Create a User
tower_user:
first_name: Joe

View File

@ -1,7 +1,8 @@
---
- name: Test no parameters
tower_send:
register: result
ignore_errors: yes
ignore_errors: true
- assert:
that:

View File

@ -1,3 +1,4 @@
---
- name: Set the value of AWX_PROOT_SHOW_PATHS to a baseline
tower_settings:
name: AWX_PROOT_SHOW_PATHS
@ -10,7 +11,7 @@
'not': 'a valid'
'tower': 'setting'
register: result
ignore_errors: True
ignore_errors: true
- assert:
that:
@ -51,10 +52,9 @@
- name: Apply multiple setting via settings with no change
tower_settings:
name: AWX_PROOT_BASE_PATH
value: /tmp
name: AWX_PROOT_SHOW_PATHS
value: '["/var/lib/awx/projects/", "/var/tmp"]'
settings:
AWX_PROOT_BASE_PATH: /tmp
AWX_PROOT_SHOW_PATHS: ["/var/lib/awx/projects/", "/var/tmp"]
register: result
- debug:
@ -66,10 +66,9 @@
- name: Apply multiple setting via settings with change
tower_settings:
name: AWX_PROOT_BASE_PATH
value: /tmp
name: AWX_PROOT_SHOW_PATHS
value: '["/var/lib/awx/new_projects/", "/tmp"]'
settings:
AWX_PROOT_BASE_PATH: /tmp
AWX_PROOT_SHOW_PATHS: []
register: result
- assert:

View File

@ -1,10 +1,11 @@
---
- 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
ignore_errors: true
- name: Assert a meaningful error was provided for the failed Tower team creation
assert:

View File

@ -1,3 +1,4 @@
---
- name: Create a User
tower_user:
first_name: Joe

View File

@ -44,7 +44,7 @@
credential: Demo Credential
job_type: run
state: present
survey_enabled: yes
survey_enabled: true
survey_spec: '{"spec": [{"index": 0, "question_name": "my question?", "default": "mydef", "variable": "myvar", "type": "text", "required": false}], "description": "test", "name": "test"}'