Assorted pylint fixes

This commit is contained in:
Dag Wieers
2019-02-14 21:02:27 +01:00
committed by Matt Clay
parent 8e0f95951d
commit f9ab9b4d68
65 changed files with 343 additions and 473 deletions

View File

@@ -1,4 +1,6 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Copyright: Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
@@ -181,7 +183,7 @@ def get_api_definitions(module, swagger_file=None, swagger_dict=None, swagger_te
with open(swagger_file) as f:
apidata = f.read()
except OSError as e:
msg = "Failed trying to read swagger file {}: {}".format(str(swagger_file), str(e))
msg = "Failed trying to read swagger file {0}: {1}".format(str(swagger_file), str(e))
module.fail_json(msg=msg, exception=traceback.format_exc())
if swagger_dict is not None:
apidata = json.dumps(swagger_dict)
@@ -216,7 +218,7 @@ def delete_rest_api(module, client, api_id):
try:
delete_response = delete_api(client, api_id=api_id)
except (botocore.exceptions.ClientError, botocore.exceptions.EndpointConnectionError) as e:
module.fail_json_aws(e, msg="deleting API {}".format(api_id))
module.fail_json_aws(e, msg="deleting API {0}".format(api_id))
return delete_response
@@ -235,7 +237,7 @@ def ensure_api_in_correct_state(module, client, api_id=None, api_data=None, stag
try:
configure_response = configure_api(client, api_data=api_data, api_id=api_id)
except (botocore.exceptions.ClientError, botocore.exceptions.EndpointConnectionError) as e:
module.fail_json_aws(e, msg="configuring API {}".format(api_id))
module.fail_json_aws(e, msg="configuring API {0}".format(api_id))
deploy_response = None
@@ -244,7 +246,7 @@ def ensure_api_in_correct_state(module, client, api_id=None, api_data=None, stag
deploy_response = create_deployment(client, api_id=api_id, stage=stage,
description=deploy_desc)
except (botocore.exceptions.ClientError, botocore.exceptions.EndpointConnectionError) as e:
msg = "deploying api {} to stage {}".format(api_id, stage)
msg = "deploying api {0} to stage {1}".format(api_id, stage)
module.fail_json_aws(e, msg)
return configure_response, deploy_response

View File

@@ -1,18 +1,7 @@
#!/usr/bin/python
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
# -*- coding: utf-8 -*
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ['preview'],
@@ -734,7 +723,7 @@ def get_arn_from_kms_alias(kms, aliasname):
key_id = a['TargetKeyId']
break
if not key_id:
raise Exception('could not find alias {}'.format(aliasname))
raise Exception('could not find alias {0}'.format(aliasname))
# now that we have the ID for the key, we need to get the key's ARN. The alias
# has an ARN but we need the key itself.
@@ -742,14 +731,14 @@ def get_arn_from_kms_alias(kms, aliasname):
for k in ret['Keys']:
if k['KeyId'] == key_id:
return k['KeyArn']
raise Exception('could not find key from id: {}'.format(key_id))
raise Exception('could not find key from id: {0}'.format(key_id))
def get_arn_from_role_name(iam, rolename):
ret = iam.get_role(RoleName=rolename)
if ret.get('Role') and ret['Role'].get('Arn'):
return ret['Role']['Arn']
raise Exception('could not find arn for name {}.'.format(rolename))
raise Exception('could not find arn for name {0}.'.format(rolename))
def do_grant(kms, keyarn, role_arn, granttypes, mode='grant', dry_run=True, clean_invalid_entries=True):
@@ -826,7 +815,7 @@ def assert_policy_shape(policy):
'''Since the policy seems a little, uh, fragile, make sure we know approximately what we're looking at.'''
errors = []
if policy['Version'] != "2012-10-17":
errors.append('Unknown version/date ({}) of policy. Things are probably different than we assumed they were.'.format(policy['Version']))
errors.append('Unknown version/date ({0}) of policy. Things are probably different than we assumed they were.'.format(policy['Version']))
found_statement_type = {}
for statement in policy['Statement']:
@@ -836,10 +825,10 @@ def assert_policy_shape(policy):
for statementtype in statement_label.keys():
if not found_statement_type.get(statementtype):
errors.append('Policy is missing {}.'.format(statementtype))
errors.append('Policy is missing {0}.'.format(statementtype))
if len(errors):
raise Exception('Problems asserting policy shape. Cowardly refusing to modify it: {}'.format(' '.join(errors)))
raise Exception('Problems asserting policy shape. Cowardly refusing to modify it: {0}'.format(' '.join(errors)))
return None
@@ -881,13 +870,13 @@ def main():
if module.params['role_name'] and not module.params['role_arn']:
module.params['role_arn'] = get_arn_from_role_name(iam, module.params['role_name'])
if not module.params['role_arn']:
module.fail_json(msg='role_arn or role_name is required to {}'.format(module.params['mode']))
module.fail_json(msg='role_arn or role_name is required to {0}'.format(module.params['mode']))
# check the grant types for 'grant' only.
if mode == 'grant':
for g in module.params['grant_types']:
if g not in statement_label:
module.fail_json(msg='{} is an unknown grant type.'.format(g))
module.fail_json(msg='{0} is an unknown grant type.'.format(g))
ret = do_grant(kms, module.params['key_arn'], module.params['role_arn'], module.params['grant_types'],
mode=mode,

View File

@@ -1,4 +1,6 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Copyright: Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
@@ -227,7 +229,7 @@ def _find_address_by_ip(ec2, public_ip):
try:
return ec2.get_all_addresses([public_ip])[0]
except boto.exception.EC2ResponseError as e:
if "Address '{}' not found.".format(public_ip) not in e.message:
if "Address '{0}' not found.".format(public_ip) not in e.message:
raise

View File

@@ -1,4 +1,6 @@
#!/usr/bin/python
# -*- coding: utf-8 -*
# Copyright: Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
@@ -191,8 +193,8 @@ class EcsEcr:
if registry_id:
default_registry_id = self.sts.get_caller_identity().get('Account')
if registry_id != default_registry_id:
raise Exception('Cannot create repository in registry {}.'
'Would be created in {} instead.'.format(
raise Exception('Cannot create repository in registry {0}.'
'Would be created in {1} instead.'.format(
registry_id, default_registry_id))
if not self.check_mode:
repo = self.ecr.create_repository(repositoryName=name).get('repository')
@@ -216,9 +218,9 @@ class EcsEcr:
if self.get_repository(registry_id, name) is None:
printable = name
if registry_id:
printable = '{}:{}'.format(registry_id, name)
printable = '{0}:{1}'.format(registry_id, name)
raise Exception(
'could not find repository {}'.format(printable))
'could not find repository {0}'.format(printable))
return
def delete_repository(self, registry_id, name):

View File

@@ -1,7 +1,7 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# (c) 2014, Michael J. Schultz <mjschultz@gmail.com>
# Copyright: (c) 2014, Michael J. Schultz <mjschultz@gmail.com>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function
@@ -135,7 +135,7 @@ from ansible.module_utils.aws.core import AnsibleAWSModule
def arn_topic_lookup(module, client, short_topic):
lookup_topic = ':{}'.format(short_topic)
lookup_topic = ':{0}'.format(short_topic)
try:
paginator = client.get_paginator('list_topics')
@@ -206,7 +206,7 @@ def main():
sns_kwargs['TopicArn'] = arn_topic_lookup(module, client, topic)
if not sns_kwargs['TopicArn']:
module.fail_json(msg='Could not find topic: {}'.format(topic))
module.fail_json(msg='Could not find topic: {0}'.format(topic))
if sns_kwargs['MessageStructure'] == 'json':
sns_kwargs['Message'] = json.dumps(dict_msg)