2017-11-17 15:19:13 +00:00
|
|
|
# Test code for the ACI modules
|
2018-02-21 18:35:59 +00:00
|
|
|
# Copyright: (c) 2017, Jacob McGill (@jmcgill298)
|
2017-11-17 15:19:13 +00:00
|
|
|
|
|
|
|
# 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 }}"
|
2018-01-20 23:38:20 +00:00
|
|
|
validate_certs: '{{ aci_validate_certs | default(false) }}'
|
|
|
|
use_ssl: '{{ aci_use_ssl | default(true) }}'
|
|
|
|
use_proxy: '{{ aci_use_proxy | default(true) }}'
|
2018-02-02 23:41:56 +00:00
|
|
|
output_level: debug
|
2017-11-17 15:19:13 +00:00
|
|
|
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
|
|
|
|
|
2018-08-07 21:54:54 +00:00
|
|
|
- name: ensure bd anstest does not exist
|
|
|
|
aci_bd:
|
|
|
|
<<: *aci_tenant_present
|
|
|
|
bd: anstest
|
|
|
|
state: absent
|
|
|
|
|
|
|
|
- name: ensure bd anstest2 does not exist
|
|
|
|
aci_bd:
|
|
|
|
<<: *aci_tenant_present
|
|
|
|
bd: anstest2
|
|
|
|
state: absent
|
|
|
|
|
2017-11-17 15:19:13 +00:00
|
|
|
- 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:
|
2018-08-07 21:54:54 +00:00
|
|
|
- bd_present_check_mode is changed
|
2018-02-02 23:41:56 +00:00
|
|
|
- 'bd_present_check_mode.sent == {"fvBD": {"attributes": {"descr": "Ansible Test", "name": "anstest"}}}'
|
2018-08-07 21:54:54 +00:00
|
|
|
- bd_present is changed
|
2018-02-02 23:41:56 +00:00
|
|
|
- bd_present.sent == bd_present_check_mode.sent
|
|
|
|
- bd_present.previous == []
|
2018-08-07 21:54:54 +00:00
|
|
|
- bd_present_idempotent is not changed
|
2018-02-02 23:41:56 +00:00
|
|
|
- bd_present_idempotent.previous != []
|
2018-08-07 21:54:54 +00:00
|
|
|
- bd_update is changed
|
2018-02-02 23:41:56 +00:00
|
|
|
- bd_update.previous != []
|
2018-08-07 21:54:54 +00:00
|
|
|
- bd_update.sent != bd_update.proposed
|
2018-02-02 23:41:56 +00:00
|
|
|
- 'bd_update.sent == {"fvBD": {"attributes": {"descr": "Ansible Test Update"}, "children": [{"fvRsCtx": {"attributes": {"tnFvCtxName": "anstest"}}}]}}'
|
|
|
|
- 'bd_present_2.sent.fvBD.attributes == {"arpFlood": "yes", "descr": "Ansible Test", "ipLearning": "no", "multiDstPktAct": "drop", "name": "anstest2",
|
2017-11-17 15:19:13 +00:00
|
|
|
"unicastRoute": "no", "unkMacUcastAct": "flood", "unkMcastAct": "opt-flood"}'
|
2018-08-07 21:54:54 +00:00
|
|
|
- bd_present_missing_param is failed
|
2018-01-20 20:40:55 +00:00
|
|
|
- 'bd_present_missing_param.msg == "state is present but all of the following are missing: tenant"'
|
2017-11-17 15:19:13 +00:00
|
|
|
|
|
|
|
- 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:
|
2018-08-07 21:54:54 +00:00
|
|
|
- query_all is not changed
|
2018-02-14 22:07:07 +00:00
|
|
|
- query_all.current | length > 1
|
|
|
|
- query_all.current.0.fvBD is defined
|
2019-02-01 15:19:35 +00:00
|
|
|
- '"rsp-subtree-class=fvRsBdToEpRet,fvRsCtx,fvRsIgmpsn,fvRsBDToNdP" in query_all.filter_string|urldecode'
|
2017-11-17 15:19:13 +00:00
|
|
|
- '"class/fvBD.json" in query_all.url'
|
2018-08-07 21:54:54 +00:00
|
|
|
- query_tenant is not changed
|
2018-02-14 22:07:07 +00:00
|
|
|
- query_tenant.current | length == 1
|
|
|
|
- query_tenant.current.0.fvTenant.children | length == 2
|
2019-02-01 15:19:35 +00:00
|
|
|
- '"rsp-subtree-class=fvRsBdToEpRet,fvBD,fvRsCtx,fvRsIgmpsn,fvRsBDToNdP" in query_tenant.filter_string|urldecode'
|
2017-11-17 15:19:13 +00:00
|
|
|
- '"tn-anstest.json" in query_tenant.url'
|
2018-08-07 21:54:54 +00:00
|
|
|
- query_bd_bd is not changed
|
2018-02-14 22:07:07 +00:00
|
|
|
- query_bd_bd.current != []
|
2019-01-03 23:38:57 +00:00
|
|
|
- '"query-target-filter=eq(fvBD.name, \"anstest\")" in query_bd_bd.filter_string|urldecode'
|
2019-02-01 15:19:35 +00:00
|
|
|
- '"rsp-subtree-class=fvRsBdToEpRet,fvRsCtx,fvRsIgmpsn,fvRsBDToNdP" in query_bd_bd.filter_string|urldecode'
|
2017-11-17 15:19:13 +00:00
|
|
|
- '"class/fvBD.json" in query_bd_bd.url'
|
2018-08-07 21:54:54 +00:00
|
|
|
- query_bd is not changed
|
2018-02-14 22:07:07 +00:00
|
|
|
- query_bd.current | length == 1
|
2018-08-07 21:54:54 +00:00
|
|
|
- query_bd.current.0.fvBD.attributes.name == "anstest"
|
2019-02-01 15:19:35 +00:00
|
|
|
- '"rsp-subtree-class=fvRsBdToEpRet,fvRsCtx,fvRsIgmpsn,fvRsBDToNdP" in query_bd.filter_string|urldecode'
|
2017-11-17 15:19:13 +00:00
|
|
|
- '"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:
|
2018-08-07 21:54:54 +00:00
|
|
|
- bd_absent_check_mode is changed
|
2017-11-17 15:19:13 +00:00
|
|
|
- bd_absent_check_mode.proposed == {}
|
2018-08-07 21:54:54 +00:00
|
|
|
- bd_absent is changed
|
2018-02-02 23:41:56 +00:00
|
|
|
- bd_absent.previous != []
|
2018-08-07 21:54:54 +00:00
|
|
|
- bd_absent_idempotent is not changed
|
2018-02-02 23:41:56 +00:00
|
|
|
- bd_absent_idempotent.previous == []
|
2018-08-07 21:54:54 +00:00
|
|
|
- bd_absent_missing_param is failed
|
2018-01-20 20:40:55 +00:00
|
|
|
- 'bd_absent_missing_param.msg == "state is absent but all of the following are missing: bd"'
|
2017-11-17 15:19:13 +00:00
|
|
|
|
|
|
|
- name: delete vrf - cleanup before ending tests
|
|
|
|
aci_vrf:
|
|
|
|
<<: *aci_vrf_present
|
|
|
|
state: absent
|
2018-08-07 21:54:54 +00:00
|
|
|
when: vrf_present is changed
|
2017-11-17 15:19:13 +00:00
|
|
|
|
|
|
|
- name: delete tenant - cleanup before ending tests
|
|
|
|
aci_tenant:
|
|
|
|
<<: *aci_tenant_present
|
|
|
|
state: absent
|
2018-08-07 21:54:54 +00:00
|
|
|
when: tenant_present is changed
|