Debian Codegraph @

ansible_collections/community/aws/tests/integration/targets/s3_metrics_configuration/tasks/main.yml

raw
1 ---
2 # Integration tests for s3_metrics_configuration
3 #
4 # Notes:
5 # - The module only outputs 'changed' since its very simple
6 #
7 - module_defaults:
8 group/aws:
9 access_key: '{{ aws_access_key }}'
10 secret_key: '{{ aws_secret_key }}'
11 session_token: '{{ security_token | default(omit) }}'
12 region: '{{ aws_region }}'
13 collections:
14 - amazon.aws
15 block:
16
17 # TODO: Until there's a module to get info s3 metrics configuration, awscli is needed
18 - name: Install awscli
19 pip:
20 state: present
21 name: awscli
22
23 # ============================================================
24 - name: Try to create metrics configuration for non-existing bucket
25 s3_metrics_configuration:
26 bucket_name: '{{ test_bucket }}'
27 id: 'EntireBucket'
28 state: present
29 register: result
30 ignore_errors: yes
31
32 - assert:
33 that:
34 - result is failed
35
36 # ============================================================
37 - name: Create simple s3_bucket to act upon it
38 s3_bucket:
39 name: '{{ test_bucket }}'
40 state: present
41 register: output
42
43 - assert:
44 that:
45 - output is changed
46 - output.name == test_bucket
47
48 # ============================================================
49 - name: Create a metrics configuration under check mode
50 s3_metrics_configuration:
51 bucket_name: '{{ test_bucket }}'
52 id: 'EntireBucket'
53 state: present
54 check_mode: yes
55 register: result
56
57 - include_tasks: './s3_metrics_info.yml'
58
59 - assert:
60 that:
61 - result is changed
62 - metrics_info | selectattr('Id', 'search', 'EntireBucket') | list | length == 0
63
64 # ============================================================
65 - name: Create a metrics configuration that enables metrics for an entire bucket
66 s3_metrics_configuration:
67 bucket_name: '{{ test_bucket }}'
68 id: 'EntireBucket'
69 state: present
70 register: result
71
72 - include_tasks: './s3_metrics_info.yml'
73
74 - assert:
75 that:
76 - result is changed
77 - metrics_info | selectattr('Id', 'search', 'EntireBucket') | list | length == 1
78
79 # ============================================================
80 - name: Create a metrics configuration idempotency under check mode
81 s3_metrics_configuration:
82 bucket_name: '{{ test_bucket }}'
83 id: 'EntireBucket'
84 state: present
85 check_mode: yes
86 register: result
87
88 - assert:
89 that:
90 - result is not changed
91
92 # ============================================================
93 - name: Create a metrics configuration idempotency
94 s3_metrics_configuration:
95 bucket_name: '{{ test_bucket }}'
96 id: 'EntireBucket'
97 state: present
98 register: result
99
100 - assert:
101 that:
102 - result is not changed
103
104 # ============================================================
105 - name: Put a metrics configuration that enables metrics for objects starting with a prefix
106 s3_metrics_configuration:
107 bucket_name: "{{ test_bucket }}"
108 id: Assets
109 filter_prefix: assets
110 state: present
111 register: result
112
113 - include_tasks: './s3_metrics_info.yml'
114
115 - assert:
116 that:
117 - result is changed
118 - (metrics_info | selectattr('Id', 'search', 'Assets') | list | first).Filter.Prefix == 'assets'
119
120 # ============================================================
121 - name: Update existing metrics configuration under check mode
122 s3_metrics_configuration:
123 bucket_name: "{{ test_bucket }}"
124 id: Assets
125 filter_tag:
126 kind: Asset
127 state: present
128 check_mode: yes
129 register: result
130
131 - include_tasks: './s3_metrics_info.yml'
132
133 - assert:
134 that:
135 - result is changed
136 - (metrics_info | selectattr('Id', 'search', 'Assets') | list | first).Filter.Prefix == 'assets'
137 - (metrics_info | selectattr('Id', 'search', 'Assets') | list | first).Filter.Tag is not defined
138
139 # ============================================================
140 - name: Update existing metrics configuration and enable metrics for objects with specific tag
141 s3_metrics_configuration:
142 bucket_name: "{{ test_bucket }}"
143 id: Assets
144 filter_tag:
145 kind: Asset
146 state: present
147 register: result
148
149 - include_tasks: './s3_metrics_info.yml'
150
151 - assert:
152 that:
153 - result is changed
154 - (metrics_info | selectattr('Id', 'search', 'Assets') | list | first).Filter.Prefix is not defined
155 - (metrics_info | selectattr('Id', 'search', 'Assets') | list | first).Filter.Tag.Key == 'kind'
156 - (metrics_info | selectattr('Id', 'search', 'Assets') | list | first).Filter.Tag.Value == 'Asset'
157
158 # ============================================================
159 - name: Put a metrics configuration that enables metrics for objects that start with a particular prefix and have specific tags applied
160 s3_metrics_configuration:
161 bucket_name: "{{ test_bucket }}"
162 id: ImportantBlueDocuments
163 filter_prefix: documents
164 filter_tags:
165 priority: High
166 class: Blue
167 state: present
168 register: result
169
170 - include_tasks: './s3_metrics_info.yml'
171
172 - assert:
173 that:
174 - result is changed
175 - (metrics_info | selectattr('Id', 'search', 'ImportantBlueDocuments') | list | first).Filter.And.Prefix == 'documents'
176 - (metrics_info | selectattr('Id', 'search', 'ImportantBlueDocuments') | list | first).Filter.And.Tags[0].Key == 'priority'
177 - (metrics_info | selectattr('Id', 'search', 'ImportantBlueDocuments') | list | first).Filter.And.Tags[0].Value == 'High'
178 - (metrics_info | selectattr('Id', 'search', 'ImportantBlueDocuments') | list | first).Filter.And.Tags[1].Key == 'class'
179 - (metrics_info | selectattr('Id', 'search', 'ImportantBlueDocuments') | list | first).Filter.And.Tags[1].Value == 'Blue'
180
181 # ============================================================
182 - name: Delete metrics configuration in check mode
183 s3_metrics_configuration:
184 bucket_name: '{{ test_bucket }}'
185 id: 'EntireBucket'
186 state: absent
187 check_mode: yes
188 register: result
189
190 - include_tasks: './s3_metrics_info.yml'
191
192 - assert:
193 that:
194 - result is changed
195 - metrics_info | selectattr('Id', 'search', 'EntireBucket') | list | length == 1 # still present
196
197 # ============================================================
198 - name: Delete metrics configuration
199 s3_metrics_configuration:
200 bucket_name: '{{ test_bucket }}'
201 id: 'EntireBucket'
202 state: absent
203 register: result
204
205 - include_tasks: './s3_metrics_info.yml'
206
207 - assert:
208 that:
209 - result is changed
210 - metrics_info | selectattr('Id', 'search', 'EntireBucket') | list | length == 0
211
212 # ============================================================
213 - name: Try to delete non-existing metrics configuration
214 s3_metrics_configuration:
215 bucket_name: '{{ test_bucket }}'
216 id: 'EntireBucket'
217 state: absent
218 register: result
219
220 - assert:
221 that:
222 - result is not changed
223
224 # ============================================================
225 - name: Try to delete metrics configuration for non-existing bucket
226 s3_metrics_configuration:
227 bucket_name: '{{ test_bucket }}-non-existing'
228 id: 'EntireBucket'
229 state: absent
230 register: result
231 ignore_errors: yes
232
233 - assert:
234 that:
235 - result is failed
236
237 # ============================================================
238 always:
239 - name: Delete test bucket
240 s3_bucket:
241 name: '{{ test_bucket }}'
242 state: absent
243 ignore_errors: yes