1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00
community.general/test/integration/targets/aci_contract/tasks/main.yml
Dag Wieers bee765fa6b
ACI: Change RETURN output as discussed (#35617)
* ACI: Change result output as discussed

* Update all modules to use new aci.exit_json()

* Update output_level spec and docs

* Fix integration tests

* Small PEP8 fix

* Asorted fixes to tests and aci_rest

* More test fixes and support for ANSIBLE_DEBUG

* Fix another PEP8 issues

* Move response handling inside ACI module

* Reform of ACI error handling and error output

* Diff multiline json output

* Fix a few more tests

* Revert aci_bd tests

* Small correction

* UI change: existing->current, original->previous

* UI change: config->sent

* Update all modules with RETURN values

* Fix a few more tests

* Improve docstring and add 'raw' return value

* Fix thinko

* Fix sanity/pep8 issues

* Rewrite unit tests to comply with new design
2018-02-03 00:41:56 +01:00

163 lines
5 KiB
YAML

# Test code for the ACI modules
# Copyright 2017, Jacob McGill <jmcgill298
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
- name: Test that we have an ACI APIC host, ACI username and ACI password
fail:
msg: 'Please define the following variables: aci_hostname, aci_username and aci_password.'
when: aci_hostname is not defined or aci_username is not defined or aci_password is not defined
- name: ensure tenant exists for tests to kick off
aci_tenant: &aci_tenant_present
host: "{{ aci_hostname }}"
username: "{{ aci_username }}"
password: "{{ aci_password }}"
validate_certs: '{{ aci_validate_certs | default(false) }}'
use_ssl: '{{ aci_use_ssl | default(true) }}'
use_proxy: '{{ aci_use_proxy | default(true) }}'
output_level: debug
state: present
tenant: anstest
register: tenant_present
- name: create contract - check mode works
aci_contract: &aci_contract_present
<<: *aci_tenant_present
contract: anstest
description: Ansible Test
check_mode: yes
register: present_check_mode
- name: create contract - creation works
aci_contract:
<<: *aci_contract_present
register: contract_present
- name: create contract - idempotency works
aci_contract:
<<: *aci_contract_present
register: present_idempotent
- name: update contract - update works
aci_contract:
<<: *aci_contract_present
scope: application-profile
register: present_update
- name: create contract - used for query
aci_contract:
<<: *aci_contract_present
contract: anstest2
- name: missing param - failure message works
aci_contract:
<<: *aci_tenant_present
ignore_errors: yes
register: present_missing_param
- name: present assertions
assert:
that:
- present_check_mode.changed == true
- present_check_mode.previous == []
- 'present_check_mode.sent == {"vzBrCP": {"attributes": {"name": "anstest", "descr": "Ansible Test"}}}'
- contract_present.changed == true
- contract_present.sent == present_check_mode.sent
- present_idempotent.changed == false
- present_update.changed == true
- present_update.sent != present_update.proposed
- 'present_update.sent.vzBrCP.attributes.scope == "application-profile"'
- present_missing_param.failed == true
- 'present_missing_param.msg == "state is present but all of the following are missing: contract"'
- name: query contract
aci_contract: &aci_contract_query
<<: *aci_contract_present
state: query
register: query_contract
- name: query all in tenant
aci_contract:
<<: *aci_contract_query
contract: "{{ fakevar | default(omit) }}"
register: query_tenant
- name: query all with name
aci_contract:
<<: *aci_contract_query
tenant: "{{ fakevar | default(omit) }}"
register: query_name
- name: query all
aci_contract:
<<: *aci_contract_query
tenant: "{{ fakevar | default(omit) }}"
contract: "{{ fakevar | default(omit) }}"
register: query_all
- name: query assertions
assert:
that:
- query_contract.changed == false
- query_contract.previous | length == 1
- '"tn-anstest/brc-anstest.json" in query_contract.url'
- query_tenant.changed == false
- query_tenant.previous | length == 1
- query_tenant.previous.0.fvTenant.children | length > 1
- '"rsp-subtree-class=vzBrCP" in query_tenant.filter_string'
- '"tn-anstest.json" in query_tenant.url'
- query_name.changed == false
- query_name.previous != []
- '"query-target-filter=eq(vzBrCP.name, \"anstest\")" in query_name.filter_string'
- '"class/vzBrCP.json" in query_name.url'
- query_all.changed == false
- query_all.previous | length > 1
- '"class/vzBrCP.json" in query_all.url'
- name: delete contract - check mode works
aci_contract: &aci_contract_absent
<<: *aci_contract_present
state: absent
check_mode: yes
register: absent_check_mode
- name: delete contract - deletion works
aci_contract:
<<: *aci_contract_absent
register: contract_absent
- name: delete contract - idempotency works
aci_contract:
<<: *aci_contract_absent
register: absent_idempotent
- name: delete contract - cleanup second contract
aci_contract:
<<: *aci_contract_absent
contract: anstest2
- name: missing param - fail message works
aci_contract:
<<: *aci_contract_absent
tenant: "{{ fakevar | default(omit) }}"
ignore_errors: yes
register: absent_missing_param
- name: absent assertions
assert:
that:
- absent_check_mode.changed == true
- absent_check_mode.previous != []
- contract_absent.changed == true
- contract_absent.previous == absent_check_mode.previous
- absent_idempotent.changed == false
- absent_idempotent.previous == []
- absent_missing_param.failed == true
- 'absent_missing_param.msg == "state is absent but all of the following are missing: tenant"'
- name: cleanup tenant
aci_tenant:
<<: *aci_tenant_present
state: absent
when: tenant_present.changed == true