mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
191 lines
5.9 KiB
YAML
191 lines
5.9 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: no
|
||
|
state: present
|
||
|
tenant: anstest
|
||
|
register: tenant_present
|
||
|
|
||
|
- name: ensure vrf exists for tests to kick off
|
||
|
aci_vrf: &aci_vrf_present
|
||
|
<<: *aci_tenant_present
|
||
|
vrf: anstest
|
||
|
register: vrf_present
|
||
|
|
||
|
- name: create bd - check mode works
|
||
|
aci_bd: &aci_bd_present
|
||
|
<<: *aci_tenant_present
|
||
|
bd: anstest
|
||
|
description: Ansible Test
|
||
|
check_mode: yes
|
||
|
register: bd_present_check_mode
|
||
|
|
||
|
- name: create bd - creation works
|
||
|
aci_bd:
|
||
|
<<: *aci_bd_present
|
||
|
register: bd_present
|
||
|
|
||
|
- name: create bd again - idempotency works
|
||
|
aci_bd:
|
||
|
<<: *aci_bd_present
|
||
|
register: bd_present_idempotent
|
||
|
|
||
|
- name: update bd - update works
|
||
|
aci_bd:
|
||
|
<<: *aci_bd_present
|
||
|
vrf: anstest
|
||
|
description: Ansible Test Update
|
||
|
register: bd_update
|
||
|
|
||
|
- name: create another bd - check more params
|
||
|
aci_bd:
|
||
|
<<: *aci_bd_present
|
||
|
bd: anstest2
|
||
|
ip_learning: "no"
|
||
|
l2_unknown_unicast: flood
|
||
|
l3_unknown_multicast: opt-flood
|
||
|
multi_dest: drop
|
||
|
enable_routing: "no"
|
||
|
arp_flooding: "yes"
|
||
|
register: bd_present_2
|
||
|
|
||
|
- name: create bd without all necessary params - failure message works
|
||
|
aci_bd:
|
||
|
<<: *aci_bd_present
|
||
|
tenant: "{{ fake_var | default(omit) }}"
|
||
|
ignore_errors: yes
|
||
|
register: bd_present_missing_param
|
||
|
|
||
|
- name: present asserts
|
||
|
assert:
|
||
|
that:
|
||
|
- bd_present_check_mode.changed == true
|
||
|
- 'bd_present_check_mode.config == {"fvBD": {"attributes": {"descr": "Ansible Test", "name": "anstest"}}}'
|
||
|
- bd_present.changed == true
|
||
|
- bd_present.config == bd_present_check_mode.config
|
||
|
- bd_present.existing == []
|
||
|
- bd_present_idempotent.changed == false
|
||
|
- bd_present_idempotent.existing != []
|
||
|
- bd_update.changed == true
|
||
|
- bd_update.existing != []
|
||
|
- bd_update.changed != bd_update.proposed
|
||
|
- 'bd_update.config == {"fvBD": {"attributes": {"descr": "Ansible Test Update"}, "children": [{"fvRsCtx": {"attributes": {"tnFvCtxName": "anstest"}}}]}}'
|
||
|
- 'bd_present_2.config.fvBD.attributes == {"arpFlood": "yes", "descr": "Ansible Test", "ipLearning": "no", "multiDstPktAct": "drop", "name": "anstest2",
|
||
|
"unicastRoute": "no", "unkMacUcastAct": "flood", "unkMcastAct": "opt-flood"}'
|
||
|
- bd_present_missing_param.failed == true
|
||
|
- 'bd_present_missing_param.msg == "state is present but the following are missing: tenant"'
|
||
|
|
||
|
- name: get all bd
|
||
|
aci_bd: &aci_query
|
||
|
<<: *aci_tenant_present
|
||
|
state: query
|
||
|
tenant: "{{ fake_var | default(omit) }}"
|
||
|
register: query_all
|
||
|
|
||
|
- name: get all in tenant
|
||
|
aci_bd:
|
||
|
<<: *aci_query
|
||
|
tenant: anstest
|
||
|
register: query_tenant
|
||
|
|
||
|
- name: get all with name
|
||
|
aci_bd:
|
||
|
<<: *aci_query
|
||
|
bd: anstest
|
||
|
register: query_bd_bd
|
||
|
|
||
|
- name: get bd
|
||
|
aci_bd:
|
||
|
<<: *aci_bd_present
|
||
|
state: query
|
||
|
register: query_bd
|
||
|
|
||
|
- name: query asserts
|
||
|
assert:
|
||
|
that:
|
||
|
- query_all.changed == false
|
||
|
- query_all.existing | length > 1
|
||
|
- query_all.existing.0.fvBD is defined
|
||
|
- '"rsp-subtree-class=fvRsCtx,fvRsIgmpsn,fvRsBDToNdP,fvRsBdToEpRet" in query_all.filter_string'
|
||
|
- '"class/fvBD.json" in query_all.url'
|
||
|
- query_tenant.changed == false
|
||
|
- query_tenant.existing | length == 1
|
||
|
- query_tenant.existing.0.fvTenant.children | length == 2
|
||
|
- '"rsp-subtree-class=fvRsCtx,fvRsIgmpsn,fvRsBDToNdP,fvRsBdToEpRet,fvBD" in query_tenant.filter_string'
|
||
|
- '"tn-anstest.json" in query_tenant.url'
|
||
|
- query_bd_bd.changed == false
|
||
|
- query_bd_bd.existing != []
|
||
|
- '"query-target-filter=eq(fvBD.name, \"anstest\")" in query_bd_bd.filter_string'
|
||
|
- '"rsp-subtree=full&rsp-subtree-class=fvRsCtx,fvRsIgmpsn,fvRsBDToNdP,fvRsBdToEpRet" in query_bd_bd.filter_string'
|
||
|
- '"class/fvBD.json" in query_bd_bd.url'
|
||
|
- query_bd.changed == false
|
||
|
- query_bd.existing | length == 1
|
||
|
- 'query_bd.existing.0.fvBD.attributes.name == "anstest"'
|
||
|
- '"rsp-subtree-class=fvRsCtx,fvRsIgmpsn,fvRsBDToNdP,fvRsBdToEpRet" in query_bd.filter_string'
|
||
|
- '"tn-anstest/BD-anstest.json" in query_bd.url'
|
||
|
|
||
|
- name: delete bd - check mode works
|
||
|
aci_bd: &aci_bd_absent
|
||
|
<<: *aci_bd_present
|
||
|
state: absent
|
||
|
check_mode: yes
|
||
|
register: bd_absent_check_mode
|
||
|
|
||
|
- name: delete bd - delete works
|
||
|
aci_bd:
|
||
|
<<: *aci_bd_absent
|
||
|
register: bd_absent
|
||
|
|
||
|
- name: delete bd again - idempotency works
|
||
|
aci_bd:
|
||
|
<<: *aci_bd_absent
|
||
|
register: bd_absent_idempotent
|
||
|
|
||
|
- name: delete bd - cleanup
|
||
|
aci_bd:
|
||
|
<<: *aci_bd_absent
|
||
|
name: anstest2
|
||
|
|
||
|
- name: delete bd missing param - fails properly
|
||
|
aci_bd:
|
||
|
<<: *aci_bd_absent
|
||
|
bd: "{{ fakevar | default(omit) }}"
|
||
|
ignore_errors: yes
|
||
|
register: bd_absent_missing_param
|
||
|
|
||
|
- name: asserts for deletion task
|
||
|
assert:
|
||
|
that:
|
||
|
- bd_absent_check_mode.changed == true
|
||
|
- bd_absent_check_mode.proposed == {}
|
||
|
- bd_absent.changed == true
|
||
|
- bd_absent.existing != []
|
||
|
- bd_absent_idempotent.changed == false
|
||
|
- bd_absent_idempotent.existing == []
|
||
|
- bd_absent_missing_param.failed == true
|
||
|
- 'bd_absent_missing_param.msg == "state is absent but the following are missing: bd"'
|
||
|
|
||
|
- name: delete vrf - cleanup before ending tests
|
||
|
aci_vrf:
|
||
|
<<: *aci_vrf_present
|
||
|
state: absent
|
||
|
when: vrf_present.changed == true
|
||
|
|
||
|
- name: delete tenant - cleanup before ending tests
|
||
|
aci_tenant:
|
||
|
<<: *aci_tenant_present
|
||
|
state: absent
|
||
|
when: tenant_present.changed == true
|