Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

s3_lifecycle: reassure that configuration is complete before returning. #1085

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- s3_lifecycle - check that configuration is complete before returning (https://github.com/ansible-collections/community.aws/pull/1085).
24 changes: 20 additions & 4 deletions plugins/modules/s3_lifecycle.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,15 +485,23 @@ def create_lifecycle_rule(client, module):

_changed = changed
_retries = 10
while wait and _changed and _retries:
_not_changed_cnt = 6
while wait and _changed and _retries and _not_changed_cnt:
# We've seen examples where get_bucket_lifecycle_configuration returns
# the updated rules, then the old rules, then the updated rules again,
# the updated rules, then the old rules, then the updated rules again and
# again couple of times.
# Thus try to read the rule few times in a row to check if it has changed.
time.sleep(5)
_retries -= 1
new_rules = fetch_rules(client, module, name)
(_changed, lifecycle_configuration) = compare_and_update_configuration(client, module,
new_rules,
new_rule)
if not _changed:
_not_changed_cnt -= 1
_changed = True
else:
_not_changed_cnt = 6

new_rules = fetch_rules(client, module, name)

Expand Down Expand Up @@ -531,13 +539,21 @@ def destroy_lifecycle_rule(client, module):

_changed = changed
_retries = 10
while wait and _changed and _retries:
_not_changed_cnt = 6
while wait and _changed and _retries and _not_changed_cnt:
# We've seen examples where get_bucket_lifecycle_configuration returns
# the updated rules, then the old rules, then the updated rules again,
# the updated rules, then the old rules, then the updated rules again and
# again couple of times.
# Thus try to read the rule few times in a row to check if it has changed.
time.sleep(5)
_retries -= 1
new_rules = fetch_rules(client, module, name)
(_changed, lifecycle_configuration) = compare_and_remove_rule(new_rules, rule_id, prefix)
if not _changed:
_not_changed_cnt -= 1
_changed = True
else:
_not_changed_cnt = 6

new_rules = fetch_rules(client, module, name)

Expand Down
36 changes: 36 additions & 0 deletions tests/integration/targets/s3_lifecycle/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,42 @@
- output.changed
- output.name == bucket_name
- not output.requester_pays
# ============================================================
- name: Create a number of policies and check if all of them are created
community.aws.s3_lifecycle:
name: "{{ bucket_name }}"
rule_id: "{{ item }}"
expiration_days: 10
prefix: "{{ item }}"
status: enabled
state: present
wait: yes
register: output
loop:
- rule_1
- rule_2
- rule_3
- assert:
that:
- (output.results | last).rules | length == 3
# ============================================================
- name: Remove previously created policies and check if all of them are removed
community.aws.s3_lifecycle:
name: "{{ bucket_name }}"
rule_id: "{{ item }}"
expiration_days: 10
prefix: "{{ item }}"
status: enabled
state: absent
wait: yes
register: output
loop:
- rule_1
- rule_2
- rule_3
- assert:
that:
- (output.results | last).rules | length == 0
# ============================================================
- name: Create a lifecycle policy
s3_lifecycle:
Expand Down