1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

[s3_bucket] Handle error paginating object versions when bucket does not exist (#49396)

This commit is contained in:
Sloane Hertel 2018-12-04 15:42:14 -05:00 committed by Sam Doran
parent a8fbfe1844
commit a3e8917b73
2 changed files with 11 additions and 5 deletions

View file

@ -0,0 +1,3 @@
---
bugfixes:
- Handle error paginating object versions when bucket does not exist (https://github.com/ansible/ansible/issues/49393)

View file

@ -120,7 +120,7 @@ import time
from ansible.module_utils.six.moves.urllib.parse import urlparse
from ansible.module_utils.six import string_types
from ansible.module_utils.basic import to_text
from ansible.module_utils.aws.core import AnsibleAWSModule
from ansible.module_utils.aws.core import AnsibleAWSModule, is_boto3_error_code
from ansible.module_utils.ec2 import compare_policies, ec2_argument_spec, boto3_tag_list_to_ansible_dict, ansible_dict_to_boto3_tag_list
from ansible.module_utils.ec2 import get_aws_connection_info, boto3_conn, AWSRetry
@ -447,10 +447,13 @@ def paginated_list(s3_client, **pagination_params):
def paginated_versions_list(s3_client, **pagination_params):
try:
pg = s3_client.get_paginator('list_object_versions')
for page in pg.paginate(**pagination_params):
# We have to merge the Versions and DeleteMarker lists here, as DeleteMarkers can still prevent a bucket deletion
yield [(data['Key'], data['VersionId']) for data in (page.get('Versions', []) + page.get('DeleteMarkers', []))]
except is_boto3_error_code('NoSuchBucket'):
yield []
def destroy_bucket(s3_client, module):