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

pull/49509/head
Sloane Hertel 6 years ago committed by Sam Doran
parent a8fbfe1844
commit a3e8917b73

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

@ -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):
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', []))]
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):

Loading…
Cancel
Save