blob: 4d356ce8837fc11a0cc02b0653b2826ff6efef40 (
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
|
# 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 }}"
validate_certs: no
state: present
tenant: anstest
register: tenant_present
- name: create vrf - check mode works
aci_vrf: &aci_vrf_present
<<: *aci_tenant_present
vrf: anstest
description: Ansible Test
check_mode: yes
register: vrf_present_check_mode
- name: create vrf - creation works
aci_vrf:
<<: *aci_vrf_present
register: vrf_present
- name: create vrf again - idempotency works
aci_vrf:
<<: *aci_vrf_present
register: vrf_present_idempotent
- name: update vrf - update works
aci_vrf:
<<: *aci_vrf_present
description: Ansible Test Update
policy_control_preference: unenforced
register: vrf_update
- name: create another vrf - check more params
aci_vrf:
<<: *aci_vrf_present
vrf: anstest2
policy_control_direction: egress
register: vrf_present_2
- name: create vrf without all necessary params - failure message works
aci_vrf:
<<: *aci_vrf_present
tenant: "{{ fake_var | default(omit) }}"
ignore_errors: yes
register: vrf_present_missing_param
- name: present asserts
assert:
that:
- vrf_present_check_mode.changed == true
- 'vrf_present_check_mode.config == {"fvCtx": {"attributes": {"descr": "Ansible Test", "name": "anstest"}}}'
- vrf_present.changed == true
- vrf_present.config == vrf_present_check_mode.config
- vrf_present.existing == []
- vrf_present_idempotent.changed == false
- vrf_present_idempotent.existing != []
- vrf_update.changed == true
- vrf_update.existing != []
- vrf_update.changed != vrf_update.proposed
- 'vrf_update.config == {"fvCtx": {"attributes": {"descr": "Ansible Test Update", "pcEnfPref": "unenforced"}}}'
- 'vrf_present_2.config.fvCtx.attributes == {"name": "anstest2", "pcEnfDir": "egress", "descr": "Ansible Test"}'
- vrf_present_missing_param.failed == true
- 'vrf_present_missing_param.msg == "state is present but all of the following are missing: tenant"'
- name: get all vrf
aci_vrf: &aci_query
<<: *aci_tenant_present
state: query
tenant: "{{ fake_var | default(omit) }}"
register: query_all
- name: get all in tenant
aci_vrf:
<<: *aci_query
tenant: anstest
register: query_tenant
- name: get all with name
aci_vrf:
<<: *aci_query
vrf: anstest
register: query_vrf_vrf
- name: get vrf
aci_vrf:
<<: *aci_vrf_present
state: query
register: query_vrf
- name: query asserts
assert:
that:
- query_all.changed == false
- query_all.existing | length > 1
- query_all.existing.0.fvCtx is defined
- '"class/fvCtx.json" in query_all.url'
- query_tenant.changed == false
- query_tenant.existing | length == 1
- query_tenant.existing.0.fvTenant.children | length == 2
- 'query_tenant.existing.0.fvTenant.attributes.name == "anstest"'
- '"rsp-subtree-class=fvCtx" in query_tenant.filter_string'
- '"tn-anstest.json" in query_tenant.url'
- query_vrf_vrf.changed == false
- query_vrf_vrf.existing != []
- 'query_vrf_vrf.existing.0.fvCtx.attributes.name == "anstest"'
- '"query-target-filter=eq(fvCtx.name, \"anstest\")" in query_vrf_vrf.filter_string'
- '"class/fvCtx.json" in query_vrf_vrf.url'
- query_vrf.changed == false
- query_vrf.existing | length == 1
- '"tn-anstest/ctx-anstest.json" in query_vrf.url'
- name: delete vrf - check mode works
aci_vrf: &aci_vrf_absent
<<: *aci_vrf_present
state: absent
check_mode: yes
register: vrf_absent_check_mode
- name: delete vrf - delete works
aci_vrf:
<<: *aci_vrf_absent
register: vrf_absent
- name: delete vrf again - idempotency works
aci_vrf:
<<: *aci_vrf_absent
register: vrf_absent_idempotent
- name: delete vrf - cleanup
aci_vrf:
<<: *aci_vrf_absent
name: anstest2
- name: delete vrf missing param - fails properly
aci_vrf:
<<: *aci_vrf_absent
vrf: "{{ fakevar | default(omit) }}"
ignore_errors: yes
register: vrf_absent_missing_param
- name: asserts for deletion task
assert:
that:
- vrf_absent_check_mode.changed == true
- vrf_absent_check_mode.existing != []
- vrf_absent_check_mode.proposed == {}
- vrf_absent.changed == true
- vrf_absent.existing == vrf_absent_check_mode.existing
- vrf_absent_idempotent.changed == false
- vrf_absent_idempotent.existing == []
- vrf_absent_missing_param.failed == true
- 'vrf_absent_missing_param.msg == "state is absent but all of the following are missing: vrf"'
- name: delete tenant - cleanup before ending tests
aci_tenant:
<<: *aci_tenant_present
state: absent
when: tenant_present.changed == true
|