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 firmware source
9  aci_firmware_source: &source_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    source: aci-msft-pkg-3.1.1i.zip
18    state: absent
19
20
21# ADD SOURCE
22#- name: Add source (check_mode)
23#  aci_firmware_source: &source_present
24#    host: '{{ aci_hostname }}'
25#    username: '{{ aci_username }}'
26#    password: '{{ aci_password }}'
27#    validate_certs: '{{ aci_validate_certs | default(false) }}'
28#    use_ssl: '{{ aci_use_ssl | default(true) }}'
29#    use_proxy: '{{ aci_use_proxy | default(true) }}'
30#    output_level: '{{ aci_output_level | default("info") }}'
31#    source: aci-msft-pkg-3.1.1i.zip
32#    url: foobar.cisco.com/download/cisco/aci/aci-msft-pkg-3.1.1i.zip
33#    url_protocol: http
34#    state: present
35#  check_mode: yes
36#  register: cm_add_source
37#
38#- name: Add source (normal mode)
39#  aci_firmware_source: *source_present
40#  register: nm_add_source
41#
42#- name: Verify add_source
43#  assert:
44#    that:
45#    - cm_add_source is changed
46#    - nm_add_source is changed
47#    - 'cm_add_source.sent == nm_add_source.sent == {"firmwareOSource": {"attributes": {"name": "aci-msft-pkg-3.1.1i.zip", "proto": "http", "url": "foobar.cisco.com/download/cisco/aci/aci-msft-pkg-3.1.1i.zip"}}}'
48#    - 'cm_add_source.proposed == nm_add_source.proposed == {"firmwareOSource": {"attributes": {"name": "aci-msft-pkg-3.1.1i.zip", "proto": "http", "url": "foobar.cisco.com/download/cisco/aci/aci-msft-pkg-3.1.1i.zip"}}}'
49#    - cm_add_source.current == cm_add_source.previous == nm_add_source.previous == []
50#    - nm_add_source.current.0.firmwareOSource.attributes.name == 'aci-msft-pkg-3.1.1i.zip'
51#    - nm_add_source.current.0.firmwareOSource.attributes.proto == 'http'
52#    - nm_add_source.current.0.firmwareOSource.attributes.url == 'foobar.cisco.com/download/cisco/aci/aci-msft-pkg-3.1.1i.zip'
53#
54#- name: Add source again (check_mode)
55#  aci_firmware_source: *source_present
56#  check_mode: yes
57#  register: cm_add_source_again
58#
59#- name: Add source again (normal mode)
60#  aci_firmware_source: *souce_present
61#  register: nm_add_source_again
62#
63#- name: Verify add_source_again
64#  assert:
65#    that:
66#    - cm_add_source_again is not changed
67#    - nm_add_source_again is not changed
68
69
70# QUERY ALL SOURCES
71- name: Query all sources (check_mode)
72  aci_firmware_source: &source_query
73    host: '{{ aci_hostname }}'
74    username: '{{ aci_username }}'
75    password: '{{ aci_password }}'
76    validate_certs: '{{ aci_validate_certs | default(false) }}'
77    use_ssl: '{{ aci_use_ssl | default(true) }}'
78    use_proxy: '{{ aci_use_proxy | default(true) }}'
79    output_level: '{{ aci_output_level | default("info") }}'
80    state: query
81  check_mode: yes
82  register: cm_query_all_sources
83
84- name: Query all sources (normal mode)
85  aci_firmware_source: *source_query
86  register: nm_query_all_sources
87
88- name: Verify query_all_sources
89  assert:
90    that:
91    - cm_query_all_sources is not changed
92    - nm_query_all_sources is not changed
93    - cm_query_all_sources == nm_query_all_sources
94#    - nm_query_all_sources.current|length >= 1
95
96
97# QUERY A SOURCE
98#- name: Query our source (check_mode)
99#  aci_firmware_source:
100#    <<: *source_query
101#    source: aci-msft-pkg-3.1.1i.zip
102#  check_mode: yes
103#  register: cm_query_source
104#
105#- name: Query our source (normal mode)
106#  aci_firmware_source:
107#    <<: *source_query
108#    source: aci-msft-pkg-3.1.1i.zip
109#  register: nm_query_source
110#
111#- name: Verify query_source
112#  assert:
113#    that:
114#    - cm_query_source is not changed
115#    -  nm_query_source is not changed
116#    - cm_query_source == nm_query_source
117#    - nm_query_source.current.0.infraRsDomP.attributes.dn == 'uni/infra/attentp-test_aep/rsdomP-[uni/phys-phys_dom]'
118#    - nm_query_source.current.0.infraRsDomP.attributes.tCl == 'physDomP'
119#    - nm_query_source.current.0.infraRsDomP.attributes.tDn == 'uni/phys-phys_dom'
120
121
122# REMOVE SOURCE
123#- name: Remove source (check_mode)
124#  aci_firmware_source: *source_absent
125#  check_mode: yes
126#  register: cm_remove_source
127
128#- name: Remove source (normal mode)
129#  aci_firmware_source: *source_absent
130#  register: nm_remove_source
131#
132#- name: Verify remove_source
133#  assert:
134#    that:
135#    - cm_remove_source is changed
136#    - nm_remove_source is changed
137#    - 'cm_remove_source.current == cm_remove_source.previous == nm_remove_source.previous == [{"infraRsDomP": {"attributes": {"dn": "uni/infra/attentp-test_aep/rsdomP-[uni/phys-phys_dom]", "tDn": "uni/phys-phys_dom"}}}]'
138#    - nm_remove_source.current == []
139#
140#- name: Remove source again (check_mode)
141#  aci_firmware_source: *source_absent
142#  check_mode: yes
143#  register: cm_remove_source_again
144#
145#- name: Remove source again (normal mode)
146#  aci_firmware_source: *source_absent
147#  register: nm_remove_source_again
148#
149#- name: Verify remove_source_again
150#  assert:
151#    that:
152#    - cm_remove_source_again is not changed
153#    - nm_remove_source_again is not changed
154
155
156# QUERY NON-EXISTING SOURCE
157#- name: Query non-existing source (check_mode)
158#  aci_firmware_source:
159#    <<: *source_query
160#    source: aci-msft-pkg-3.1.1i.zip
161#  check_mode: yes
162#  register: cm_query_non_source
163#
164#- name: Query non-existing source (normal mode)
165#  aci_firmware_source:
166#    <<: *source_query
167#    source: aci-msft-pkg-3.1.1i.zip
168#  register: nm_query_non_source
169#
170#- name: Verify query_non_source
171#  assert:
172#    that:
173#    - cm_query_non_source is not changed
174#    - nm_query_non_source is not changed
175#    - cm_query_non_source == nm_query_non_source
176#    - nm_query_non_source.current == []
177
178
179# PROVOKE ERRORS
180- name: Error when required parameter is missing
181  aci_firmware_source:
182    host: '{{ aci_hostname }}'
183    username: '{{ aci_username }}'
184    password: '{{ aci_password }}'
185    validate_certs: '{{ aci_validate_certs | default(false) }}'
186    use_ssl: '{{ aci_use_ssl | default(true) }}'
187    use_proxy: '{{ aci_use_proxy | default(true) }}'
188    output_level: '{{ aci_output_level | default("info") }}'
189    state: present
190  ignore_errors: yes
191  register: error_on_missing_required_param
192
193- name: Verify error_on_missing_required_param
194  assert:
195    that:
196    - error_on_missing_required_param is failed
197    - 'error_on_missing_required_param.msg == "state is present but all of the following are missing: source, url"'
198