blob: a31151c372e300dee23532d9be1302e9eb1f993b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
|
# Test code for the ACI modules
# Copyright: (c) 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 }}"
validate_certs: '{{ aci_validate_certs | default(false) }}'
use_ssl: '{{ aci_use_ssl | default(true) }}'
use_proxy: '{{ aci_use_proxy | default(true) }}'
output_level: debug
state: present
tenant: anstest
register: tenant_present
- name: ensure ap does not exist initially
aci_ap:
<<: *aci_tenant_present
ap: anstest
state: absent
- name: create ap - check mode works
aci_ap: &aci_ap_present
<<: *aci_tenant_present
ap: anstest
description: Ansible Test
check_mode: yes
register: ap_present_check_mode
- name: create ap - creation works
aci_ap:
<<: *aci_ap_present
register: ap_present
- name: create ap - extra for query
aci_ap:
<<: *aci_tenant_present
ap: anstest2
- name: create ap - idempotency works
aci_ap:
<<: *aci_ap_present
register: ap_present_idempotent
- name: update ap - update works
aci_ap:
<<: *aci_ap_present
description: Ansible Test Update
register: ap_present_update
- name: create ap - creation works
aci_ap:
<<: *aci_tenant_present
ignore_errors: yes
register: ap_present_missing_param
- name: present asserts
assert:
that:
- ap_present_check_mode is changed
- ap_present is changed
- ap_present.previous == []
- ap_present.sent == ap_present_check_mode.sent
- 'ap_present.sent == {"fvAp": {"attributes": {"descr": "Ansible Test", "name": "anstest"}}}'
- ap_present_idempotent is not changed
- ap_present_idempotent.previous != []
- ap_present_idempotent.sent == {}
- ap_present_update is changed
- 'ap_present_update.sent.fvAp.attributes == {"descr": "Ansible Test Update"}'
- ap_present_missing_param is failed
- 'ap_present_missing_param.msg == "state is present but all of the following are missing: ap"'
- name: get ap - query specific ap
aci_ap: &aci_ap_query
<<: *aci_ap_present
state: query
register: query_ap
- name: get all ap for tenant - query tenant aps
aci_ap:
<<: *aci_ap_query
ap: "{{ fakevar | default(omit) }}"
register: query_ap_tenant
- name: get all ap by name - query ap name
aci_ap:
<<: *aci_ap_query
tenant: "{{ fakevar | default(omit) }}"
register: query_ap_ap
- name: get all aps - query general
aci_ap:
<<: *aci_ap_query
tenant: "{{ fakevar | default(omit) }}"
ap: "{{ fakevar | default(omit) }}"
register: query_all
- name: query assertions
assert:
that:
- query_ap is not changed
- query_ap.current | length == 1
- query_ap.current.0.fvAp.attributes.name == "anstest"
- '"tn-anstest/ap-anstest.json" in query_ap.url'
- query_ap_tenant is not changed
- query_ap_tenant.current | length == 1
- query_ap_tenant.current.0.fvTenant.children | length == 2
- '"rsp-subtree-class=fvAp" in query_ap_tenant.filter_string'
- '"tn-anstest.json" in query_ap_tenant.url'
- query_ap_ap is not changed
- query_ap_ap.current != []
- query_ap_ap.current.0.fvAp is defined
- '"query-target-filter=eq(fvAp.name, \"anstest\")" in query_ap_ap.filter_string'
- '"class/fvAp.json" in query_ap_ap.url'
- query_all is not changed
- query_all.current | length > 1
- '"class/fvAp.json" in query_all.url'
- name: delete ap - check_mode works
aci_ap: &aci_ap_absent
<<: *aci_ap_present
state: absent
check_mode: yes
register: ap_delete_check_mode
- name: delete ap - delete works
aci_ap:
<<: *aci_ap_absent
register: ap_delete
- name: delete ap - delete idempotency works
aci_ap:
<<: *aci_ap_absent
register: ap_delete_idempotent
- name: delete ap - missing param error
aci_ap:
<<: *aci_ap_absent
tenant: "{{ fakevar | default(omit) }}"
ignore_errors: yes
register: ap_delete_missing_param
- name: delete ap remove ap used for query
aci_ap:
<<: *aci_ap_absent
ap: anstest2
- name: absent assertions
assert:
that:
- ap_delete_check_mode is changed
- ap_delete_check_mode.previous != []
- '"tn-anstest/ap-anstest.json" in ap_delete_check_mode.url'
- ap_delete is changed
- ap_delete.previous == ap_delete_check_mode.previous
- ap_delete_idempotent is not changed
- ap_delete_idempotent.previous == []
- ap_delete_missing_param is failed
- 'ap_delete_missing_param.msg == "state is absent but all of the following are missing: tenant"'
- name: delete tenant - cleanup before ending tests
aci_tenant:
<<: *aci_tenant_present
state: absent
when: tenant_present is changed
|