Files
awx/awx_collection/tests/integration/targets/group/tasks/main.yml
John Westcott IV b87ff45c07 Enhance collection test
ad_hoc_command_cancel really can no longer timeout on a cancel (it happens sub second) and remove unneeded block

Modified all test to respect test_id parameter so that all tests can be run togeather as a single ID

Fix a check in group since its group2 is deleted from being a sub group of group1

The UI now allows to propage sub groups to the inventory which we may want to support within the collection

Only run instance integration test if we are running on k8s and assume we are not by default

Fix hard coded names in manual_project
2023-04-25 13:48:37 -04:00

200 lines
4.2 KiB
YAML

---
- name: Generate a test ID
set_fact:
test_id: "{{ lookup('password', '/dev/null chars=ascii_letters length=16') }}"
when: test_id is not defined
- name: Generate names
set_fact:
group_name1: "AWX-Collection-tests-group-group1-{{ test_id }}"
group_name2: "AWX-Collection-tests-group-group2-{{ test_id }}"
group_name3: "AWX-Collection-tests-group-group3-{{ test_id }}"
inv_name: "AWX-Collection-tests-group-inv-{{ test_id }}"
host_name1: "AWX-Collection-tests-group-host1-{{ test_id }}"
host_name2: "AWX-Collection-tests-group-host2-{{ test_id }}"
host_name3: "AWX-Collection-tests-group-host3-{{ test_id }}"
- name: Create an Inventory
inventory:
name: "{{ inv_name }}"
organization: Default
state: present
register: result
- name: Create a Group
group:
name: "{{ group_name1 }}"
inventory: "{{ result.id }}"
state: present
variables:
foo: bar
register: result
- assert:
that:
- "result is changed"
- name: Create a Group
group:
name: "{{ group_name2 }}"
inventory: "{{ inv_name }}"
state: present
variables:
foo: bar
register: result
- assert:
that:
- "result is changed"
- name: Create a Group
group:
name: "{{ group_name3 }}"
inventory: "{{ inv_name }}"
state: present
variables:
foo: bar
register: result
- assert:
that:
- "result is changed"
- name: add hosts
host:
name: "{{ item }}"
inventory: "{{ inv_name }}"
loop:
- "{{ host_name1 }}"
- "{{ host_name2 }}"
- "{{ host_name3 }}"
- name: Create a Group with hosts and sub group
group:
name: "{{ group_name1 }}"
inventory: "{{ inv_name }}"
hosts:
- "{{ host_name1 }}"
- "{{ host_name2 }}"
children:
- "{{ group_name2 }}"
state: present
variables:
foo: bar
register: result
- name: Create a Group with hosts and sub group
group:
name: "{{ group_name1 }}"
inventory: "{{ inv_name }}"
hosts:
- "{{ host_name3 }}"
children:
- "{{ group_name3 }}"
state: present
preserve_existing_hosts: true
preserve_existing_children: true
register: result
- name: "Find number of hosts in {{ group_name1 }}"
set_fact:
group1_host_count: "{{ lookup('awx.awx.controller_api', 'groups/{{result.id}}/all_hosts/') |length}}"
- assert:
that:
- group1_host_count == "3"
- name: Delete a Group
group:
name: "{{ group_name1 }}"
inventory: "{{ inv_name }}"
state: absent
register: result
- assert:
that:
- "result is changed"
- name: Delete a Group
group:
name: "{{ group_name2 }}"
inventory: "{{ inv_name }}"
state: absent
register: result
# In this case, group 2 was last a child of group1 so deleting group1 deleted group2
- assert:
that:
- "result is not changed"
- name: Delete a Group
group:
name: "{{ group_name3 }}"
inventory: "{{ inv_name }}"
state: absent
register: result
- assert:
that:
- "result is not changed"
- name: Check module fails with correct msg
group:
name: test-group
description: Group Description
inventory: test-non-existing-inventory
state: present
register: result
ignore_errors: true
- assert:
that:
- "result is failed"
- "result is not changed"
- "'test-non-existing-inventory' in result.msg"
- "result.total_results == 0"
- name: add hosts
host:
name: "{{ item }}"
inventory: "{{ inv_name }}"
loop:
- "{{ host_name1 }}"
- "{{ host_name2 }}"
- "{{ host_name3 }}"
- name: add mid level group
group:
name: "{{ group_name2 }}"
inventory: "{{ inv_name }}"
hosts:
- "{{ host_name3 }}"
- name: add top group
group:
name: "{{ group_name3 }}"
inventory: "{{ inv_name }}"
hosts:
- "{{ host_name1 }}"
- "{{ host_name2 }}"
children:
- "{{ group_name2 }}"
- name: Delete the parent group
group:
name: "{{ group_name3 }}"
inventory: "{{ inv_name }}"
state: absent
- name: Delete the child group
group:
name: "{{ group_name2 }}"
inventory: "{{ inv_name }}"
state: absent
- name: Delete an Inventory
inventory:
name: "{{ inv_name }}"
organization: Default
state: absent