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, Dag Wieers (@dagwieers) <dag@wieers.com>
|
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: create a snapshot - creation works
|
|
|
|
aci_config_snapshot: &create_snapshot
|
2018-01-22 21:06:56 +00:00
|
|
|
host: "{{ aci_hostname }}"
|
2017-11-17 15:19:13 +00:00
|
|
|
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
|
|
|
export_policy: anstest
|
|
|
|
max_count: 10
|
|
|
|
include_secure: no
|
|
|
|
format: json
|
|
|
|
description: ansible test
|
|
|
|
register: create
|
|
|
|
|
|
|
|
- name: update snapshot to include secure and use xml - update works
|
|
|
|
aci_config_snapshot:
|
|
|
|
<<: *create_snapshot
|
2018-02-02 23:41:56 +00:00
|
|
|
include_secure: yes
|
2017-11-17 15:19:13 +00:00
|
|
|
format: xml
|
|
|
|
register: create_update
|
|
|
|
|
|
|
|
- name: create a snapshot invalid max_count - error message
|
|
|
|
aci_config_snapshot:
|
|
|
|
<<: *create_snapshot
|
|
|
|
max_count: 11
|
|
|
|
ignore_errors: yes
|
|
|
|
register: invalid_max_count
|
|
|
|
|
|
|
|
- name: create a snapshot invalid max_count - error message
|
|
|
|
aci_config_snapshot:
|
|
|
|
<<: *create_snapshot
|
|
|
|
export_policy: "{{ fake_var | default(omit) }}"
|
|
|
|
ignore_errors: yes
|
|
|
|
register: missing_param
|
|
|
|
|
|
|
|
- name: present assertion tests
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- create.failed == false
|
|
|
|
- create.changed == true
|
2018-02-02 23:41:56 +00:00
|
|
|
- 'create.sent.configExportP.attributes.adminSt == "triggered"'
|
2017-11-17 15:19:13 +00:00
|
|
|
- create_update.failed == false
|
|
|
|
- create_update.changed == true
|
2018-02-02 23:41:56 +00:00
|
|
|
- 'create_update.sent == {"configExportP": {"attributes": {"adminSt": "triggered", "format": "xml", "includeSecureFields": "yes"}}}'
|
2017-11-17 15:19:13 +00:00
|
|
|
- invalid_max_count.failed == true
|
2018-02-02 23:41:56 +00:00
|
|
|
- invalid_max_count.msg == "Parameter 'max_count' must be a number between 1 and 10"
|
2017-11-17 15:19:13 +00:00
|
|
|
- missing_param.failed == true
|
2018-01-20 20:40:55 +00:00
|
|
|
- 'missing_param.msg == "state is present but all of the following are missing: export_policy"'
|
2017-11-17 15:19:13 +00:00
|
|
|
|
|
|
|
- name: query with export_policy
|
|
|
|
aci_config_snapshot: &query_snapshot
|
|
|
|
<<: *create_snapshot
|
|
|
|
state: query
|
|
|
|
register: query_export
|
|
|
|
|
|
|
|
- name: generate snapshot name
|
|
|
|
set_fact:
|
2018-02-14 22:07:07 +00:00
|
|
|
test_snapshot: "{{ query_export.current.0.configSnapshotCont.children.0.configSnapshot.attributes.rn.strip('snapshot-') }}"
|
2017-11-17 15:19:13 +00:00
|
|
|
|
|
|
|
- name: query with export_policy and snapshot
|
|
|
|
aci_config_snapshot: &query_both
|
|
|
|
<<: *query_snapshot
|
|
|
|
snapshot: "{{ test_snapshot }}"
|
|
|
|
register: query_export_snapshot
|
|
|
|
|
|
|
|
- name: query with snapshot - module add run- to snapshot
|
|
|
|
aci_config_snapshot:
|
|
|
|
<<: *query_snapshot
|
|
|
|
export_policy: "{{ fake_var | default(omit) }}"
|
|
|
|
snapshot: "{{ test_snapshot.strip('run-') }}"
|
|
|
|
register: query_snapshot
|
|
|
|
|
|
|
|
- name: query no params
|
|
|
|
aci_config_snapshot:
|
|
|
|
<<: *query_snapshot
|
|
|
|
export_policy: "{{ fake_var | default(omit) }}"
|
|
|
|
register: query_all
|
|
|
|
|
|
|
|
- name: query assertion tests
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- query_export.failed == false
|
|
|
|
- query_export.changed == false
|
|
|
|
- '"snapshots-[uni/fabric/configexp-anstest].json" in query_export.url'
|
2018-02-14 22:07:07 +00:00
|
|
|
- query_export.current.0.configSnapshotCont.attributes.name == "anstest"
|
|
|
|
- query_export.current.0.configSnapshotCont.children | length > 1
|
2017-11-17 15:19:13 +00:00
|
|
|
- query_export_snapshot.failed == false
|
|
|
|
- query_export_snapshot.changed == false
|
|
|
|
- '"snapshots-[uni/fabric/configexp-anstest]/snapshot-{{ test_snapshot }}.json" in query_export_snapshot.url'
|
2018-02-14 22:07:07 +00:00
|
|
|
- query_export_snapshot.current | length == 1
|
2017-11-17 15:19:13 +00:00
|
|
|
- query_snapshot.failed == false
|
|
|
|
- query_snapshot.changed == false
|
|
|
|
- '"class/configSnapshot.json" in query_snapshot.url'
|
|
|
|
- '"configSnapshot.name, \"{{ test_snapshot }}\"" in query_snapshot.filter_string'
|
|
|
|
- query_all.failed == false
|
|
|
|
- query_all.changed == false
|
|
|
|
- '"class/configSnapshot.json" in query_all.url'
|
2018-02-14 22:07:07 +00:00
|
|
|
- query_all.current | length > 1
|
2017-11-17 15:19:13 +00:00
|
|
|
|
|
|
|
- name: delete works
|
|
|
|
aci_config_snapshot: &delete
|
|
|
|
<<: *query_both
|
|
|
|
state: absent
|
|
|
|
register: delete_snapshot
|
|
|
|
|
|
|
|
- name: delete works - idempotency
|
|
|
|
aci_config_snapshot:
|
|
|
|
<<: *delete
|
|
|
|
register: delete_idempotent
|
|
|
|
|
|
|
|
- name: delete missing param
|
|
|
|
aci_config_snapshot:
|
|
|
|
<<: *delete
|
|
|
|
snapshot: "{{ fake_var | default(omit) }}"
|
|
|
|
ignore_errors: yes
|
|
|
|
register: delete_missing_param
|
|
|
|
|
|
|
|
- name: absent assertion tests
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- delete_snapshot.failed == false
|
|
|
|
- delete_snapshot.changed == true
|
2018-02-02 23:41:56 +00:00
|
|
|
- 'delete_snapshot.sent == {"configSnapshot": {"attributes": {"retire": "yes"}}}'
|
|
|
|
- delete_snapshot.previous != []
|
|
|
|
- delete_snapshot.previous.0.configSnapshot.attributes.name == test_snapshot
|
2017-11-17 15:19:13 +00:00
|
|
|
- delete_idempotent.failed == false
|
|
|
|
- delete_idempotent.changed == false
|
2018-02-02 23:41:56 +00:00
|
|
|
- delete_idempotent.previous == []
|
2017-11-17 15:19:13 +00:00
|
|
|
- delete_missing_param.failed == true
|
2018-01-20 20:40:55 +00:00
|
|
|
- 'delete_missing_param.msg == "state is absent but all of the following are missing: snapshot"'
|