1# Test code for the ACI modules
2# Copyright: (c) 2018, Dag Wieers (@dagwieers) <dag@wieers.com>
3
4# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
5
6
7# CLEAN ENVIRONMENT
8- name: Remove L3 domain
9  aci_domain: &domain_absent
10    host: "{{ aci_hostname }}"
11    username: "{{ aci_username }}"
12    password: "{{ aci_password }}"
13    validate_certs: '{{ aci_validate_certs | default(false) }}'
14    use_ssl: '{{ aci_use_ssl | default(true) }}'
15    use_proxy: '{{ aci_use_proxy | default(true) }}'
16    output_level: '{{ aci_output_level | default("info") }}'
17    domain: l3_dom
18    domain_type: l3dom
19    state: absent
20
21
22# ADD DOMAIN
23- name: Add L3 domain (check_mode)
24  aci_domain: &domain_present
25    host: '{{ aci_hostname }}'
26    username: '{{ aci_username }}'
27    password: '{{ aci_password }}'
28    validate_certs: '{{ aci_validate_certs | default(false) }}'
29    use_ssl: '{{ aci_use_ssl | default(true) }}'
30    use_proxy: '{{ aci_use_proxy | default(true) }}'
31    output_level: '{{ aci_output_level | default("info") }}'
32    domain: l3_dom
33    domain_type: l3dom
34    state: present
35  check_mode: yes
36  register: cm_add_domain
37
38- name: Add L3 domain (normal mode)
39  aci_domain: *domain_present
40  register: nm_add_domain
41
42- name: Verify add_domain
43  assert:
44    that:
45    - cm_add_domain is changed
46    - nm_add_domain is changed
47    - 'cm_add_domain.sent == nm_add_domain.sent == {"l3extDomP": {"attributes": {"name": "l3_dom"}}}'
48    - 'cm_add_domain.proposed == nm_add_domain.proposed == {"l3extDomP": {"attributes": {"name": "l3_dom"}}}'
49    - cm_add_domain.current == cm_add_domain.previous == nm_add_domain.previous == []
50    - 'nm_add_domain.current == [{"l3extDomP": {"attributes": {"dn": "uni/l3dom-l3_dom", "name": "l3_dom", "nameAlias": "", "ownerKey": "", "ownerTag": ""}}}]'
51
52- name: Add L3 domain again (check_mode)
53  aci_domain: *domain_present
54  check_mode: yes
55  register: cm_add_domain_again
56
57- name: Add L3 domain again (normal mode)
58  aci_domain: *domain_present
59  register: nm_add_domain_again
60
61- name: Verify add_domain_again
62  assert:
63    that:
64    - cm_add_domain_again is not changed
65    - nm_add_domain_again is not changed
66
67
68# QUERY ALL DOMAINS
69- name: Query all L3 domains (check_mode)
70  aci_domain: &domain_query
71    host: '{{ aci_hostname }}'
72    username: '{{ aci_username }}'
73    password: '{{ aci_password }}'
74    validate_certs: '{{ aci_validate_certs | default(false) }}'
75    use_ssl: '{{ aci_use_ssl | default(true) }}'
76    use_proxy: '{{ aci_use_proxy | default(true) }}'
77    output_level: '{{ aci_output_level | default("info") }}'
78    domain_type: l3dom
79    state: query
80  check_mode: yes
81  register: cm_query_all_domains
82
83- name: Query all L3 domains (normal mode)
84  aci_domain: *domain_query
85  register: nm_query_all_domains
86
87- name: Verify query_all_domains
88  assert:
89    that:
90    - cm_query_all_domains is not changed
91    - nm_query_all_domains is not changed
92    - cm_query_all_domains == nm_query_all_domains
93    - nm_query_all_domains.current|length >= 1
94
95
96# QUERY A DOMAIN
97- name: Query our L3 domain (check_mode)
98  aci_domain:
99    <<: *domain_query
100    domain: l3_dom
101  check_mode: yes
102  register: cm_query_domain
103
104- name: Query our L3 domain (normal mode)
105  aci_domain:
106    <<: *domain_query
107    domain: l3_dom
108  register: nm_query_domain
109
110- name: Verify query_domain
111  assert:
112    that:
113    - cm_query_domain is not changed
114    - nm_query_domain is not changed
115    - cm_query_domain == nm_query_domain
116    - nm_query_domain.current.0.l3extDomP.attributes.dn == 'uni/l3dom-l3_dom'
117    - nm_query_domain.current.0.l3extDomP.attributes.name == 'l3_dom'
118
119
120# REMOVE DOMAIN
121- name: Remove L3 domain (check_mode)
122  aci_domain: *domain_absent
123  check_mode: yes
124  register: cm_remove_domain
125
126- name: Remove L3 domain (normal mode)
127  aci_domain: *domain_absent
128  register: nm_remove_domain
129
130- name: Verify remove_domain
131  assert:
132    that:
133    - cm_remove_domain is changed
134    - nm_remove_domain is changed
135    - 'cm_remove_domain.current == cm_remove_domain.previous == nm_remove_domain.previous == [{"l3extDomP": {"attributes": {"dn": "uni/l3dom-l3_dom", "name": "l3_dom", "nameAlias": "", "ownerKey": "", "ownerTag": ""}}}]'
136    - nm_remove_domain.current == []
137
138- name: Remove L3 domain again (check_mode)
139  aci_domain: *domain_absent
140  check_mode: yes
141  register: cm_remove_domain_again
142
143- name: Remove L3 domain again (normal mode)
144  aci_domain: *domain_absent
145  register: nm_remove_domain_again
146
147- name: Verify remove_domain_again
148  assert:
149    that:
150    - cm_remove_domain_again is not changed
151    - nm_remove_domain_again is not changed
152
153
154# QUERY NON-EXISTING DOMAIN
155- name: Query non-existing L3 domain (check_mode)
156  aci_domain:
157    <<: *domain_query
158    domain: l3_dom
159  check_mode: yes
160  register: cm_query_non_domain
161
162- name: Query non-existing L3 domain (normal mode)
163  aci_domain:
164    <<: *domain_query
165    domain: l3_dom
166  register: nm_query_non_domain
167
168- name: Verify query_non_domain
169  assert:
170    that:
171    - cm_query_non_domain is not changed
172    - nm_query_non_domain is not changed
173    - cm_query_non_domain == nm_query_non_domain
174    - nm_query_non_domain.current == []
175