summaryrefslogtreecommitdiff
path: root/test/integration/targets/meraki_webhook/tasks/tests.yml
blob: c16caba0cc9325d6043da452692dc4af09fbc1d1 (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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
# Test code for the Meraki Webhook module
# Copyright: (c) 2019, Kevin Breit (@kbreit)

# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
---
- block:
  - name: Test an API key is provided
    fail:
      msg: Please define an API key
    when: auth_key is not defined

  - name: Create test network
    meraki_network:
      auth_key: '{{auth_key}}'
      state: present
      org_name: '{{test_org_name}}'
      net_name: '{{test_net_name}}'
      type: appliance

  - name: Create webhook with check mode
    meraki_webhook:
      auth_key: '{{auth_key}}'
      state: present
      org_name: '{{test_org_name}}'
      net_name: '{{test_net_name}}'
      name: Test_Hook
      url: https://webhook.site/8eb5b76f-b167-4cb8-9fc4-42621b724244
      shared_secret: shhhdonttellanyone
    check_mode: yes
    register: create_one_check

  - debug:
      var: create_one_check

  - assert:
      that:
        - create_one_check is changed
        - create_one_check.data is defined

  - name: Create webhook
    meraki_webhook:
      auth_key: '{{auth_key}}'
      state: present
      org_name: '{{test_org_name}}'
      net_name: '{{test_net_name}}'
      name: Test_Hook
      url: https://webhook.site/8eb5b76f-b167-4cb8-9fc4-42621b724244
      shared_secret: shhhdonttellanyone
    register: create_one

  - debug:
      var: create_one

  - assert:
      that:
        - create_one is changed
        - create_one.data is defined

  - set_fact:
      webhook_id: '{{create_one.data.id}}'

  - name: Query one webhook
    meraki_webhook:
      auth_key: '{{auth_key}}'
      state: query
      org_name: '{{test_org_name}}'
      net_name: '{{test_net_name}}'
      name: Test_Hook
    register: query_one

  - debug:
      var: query_one

  - assert:
      that:
        - query_one.data is defined

  - name: Query one webhook with id
    meraki_webhook:
      auth_key: '{{auth_key}}'
      state: query
      org_name: '{{test_org_name}}'
      net_name: '{{test_net_name}}'
      webhook_id: '{{webhook_id}}'
    register: query_one_id

  - debug:
      var: query_one_id

  - assert:
      that:
        - query_one_id.data is defined

  - name: Update webhook with check mode
    meraki_webhook:
      auth_key: '{{auth_key}}'
      state: present
      org_name: '{{test_org_name}}'
      net_name: '{{test_net_name}}'
      name: Test_Hook
      url: https://webhook.site/8eb5b76f-b167-4cb8-9fc4-42621b724244
      shared_secret: shhhdonttellanyonehere
    check_mode: yes
    register: update_check

  - assert:
      that:
        - update_check is changed
        - update_check.data is defined

  - name: Update webhook
    meraki_webhook:
      auth_key: '{{auth_key}}'
      state: present
      org_name: '{{test_org_name}}'
      net_name: '{{test_net_name}}'
      name: Test_Hook
      url: https://webhook.site/8eb5b76f-b167-4cb8-9fc4-42621b724244
      shared_secret: shhhdonttellanyonehere
    register: update

  - debug:
      var: update

  - assert:
      that:
        - update is changed
        - update.data is defined

  - name: Update webhook with idempotency
    meraki_webhook:
      auth_key: '{{auth_key}}'
      state: present
      org_name: '{{test_org_name}}'
      net_name: '{{test_net_name}}'
      name: Test_Hook
      url: https://webhook.site/8eb5b76f-b167-4cb8-9fc4-42621b724244
      shared_secret: shhhdonttellanyonehere
    register: update_idempotent

  - debug:
      var: update_idempotent

  - assert:
      that:
        - update_idempotent is not changed
        - update_idempotent.data is defined

  - name: Update webhook with id
    meraki_webhook:
      auth_key: '{{auth_key}}'
      state: present
      org_name: '{{test_org_name}}'
      net_name: '{{test_net_name}}'
      webhook_id: '{{webhook_id}}'
      name: Test_Hook
      url: https://webhook.site/8eb5b76f-b167-4cb8-9fc4-42621b724244
      shared_secret: shhhdonttellanyonehereid
    register: update_id

  - debug:
      var: update_id

  - assert:
      that:
        - update_id is changed
        - update_id.data is defined

  - name: Test webhook
    meraki_webhook:
      auth_key: '{{auth_key}}'
      state: present
      org_name: '{{test_org_name}}'
      net_name: '{{test_net_name}}'
      test: test
      url: https://webhook.site/8eb5b76f-b167-4cb8-9fc4-42621b724244
    register: webhook_test

  - debug:
      var: webhook_test

  - set_fact:
      test_id: '{{webhook_test.data.id}}'

  - name: Get webhook status
    meraki_webhook:
      auth_key: '{{auth_key}}'
      state: present
      org_name: '{{test_org_name}}'
      net_name: '{{test_net_name}}'
      test: status
      test_id: '{{test_id}}'
    register: webhook_test_status

  - debug:
      var: webhook_test_status

  - assert:
      that:
        - webhook_test_status.data is defined

  - name: Query all webhooks
    meraki_webhook:
      auth_key: '{{auth_key}}'
      state: query
      org_name: '{{test_org_name}}'
      net_name: '{{test_net_name}}'
    register: query_all

  - debug:
      var: query_all

  - name: Delete webhook invalid webhook
    meraki_webhook:
      auth_key: '{{auth_key}}'
      state: absent
      org_name: '{{test_org_name}}'
      net_name: '{{test_net_name}}'
      name: Test_Hook_Invalid
    check_mode: yes
    register: delete_invalid
    ignore_errors: yes

  - debug:
      var: delete_invalid

  - assert:
      that:
        - 'delete_invalid.msg == "There is no webhook with the name Test_Hook_Invalid"'

  - name: Delete webhook in check mode
    meraki_webhook:
      auth_key: '{{auth_key}}'
      state: absent
      org_name: '{{test_org_name}}'
      net_name: '{{test_net_name}}'
      name: Test_Hook
    check_mode: yes
    register: delete_check

  - debug:
      var: delete_check

  - assert:
      that:
        - delete_check is changed

  - name: Delete webhook
    meraki_webhook:
      auth_key: '{{auth_key}}'
      state: absent
      org_name: '{{test_org_name}}'
      net_name: '{{test_net_name}}'
      name: Test_Hook
    register: delete

  - debug:
      var: delete

  - assert:
      that:
        - delete is changed

  always:
  #############################################################################
  # Tear down starts here
  #############################################################################
  - name: Delete test network
    meraki_network:
      auth_key: '{{auth_key}}'
      state: absent
      org_name: '{{test_org_name}}'
      net_name: '{{test_net_name}}'