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
|
|
|
tenant: anstest
|
2018-08-06 20:42:10 +00:00
|
|
|
state: present
|
2017-11-17 15:19:13 +00:00
|
|
|
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:
|
2018-08-07 21:54:54 +00:00
|
|
|
- present_check_mode is changed
|
2018-02-02 23:41:56 +00:00
|
|
|
- present_check_mode.previous == []
|
|
|
|
- 'present_check_mode.sent == {"vzBrCP": {"attributes": {"name": "anstest", "descr": "Ansible Test"}}}'
|
2018-08-07 21:54:54 +00:00
|
|
|
- contract_present is changed
|
2018-02-02 23:41:56 +00:00
|
|
|
- contract_present.sent == present_check_mode.sent
|
2018-08-07 21:54:54 +00:00
|
|
|
- present_idempotent is not changed
|
|
|
|
- present_update is changed
|
2018-02-02 23:41:56 +00:00
|
|
|
- present_update.sent != present_update.proposed
|
2018-08-07 21:54:54 +00:00
|
|
|
- present_update.sent.vzBrCP.attributes.scope == "application-profile"
|
|
|
|
- present_missing_param is failed
|
2018-01-20 20:40:55 +00:00
|
|
|
- 'present_missing_param.msg == "state is present but all of the following are missing: contract"'
|
2017-11-17 15:19:13 +00:00
|
|
|
|
|
|
|
- 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:
|
2018-08-07 21:54:54 +00:00
|
|
|
- query_contract is not changed
|
2018-02-14 22:07:07 +00:00
|
|
|
- query_contract.current | length == 1
|
2017-11-17 15:19:13 +00:00
|
|
|
- '"tn-anstest/brc-anstest.json" in query_contract.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 > 1
|
2017-11-17 15:19:13 +00:00
|
|
|
- '"rsp-subtree-class=vzBrCP" in query_tenant.filter_string'
|
|
|
|
- '"tn-anstest.json" in query_tenant.url'
|
2018-08-07 21:54:54 +00:00
|
|
|
- query_name is not changed
|
2018-02-14 22:07:07 +00:00
|
|
|
- query_name.current != []
|
2019-01-03 23:38:57 +00:00
|
|
|
- '"query-target-filter=eq(vzBrCP.name, \"anstest\")" in query_name.filter_string|urldecode'
|
2017-11-17 15:19:13 +00:00
|
|
|
- '"class/vzBrCP.json" in query_name.url'
|
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
|
2017-11-17 15:19:13 +00:00
|
|
|
- '"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:
|
2018-08-07 21:54:54 +00:00
|
|
|
- absent_check_mode is changed
|
2018-02-02 23:41:56 +00:00
|
|
|
- absent_check_mode.previous != []
|
2018-08-07 21:54:54 +00:00
|
|
|
- contract_absent is changed
|
2018-02-02 23:41:56 +00:00
|
|
|
- contract_absent.previous == absent_check_mode.previous
|
2018-08-07 21:54:54 +00:00
|
|
|
- absent_idempotent is not changed
|
2018-02-02 23:41:56 +00:00
|
|
|
- absent_idempotent.previous == []
|
2018-08-07 21:54:54 +00:00
|
|
|
- absent_missing_param is failed
|
2018-01-20 20:40:55 +00:00
|
|
|
- 'absent_missing_param.msg == "state is absent but all of the following are missing: tenant"'
|
2017-11-17 15:19:13 +00:00
|
|
|
|
|
|
|
- name: cleanup tenant
|
|
|
|
aci_tenant:
|
|
|
|
<<: *aci_tenant_present
|
|
|
|
state: absent
|
2018-08-07 21:54:54 +00:00
|
|
|
when: tenant_present is changed
|