forked from ansible/ansible
-
Notifications
You must be signed in to change notification settings - Fork 1
/
error_handling.yml
191 lines (177 loc) · 6.99 KB
/
error_handling.yml
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
# Test code for the ACI modules
# Copyright: (c) 2018, Dag Wieers (@dagwieers) <dag@wieers.com>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# PROVOKE ERRORS
- name: Error on name resolution
aci_rest:
host: foo.bar.cisco.com
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
path: /api/mo/uni.json
method: post
content:
fvTenant:
attributes:
name: ansible_test
ignore_errors: yes
register: error_on_name_resolution
- name: Verify error_on_name_resolution
assert:
that:
- error_on_name_resolution.failed == true
- "error_on_name_resolution.msg == 'Connection failed for https://foo.bar.cisco.com/api/aaaLogin.json. Request failed: <urlopen error [Errno -2] Name or service not known>'"
- "'current' not in error_on_name_resolution"
- "'previous' not in error_on_name_resolution"
- "'sent' not in error_on_name_resolution"
- "'proposed' not in error_on_name_resolution"
- "'filter_string' not in error_on_name_resolution"
- name: Error when required parameter is missing
aci_rest:
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
method: post
content:
fvTenant:
attributes:
name: ansible_test
ignore_errors: yes
register: error_on_missing_required_param
- name: Verify error_on_missing_required_param
assert:
that:
- error_on_missing_required_param.failed == true
- 'error_on_missing_required_param.msg == "missing required arguments: path"'
- "'current' not in error_on_missing_required_param"
- "'previous' not in error_on_missing_required_param"
- "'sent' not in error_on_missing_required_param"
- "'proposed' not in error_on_missing_required_param"
- "'filter_string' not in error_on_missing_required_param"
- name: Error when attributes are missing
aci_rest:
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
path: /api/mo/uni/tn-ansible_test.json
method: post
content:
fvTenant:
children:
ignore_errors: yes
register: error_on_missing_attributes
- name: Verify error_on_missing_attributes
assert:
that:
- error_on_missing_attributes.failed == true
- error_on_missing_attributes.method == 'POST'
- "error_on_missing_attributes.msg == 'APIC Error 400: invalid data at line \\'1\\'. Attributes are missing, tag \\'attributes\\' must be specified first, before any other tag'"
- 'error_on_missing_attributes.response == "HTTP Error 400: Bad Request"'
- error_on_missing_attributes.status == 400
- "'current' not in error_on_missing_attributes"
- "'previous' not in error_on_missing_attributes"
- "'sent' not in error_on_missing_attributes"
- "'proposed' not in error_on_missing_attributes"
- "'filter_string' not in error_on_missing_attributes"
- name: Error when input does not validate
aci_rest:
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
path: /api/mo/uni.json
method: post
content:
fvTenant:
attributes:
name: ansible_test
descr: This is an [invalid] description
ignore_errors: yes
register: error_on_input_validation
- name: Verify error_on_input_validation
assert:
that:
- error_on_input_validation.failed == true
- error_on_input_validation.method == 'POST'
- "error_on_input_validation.msg == 'APIC Error 801: property descr of uni/tn-ansible_test failed validation for value \\'This is an [invalid] description\\''"
- 'error_on_input_validation.response == "HTTP Error 400: Bad Request"'
- error_on_input_validation.status == 400
- "'current' not in error_on_input_validation"
- "'previous' not in error_on_input_validation"
- "'sent' not in error_on_input_validation"
- "'proposed' not in error_on_input_validation"
- "'filter_string' not in error_on_input_validation"
- name: Error when invalid attributes are used
aci_rest:
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
path: /api/mo/uni.json
method: post
content:
fvTenant:
attributes:
name: ansible_test
description: This is an "invalid" description
ignore_errors: yes
register: error_on_invalid_attributes
- name: Verify error_on_invalid_attributes
assert:
that:
- error_on_invalid_attributes.failed == true
- error_on_invalid_attributes.method == 'POST'
- "error_on_invalid_attributes.msg == 'APIC Error 400: unknown attribute \\'description\\' in element \\'fvTenant\\''"
- 'error_on_invalid_attributes.response == "HTTP Error 400: Bad Request"'
- error_on_invalid_attributes.status == 400
- "'current' not in error_on_invalid_attributes"
- "'previous' not in error_on_invalid_attributes"
- "'sent' not in error_on_invalid_attributes"
- "'proposed' not in error_on_invalid_attributes"
- "'filter_string' not in error_on_invalid_attributes"
- name: Error on invalid object
aci_rest:
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
path: /api/mo/uni.json
method: post
content:
fvFoobar:
attributes:
name: ansible_test
ignore_errors: yes
register: error_on_invalid_object
- name: Verify error_on_invalid_object
assert:
that:
- error_on_invalid_object.failed == true
- error_on_invalid_object.method == 'POST'
- "error_on_invalid_object.msg == 'APIC Error 122: unknown managed object class fvFoobar'"
- 'error_on_invalid_object.response == "HTTP Error 400: Bad Request"'
- error_on_invalid_object.status == 400
- "'current' not in error_on_invalid_object"
- "'previous' not in error_on_invalid_object"
- "'sent' not in error_on_invalid_object"
- "'proposed' not in error_on_invalid_object"