Debian Codegraph @

ansible_collections/cisco/mso/tests/integration/targets/mso_backup_schedule/tasks/main.yml

raw symbols SCIP
1 # Test code for the MSO modules
2 # Copyright: (c) 2022, Akini Ross (@akinross) <[email protected]>
3
4 # GNU General Public License v3.0+ (see LICENSE or https://www.gnu.org/licenses/gpl-3.0.txt)
5
6 - name: Test that we have an ACI MultiSite host, username and password
7 ansible.builtin.fail:
8 msg: 'Please define the following variables: mso_hostname, mso_username and mso_password.'
9 when: mso_hostname is not defined or mso_username is not defined or mso_password is not defined
10
11 # CLEAN ENVIRONMENT
12
13 - name: Set vars
14 ansible.builtin.set_fact:
15 mso_info: &mso_info
16 host: '{{ mso_hostname }}'
17 username: '{{ mso_username }}'
18 password: '{{ mso_password }}'
19 validate_certs: '{{ mso_validate_certs | default(false) }}'
20 use_ssl: '{{ mso_use_ssl | default(true) }}'
21 use_proxy: '{{ mso_use_proxy | default(true) }}'
22 output_level: '{{ mso_output_level | default("debug") }}'
23
24 - name: Query MSO version
25 cisco.mso.mso_version:
26 <<: *mso_info
27 state: query
28 register: version
29
30 # Adding generic block to allow tests to pass for versions above NDO4.1
31 - name: Execute tasks only for MSO version < 4.0
32 when: version.current.version is version('4.0', '<')
33 block:
34 - name: Delete existing backup schedule
35 cisco.mso.mso_backup_schedule:
36 <<: *mso_info
37 state: absent
38
39 - name: Ensure remote location is present
40 cisco.mso.mso_remote_location:
41 <<: *mso_info
42 remote_location: ansible_test
43 remote_protocol: scp
44 remote_host: '{{ mso_remote_location }}'
45 remote_path: '{{ mso_remote_location_path | default("/tmp") }}'
46 authentication_type: password
47 remote_username: '{{ mso_remote_location_user | default(mso_username) }}'
48 remote_password: '{{ mso_remote_location_password | default(mso_password) }}'
49 state: present
50
51 # TESTS
52
53 - name: Get empty backup schedule
54 cisco.mso.mso_backup_schedule:
55 <<: *mso_info
56 state: query
57 register: no_schedule
58
59 - name: Verify empty backup schedule
60 ansible.builtin.assert:
61 that:
62 - no_schedule is not changed
63 - no_schedule.current == {}
64
65 - name: Set backup schedule (check mode)
66 cisco.mso.mso_backup_schedule:
67 <<: *mso_info
68 frequency_unit: hours
69 frequency_length: 7
70 remote_location: ansible_test
71 state: present
72 check_mode: true
73 register: cm_schedule_create
74
75 - name: Set backup schedule (normal mode)
76 cisco.mso.mso_backup_schedule:
77 <<: *mso_info
78 frequency_unit: hours
79 frequency_length: 7
80 remote_location: ansible_test
81 state: present
82 register: nm_schedule_create
83
84 # add date tests
85 - name: Verify success set backup schedule
86 ansible.builtin.assert:
87 that:
88 - cm_schedule_create is changed
89 - cm_schedule_create.current.intervalLength == 7
90 - cm_schedule_create.current.intervalTimeUnit == "HOURS"
91 - cm_schedule_create.current.locationType == "remote"
92 - nm_schedule_create is changed
93 - nm_schedule_create.current.timeInterval.length == 7
94 - nm_schedule_create.current.timeInterval.unit == "HOURS"
95 - nm_schedule_create.current.callbackWSRequest.methodBody.locationType == "remote"
96 - "'00:00:00' in nm_schedule_create.current.firstScheduledAt"
97
98 - name: Adjust backup schedule (check mode)
99 cisco.mso.mso_backup_schedule:
100 <<: *mso_info
101 frequency_unit: days
102 frequency_length: 1
103 remote_location: ansible_test
104 state: present
105 check_mode: true
106 register: cm_schedule_adjust
107
108 - name: Adjust backup schedule (normal mode)
109 cisco.mso.mso_backup_schedule:
110 <<: *mso_info
111 frequency_unit: days
112 frequency_length: 1
113 remote_location: ansible_test
114 state: present
115 register: nm_schedule_adjust
116
117 - name: Verify success set backup schedule
118 ansible.builtin.assert:
119 that:
120 - cm_schedule_adjust is changed
121 - cm_schedule_adjust.current.intervalLength == 1
122 - cm_schedule_adjust.current.intervalTimeUnit == "DAYS"
123 - cm_schedule_adjust.current.locationType == "remote"
124 - nm_schedule_adjust is changed
125 - nm_schedule_adjust.current.timeInterval.length == 1
126 - nm_schedule_adjust.current.timeInterval.unit == "DAYS"
127 - nm_schedule_adjust.current.callbackWSRequest.methodBody.locationType == "remote"
128
129 - name: Get backup schedule
130 cisco.mso.mso_backup_schedule:
131 <<: *mso_info
132 state: query
133 register: schedule
134
135 - name: Verify success get backup schedule
136 ansible.builtin.assert:
137 that:
138 - schedule is not changed
139 - nm_schedule_adjust.current.timeInterval.length == 1
140 - nm_schedule_adjust.current.timeInterval.unit == "DAYS"
141 - nm_schedule_adjust.current.callbackWSRequest.methodBody.locationType == "remote"
142
143 - name: Delete backup schedule (check mode)
144 cisco.mso.mso_backup_schedule:
145 <<: *mso_info
146 state: absent
147 check_mode: true
148
149 - name: Delete backup schedule (normal mode)
150 cisco.mso.mso_backup_schedule:
151 <<: *mso_info
152 state: absent
153
154 - name: Get empty backup schedule
155 cisco.mso.mso_backup_schedule:
156 <<: *mso_info
157 state: query
158 register: no_schedule
159
160 - name: Verify empty backup schedule
161 ansible.builtin.assert:
162 that:
163 - no_schedule is not changed
164 - no_schedule.current == {}
165
166 - name: Set backup schedule incorrect time to parse (normal mode)
167 cisco.mso.mso_backup_schedule:
168 <<: *mso_info
169 start_time: no_time
170 frequency_unit: hours
171 frequency_length: 7
172 remote_location: ansible_test
173 state: present
174 register: nm_schedule_incorrect_time
175 ignore_errors: true
176
177 - name: Set backup schedule incorrect date to parse (normal mode)
178 cisco.mso.mso_backup_schedule:
179 <<: *mso_info
180 start_date: no_date
181 frequency_unit: hours
182 frequency_length: 7
183 remote_location: ansible_test
184 state: present
185 register: nm_schedule_incorrect_date
186 ignore_errors: true
187
188 - name: Set backup schedule incorrect date object create from start_date (normal mode)
189 cisco.mso.mso_backup_schedule:
190 <<: *mso_info
191 start_date: "2030-15-45"
192 frequency_unit: hours
193 frequency_length: 7
194 remote_location: ansible_test
195 state: present
196 register: nm_schedule_incorrect_date_from_start_date
197 ignore_errors: true
198
199 - name: Set backup schedule incorrect date object create from start_time (normal mode)
200 cisco.mso.mso_backup_schedule:
201 <<: *mso_info
202 start_time: "2030:15:45"
203 frequency_unit: hours
204 frequency_length: 7
205 remote_location: ansible_test
206 state: present
207 register: nm_schedule_incorrect_time_from_start_time
208 ignore_errors: true
209
210 - name: Verify error messages
211 ansible.builtin.assert:
212 that:
213 - nm_schedule_incorrect_time is failed
214 - nm_schedule_incorrect_time.msg.startswith("Failed to parse time format")
215 - nm_schedule_incorrect_date is failed
216 - nm_schedule_incorrect_date.msg.startswith("Failed to parse date format")
217 - nm_schedule_incorrect_date_from_start_date is failed
218 - nm_schedule_incorrect_date_from_start_date.msg.startswith("Failed to create datetime object")
219 - nm_schedule_incorrect_time_from_start_time is failed
220 - nm_schedule_incorrect_time_from_start_time.msg.startswith("Failed to create datetime object")
221
222 - name: Set backup schedule full (normal mode)
223 cisco.mso.mso_backup_schedule:
224 <<: *mso_info
225 start_date: "2030-11-12"
226 start_time: "00:00:01"
227 frequency_unit: days
228 frequency_length: 1
229 remote_location: ansible_test
230 remote_path: remote_add
231 state: present
232 register: nm_schedule_full
233
234 - name: Verify success set backup schedule
235 ansible.builtin.assert:
236 that:
237 - nm_schedule_full is changed
238 - nm_schedule_full.current.timeInterval.length == 1
239 - nm_schedule_full.current.timeInterval.unit == "DAYS"
240 - nm_schedule_full.current.callbackWSRequest.methodBody.locationType == "remote"
241 - nm_schedule_full.current.firstScheduledAt == "2030-11-12T00:00:01.000Z"
242 - nm_schedule_full.current.nextScheduleAt == "2030-11-13T00:00:01.000Z"
243
244 - name: Delete backup schedule (normal mode)
245 cisco.mso.mso_backup_schedule:
246 <<: *mso_info
247 state: absent
248
249 - name: Get empty backup schedule
250 cisco.mso.mso_backup_schedule:
251 <<: *mso_info
252 state: query
253 register: no_schedule
254
255 - name: Verify empty backup schedule
256 ansible.builtin.assert:
257 that:
258 - no_schedule is not changed
259 - no_schedule.current == {}