ansible/test/integration/targets/aci_config_snapshot/tasks/main.yml
Dag Wieers bee765fa6b
ACI: Change RETURN output as discussed (#35617)
* ACI: Change result output as discussed

* Update all modules to use new aci.exit_json()

* Update output_level spec and docs

* Fix integration tests

* Small PEP8 fix

* Asorted fixes to tests and aci_rest

* More test fixes and support for ANSIBLE_DEBUG

* Fix another PEP8 issues

* Move response handling inside ACI module

* Reform of ACI error handling and error output

* Diff multiline json output

* Fix a few more tests

* Revert aci_bd tests

* Small correction

* UI change: existing->current, original->previous

* UI change: config->sent

* Update all modules with RETURN values

* Fix a few more tests

* Improve docstring and add 'raw' return value

* Fix thinko

* Fix sanity/pep8 issues

* Rewrite unit tests to comply with new design
2018-02-03 00:41:56 +01:00

142 lines
5 KiB
YAML

# Test code for the ACI modules
# Copyright 2017, Dag Wieers <dag@wieers.com>
# 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
host: "{{ aci_hostname }}"
username: "{{ aci_username }}"
password: "{{ aci_password }}"
validate_certs: '{{ aci_validate_certs | default(false) }}'
use_ssl: '{{ aci_use_ssl | default(true) }}'
use_proxy: '{{ aci_use_proxy | default(true) }}'
output_level: debug
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
include_secure: yes
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
- 'create.sent.configExportP.attributes.adminSt == "triggered"'
- create_update.failed == false
- create_update.changed == true
- 'create_update.sent == {"configExportP": {"attributes": {"adminSt": "triggered", "format": "xml", "includeSecureFields": "yes"}}}'
- invalid_max_count.failed == true
- invalid_max_count.msg == "Parameter 'max_count' must be a number between 1 and 10"
- missing_param.failed == true
- 'missing_param.msg == "state is present but all of the following are missing: export_policy"'
- name: query with export_policy
aci_config_snapshot: &query_snapshot
<<: *create_snapshot
state: query
register: query_export
- name: generate snapshot name
set_fact:
test_snapshot: "{{ query_export.previous.0.configSnapshotCont.children.0.configSnapshot.attributes.rn.strip('snapshot-') }}"
- 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'
- query_export.previous.0.configSnapshotCont.attributes.name == "anstest"
- query_export.previous.0.configSnapshotCont.children | length > 1
- query_export_snapshot.failed == false
- query_export_snapshot.changed == false
- '"snapshots-[uni/fabric/configexp-anstest]/snapshot-{{ test_snapshot }}.json" in query_export_snapshot.url'
- query_export_snapshot.previous | length == 1
- 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'
- query_all.previous | length > 1
- 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
- 'delete_snapshot.sent == {"configSnapshot": {"attributes": {"retire": "yes"}}}'
- delete_snapshot.previous != []
- delete_snapshot.previous.0.configSnapshot.attributes.name == test_snapshot
- delete_idempotent.failed == false
- delete_idempotent.changed == false
- delete_idempotent.previous == []
- delete_missing_param.failed == true
- 'delete_missing_param.msg == "state is absent but all of the following are missing: snapshot"'