Skip to content

Commit

Permalink
Ignore duplicate-except pylint errors (#294)
Browse files Browse the repository at this point in the history
  • Loading branch information
tremble authored Mar 9, 2021
1 parent 03aefc7 commit 02f6d50
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 18 deletions.
20 changes: 10 additions & 10 deletions plugins/modules/aws_s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,10 +339,10 @@ def key_check(module, s3, bucket, obj, version=None, validate=True):
s3.head_object(Bucket=bucket, Key=obj)
except is_boto3_error_code('404'):
return False
except is_boto3_error_code('403') as e:
except is_boto3_error_code('403') as e: # pylint: disable=duplicate-except
if validate is True:
module.fail_json_aws(e, msg="Failed while looking up object (during key check) %s." % obj)
except (botocore.exceptions.BotoCoreError, botocore.exceptions.ClientError) as e:
except (botocore.exceptions.BotoCoreError, botocore.exceptions.ClientError) as e: # pylint: disable=duplicate-except
module.fail_json_aws(e, msg="Failed while looking up object (during key check) %s." % obj)

return True
Expand Down Expand Up @@ -374,12 +374,12 @@ def bucket_check(module, s3, bucket, validate=True):
s3.head_bucket(Bucket=bucket)
except is_boto3_error_code('404'):
return False
except is_boto3_error_code('403') as e:
except is_boto3_error_code('403') as e: # pylint: disable=duplicate-except
if validate is True:
module.fail_json_aws(e, msg="Failed while looking up bucket (during bucket_check) %s." % bucket)
except botocore.exceptions.EndpointConnectionError as e:
except botocore.exceptions.EndpointConnectionError as e: # pylint: disable=duplicate-except
module.fail_json_aws(e, msg="Invalid endpoint provided")
except (botocore.exceptions.BotoCoreError, botocore.exceptions.ClientError) as e:
except (botocore.exceptions.BotoCoreError, botocore.exceptions.ClientError) as e: # pylint: disable=duplicate-except
module.fail_json_aws(e, msg="Failed while looking up bucket (during bucket_check) %s." % bucket)
return exists

Expand All @@ -404,7 +404,7 @@ def create_bucket(module, s3, bucket, location=None):
)(s3.put_bucket_acl)(ACL=acl, Bucket=bucket)
except is_boto3_error_code(IGNORE_S3_DROP_IN_EXCEPTIONS):
module.warn("PutBucketAcl is not implemented by your storage provider. Set the permission parameters to the empty list to avoid this warning")
except (botocore.exceptions.BotoCoreError, botocore.exceptions.ClientError) as e:
except (botocore.exceptions.BotoCoreError, botocore.exceptions.ClientError) as e: # pylint: disable=duplicate-except
module.fail_json_aws(e, msg="Failed while creating bucket or setting acl (check that you have CreateBucket and PutBucketAcl permission).")

if bucket:
Expand Down Expand Up @@ -455,7 +455,7 @@ def delete_bucket(module, s3, bucket):
return True
except is_boto3_error_code('NoSuchBucket'):
return False
except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e:
except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e: # pylint: disable=duplicate-except
module.fail_json_aws(e, msg="Failed while deleting bucket %s." % bucket)


Expand Down Expand Up @@ -484,7 +484,7 @@ def create_dirkey(module, s3, bucket, obj, encrypt):
s3.put_object_acl(ACL=acl, Bucket=bucket, Key=obj)
except is_boto3_error_code(IGNORE_S3_DROP_IN_EXCEPTIONS):
module.warn("PutObjectAcl is not implemented by your storage provider. Set the permissions parameters to the empty list to avoid this warning")
except (botocore.exceptions.BotoCoreError, botocore.exceptions.ClientError) as e:
except (botocore.exceptions.BotoCoreError, botocore.exceptions.ClientError) as e: # pylint: disable=duplicate-except
module.fail_json_aws(e, msg="Failed while creating object %s." % obj)
module.exit_json(msg="Virtual directory %s created in bucket %s" % (obj, bucket), changed=True)

Expand Down Expand Up @@ -552,7 +552,7 @@ def upload_s3file(module, s3, bucket, obj, expiry, metadata, encrypt, headers, s
s3.put_object_acl(ACL=acl, Bucket=bucket, Key=obj)
except is_boto3_error_code(IGNORE_S3_DROP_IN_EXCEPTIONS):
module.warn("PutObjectAcl is not implemented by your storage provider. Set the permission parameters to the empty list to avoid this warning")
except (botocore.exceptions.BotoCoreError, botocore.exceptions.ClientError) as e:
except (botocore.exceptions.BotoCoreError, botocore.exceptions.ClientError) as e: # pylint: disable=duplicate-except
module.fail_json_aws(e, msg="Unable to set object ACL")
try:
url = s3.generate_presigned_url(ClientMethod='put_object',
Expand All @@ -577,7 +577,7 @@ def download_s3file(module, s3, bucket, obj, dest, retries, version=None):
# AccessDenied errors may be triggered if 1) file does not exist or 2) file exists but
# user does not have the s3:GetObject permission. 404 errors are handled by download_file().
module.fail_json_aws(e, msg="Could not find the key %s." % obj)
except is_boto3_error_message('require AWS Signature Version 4'):
except is_boto3_error_message('require AWS Signature Version 4'): # pylint: disable=duplicate-except
raise Sigv4Required()
except is_boto3_error_code('InvalidArgument') as e: # pylint: disable=duplicate-except
module.fail_json_aws(e, msg="Could not find the key %s." % obj)
Expand Down
4 changes: 2 additions & 2 deletions plugins/modules/ec2_ami.py
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ def deregister_image(module, connection):
# Don't error out if root volume snapshot was already deregistered as part of deregister_image
except is_boto3_error_code('InvalidSnapshot.NotFound'):
pass
except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e:
except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e: # pylint: disable=duplicate-except
module.fail_json_aws(e, msg='Failed to delete snapshot.')
exit_params['snapshots_deleted'] = snapshots

Expand Down Expand Up @@ -671,7 +671,7 @@ def get_image_by_id(module, connection, image_id):
ImageId=image_id)['ProductCodes']
except is_boto3_error_code('InvalidAMIID.Unavailable'):
pass
except (botocore.exceptions.BotoCoreError, botocore.exceptions.ClientError) as e:
except (botocore.exceptions.BotoCoreError, botocore.exceptions.ClientError) as e: # pylint: disable=duplicate-except
module.fail_json_aws(e, msg="Error retrieving image attributes for image %s" % image_id)
return result
module.fail_json(msg="Invalid number of instances (%s) found for image_id: %s." % (str(len(images)), image_id))
Expand Down
2 changes: 1 addition & 1 deletion plugins/modules/ec2_eni_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ def list_eni(connection, module):
network_interfaces_result = connection.describe_network_interfaces(aws_retry=True, **params)['NetworkInterfaces']
except is_boto3_error_code('InvalidNetworkInterfaceID.NotFound'):
module.exit_json(network_interfaces=[])
except (ClientError, NoCredentialsError) as e:
except (ClientError, NoCredentialsError) as e: # pylint: disable=duplicate-except
module.fail_json_aws(e)

# Modify boto3 tags list to be ansible friendly dict and then camel_case
Expand Down
2 changes: 1 addition & 1 deletion plugins/modules/ec2_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def find_key_pair(module, ec2_client, name):
key = ec2_client.describe_key_pairs(aws_retry=True, KeyNames=[name])['KeyPairs'][0]
except is_boto3_error_code('InvalidKeyPair.NotFound'):
return None
except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as err:
except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as err: # pylint: disable=duplicate-except
module.fail_json_aws(err, msg="error finding keypair")
except IndexError:
key = None
Expand Down
8 changes: 4 additions & 4 deletions plugins/modules/s3_bucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ def create_or_update_bucket(s3_client, module, location):
except is_boto3_error_code(['NotImplemented', 'XNotImplemented']) as exp:
if versioning is not None:
module.fail_json_aws(exp, msg="Failed to get bucket versioning")
except (BotoCoreError, ClientError) as exp:
except (BotoCoreError, ClientError) as exp: # pylint: disable=duplicate-except
module.fail_json_aws(exp, msg="Failed to get bucket versioning")
else:
if versioning is not None:
Expand Down Expand Up @@ -297,7 +297,7 @@ def create_or_update_bucket(s3_client, module, location):
except is_boto3_error_code(['NotImplemented', 'XNotImplemented']):
if requester_pays is not None:
module.fail_json_aws(exp, msg="Failed to get bucket request payment")
except (BotoCoreError, ClientError) as exp:
except (BotoCoreError, ClientError) as exp: # pylint: disable=duplicate-except
module.fail_json_aws(exp, msg="Failed to get bucket request payment")
else:
if requester_pays is not None:
Expand All @@ -320,7 +320,7 @@ def create_or_update_bucket(s3_client, module, location):
except is_boto3_error_code(['NotImplemented', 'XNotImplemented']):
if policy is not None:
module.fail_json_aws(exp, msg="Failed to get bucket policy")
except (BotoCoreError, ClientError) as exp:
except (BotoCoreError, ClientError) as exp: # pylint: disable=duplicate-except
module.fail_json_aws(exp, msg="Failed to get bucket policy")
else:
if policy is not None:
Expand Down Expand Up @@ -355,7 +355,7 @@ def create_or_update_bucket(s3_client, module, location):
except is_boto3_error_code(['NotImplemented', 'XNotImplemented']):
if tags is not None:
module.fail_json_aws(exp, msg="Failed to get bucket tags")
except (ClientError, BotoCoreError) as exp:
except (ClientError, BotoCoreError) as exp: # pylint: disable=duplicate-except
module.fail_json_aws(exp, msg="Failed to get bucket tags")
else:
if tags is not None:
Expand Down

0 comments on commit 02f6d50

Please sign in to comment.