2017-11-17 16:19:13 +01:00
|
|
|
# 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 }}"
|
2018-01-21 00:38:20 +01:00
|
|
|
validate_certs: '{{ aci_validate_certs | default(false) }}'
|
|
|
|
use_ssl: '{{ aci_use_ssl | default(true) }}'
|
|
|
|
use_proxy: '{{ aci_use_proxy | default(true) }}'
|
2017-11-17 16:19:13 +01:00
|
|
|
state: present
|
|
|
|
tenant: anstest
|
|
|
|
register: tenant_present
|
|
|
|
|
|
|
|
- name: ensure bd exists for tests to kick off
|
|
|
|
aci_bd: &aci_bd_present
|
|
|
|
<<: *aci_tenant_present
|
|
|
|
bd: anstest
|
|
|
|
register: bd_present
|
|
|
|
|
|
|
|
- name: ensure ap exists for tests to kick off
|
|
|
|
aci_ap: &aci_ap_present
|
|
|
|
<<: *aci_tenant_present
|
|
|
|
ap: anstest
|
|
|
|
register: ap_present
|
|
|
|
|
|
|
|
- name: create epg - check mode works
|
|
|
|
aci_epg: &aci_epg_present
|
|
|
|
<<: *aci_ap_present
|
|
|
|
epg: anstest
|
|
|
|
bd: anstest
|
|
|
|
description: Ansible Test
|
|
|
|
check_mode: yes
|
|
|
|
register: epg_present_check_mode
|
|
|
|
|
|
|
|
- name: create epg - creation works
|
|
|
|
aci_epg:
|
|
|
|
<<: *aci_epg_present
|
|
|
|
register: epg_present
|
|
|
|
|
|
|
|
- name: create epg - idempotency works
|
|
|
|
aci_epg:
|
|
|
|
<<: *aci_epg_present
|
|
|
|
register: epg_present_idempotent
|
|
|
|
|
|
|
|
- name: update epg - update works
|
|
|
|
aci_epg:
|
|
|
|
<<: *aci_epg_present
|
|
|
|
description: Ansible Test Update
|
|
|
|
register: epg_present_update
|
|
|
|
|
|
|
|
- name: create epg - missing param
|
|
|
|
aci_epg:
|
|
|
|
<<: *aci_epg_present
|
|
|
|
ap: "{{ fakevar | default(omit) }}"
|
|
|
|
ignore_errors: yes
|
|
|
|
register: epg_present_missing_param
|
|
|
|
|
|
|
|
- name: create epg - used for query
|
|
|
|
aci_epg:
|
|
|
|
<<: *aci_epg_present
|
|
|
|
epg: anstest2
|
|
|
|
|
|
|
|
- name: present assertions
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- epg_present_check_mode.changed == true
|
|
|
|
- epg_present_check_mode.existing == []
|
|
|
|
- epg_present_check_mode.config.fvAEPg.attributes != {}
|
|
|
|
- 'epg_present_check_mode.config.fvAEPg.children.0.fvRsBd.attributes.tnFvBDName == "anstest"'
|
|
|
|
- epg_present.changed == true
|
|
|
|
- epg_present.config == epg_present_check_mode.config
|
|
|
|
- epg_present_idempotent.changed == false
|
|
|
|
- epg_present_idempotent.config == {}
|
|
|
|
- epg_present_update.changed == true
|
|
|
|
- 'epg_present_update.config == {"fvAEPg": {"attributes": {"descr": "Ansible Test Update"}}}'
|
|
|
|
- epg_present_missing_param.failed == true
|
2018-01-20 21:40:55 +01:00
|
|
|
- 'epg_present_missing_param.msg == "state is present but all of the following are missing: ap"'
|
2017-11-17 16:19:13 +01:00
|
|
|
|
|
|
|
- name: get specific epg
|
|
|
|
aci_epg:
|
|
|
|
<<: *aci_epg_present
|
|
|
|
state: query
|
|
|
|
register: epg_query
|
|
|
|
|
|
|
|
- name: get all epgs
|
|
|
|
aci_epg:
|
|
|
|
<<: *aci_tenant_present
|
|
|
|
state: query
|
|
|
|
tenant: "{{ fakevar | default(omit) }}"
|
|
|
|
register: epg_query_all
|
|
|
|
|
|
|
|
- name: query assertions
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- epg_query.changed == false
|
|
|
|
- epg_query.existing | length == 1
|
|
|
|
- 'epg_query.existing.0.fvAEPg.attributes.name == "anstest"'
|
|
|
|
- '"tn-anstest/ap-anstest/epg-anstest.json" in epg_query.url'
|
|
|
|
- epg_query_all.changed == false
|
|
|
|
- epg_query_all.existing | length > 1
|
|
|
|
- '"rsp-subtree-class=fvRsBd" in epg_query_all.filter_string'
|
|
|
|
- '"class/fvAEPg.json" in epg_query_all.url'
|
|
|
|
|
|
|
|
- name: delete epg - check mode works
|
|
|
|
aci_epg: &aci_epg_absent
|
|
|
|
<<: *aci_epg_present
|
|
|
|
state: absent
|
|
|
|
check_mode: yes
|
|
|
|
register: delete_epg_check_mode
|
|
|
|
|
|
|
|
- name: delete epg - delete works
|
|
|
|
aci_epg:
|
|
|
|
<<: *aci_epg_absent
|
|
|
|
register: delete_epg
|
|
|
|
|
|
|
|
- name: delete epg - idempotency works
|
|
|
|
aci_epg:
|
|
|
|
<<: *aci_epg_absent
|
|
|
|
register: delete_epg_idempotent
|
|
|
|
|
|
|
|
- name: delete epg - cleanup extra epg
|
|
|
|
aci_epg:
|
|
|
|
<<: *aci_epg_absent
|
|
|
|
epg: anstest2
|
|
|
|
|
|
|
|
- name: delete epg - missing param fails
|
|
|
|
aci_epg:
|
|
|
|
<<: *aci_epg_absent
|
|
|
|
tenant: "{{ fakevar | default(omit) }}"
|
|
|
|
ignore_errors: yes
|
|
|
|
register: delete_epg_missing_param
|
|
|
|
|
|
|
|
- name: query assertions
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- delete_epg_check_mode.changed == true
|
|
|
|
- delete_epg_check_mode.existing != []
|
|
|
|
- delete_epg.changed == true
|
|
|
|
- delete_epg.existing == delete_epg_check_mode.existing
|
|
|
|
- delete_epg_idempotent.changed == false
|
|
|
|
- delete_epg_idempotent.existing == []
|
|
|
|
- delete_epg_missing_param.failed == true
|
2018-01-20 21:40:55 +01:00
|
|
|
- 'delete_epg_missing_param.msg == "state is absent but all of the following are missing: tenant"'
|
2017-11-17 16:19:13 +01:00
|
|
|
|
|
|
|
- name: cleanup bd
|
|
|
|
aci_bd:
|
|
|
|
<<: *aci_bd_present
|
|
|
|
state: absent
|
|
|
|
when: bd_present.existing == []
|
|
|
|
|
|
|
|
- name: cleanup ap
|
|
|
|
aci_ap:
|
|
|
|
<<: *aci_ap_present
|
|
|
|
state: absent
|
|
|
|
when: ap_present.existing == []
|
|
|
|
|
|
|
|
- name: cleanup tenant
|
|
|
|
aci_tenant:
|
|
|
|
<<: *aci_tenant_present
|
|
|
|
state: absent
|
|
|
|
when: tenant_present.existing == []
|