Fix errors reported by pylint. (#23282)

* Fix pylint misplaced-bare-raise errors.
* Fix pylint return-in-init error.
* Fix pylint bad-format-character error.
* Fix pylint too-many-format-args errors.
* Fix pylint too-few-format-args errors.
* Fix pylint truncated-format-string error.
pull/23381/head
Matt Clay 8 years ago committed by GitHub
parent 9e1bf1c6f2
commit 48eeab8a53

@ -525,7 +525,7 @@ class AnsibleDockerClient(Client):
msg = "You asked for verification that Docker host name matches %s. The actual hostname is %s. " \ msg = "You asked for verification that Docker host name matches %s. The actual hostname is %s. " \
"Most likely you need to set DOCKER_TLS_HOSTNAME or pass tls_hostname with a value of %s. " \ "Most likely you need to set DOCKER_TLS_HOSTNAME or pass tls_hostname with a value of %s. " \
"You may also use TLS without verification by setting the tls parameter to true." \ "You may also use TLS without verification by setting the tls parameter to true." \
% (self.auth_params['tls_hostname'], match.group(1)) % (self.auth_params['tls_hostname'], match.group(1), match.group(1))
self.fail(msg) self.fail(msg)
self.fail("SSL Exception: %s" % (error)) self.fail("SSL Exception: %s" % (error))

@ -197,7 +197,7 @@ class LinodeInventory(object):
try: try:
return Linode.find(api_id=linode_id) return Linode.find(api_id=linode_id)
except chube_api.linode_api.ApiError as e: except chube_api.linode_api.ApiError as e:
sys.exit("Looks like Linode's API is down:\n%" % e) sys.exit("Looks like Linode's API is down:\n%s" % e)
def populate_datacenter_cache(self): def populate_datacenter_cache(self):
"""Creates self._datacenter_cache, containing all Datacenters indexed by ID.""" """Creates self._datacenter_cache, containing all Datacenters indexed by ID."""

@ -135,11 +135,11 @@ def content_to_dict(module, content):
content_dict = yaml.safe_load(content) content_dict = yaml.safe_load(content)
if not isinstance(content_dict, dict): if not isinstance(content_dict, dict):
raise raise Exception()
# Check if dict is empty and return an error if it's # Check if dict is empty and return an error if it's
if not content_dict: if not content_dict:
raise raise Exception()
except: except:
module.fail_json(msg="Unable to convert 'content' to a dict, please check if valid") module.fail_json(msg="Unable to convert 'content' to a dict, please check if valid")

@ -1882,7 +1882,7 @@ class AnsibleModule(object):
try: try:
cwd = os.getcwd() cwd = os.getcwd()
if not os.access(cwd, os.F_OK|os.R_OK): if not os.access(cwd, os.F_OK|os.R_OK):
raise raise Exception()
return cwd return cwd
except: except:
# we don't have access to the cwd, probably because of sudo. # we don't have access to the cwd, probably because of sudo.

@ -330,7 +330,7 @@ class AnsibleDockerClient(Client):
msg = "You asked for verification that Docker host name matches %s. The actual hostname is %s. " \ msg = "You asked for verification that Docker host name matches %s. The actual hostname is %s. " \
"Most likely you need to set DOCKER_TLS_HOSTNAME or pass tls_hostname with a value of %s. " \ "Most likely you need to set DOCKER_TLS_HOSTNAME or pass tls_hostname with a value of %s. " \
"You may also use TLS without verification by setting the tls parameter to true." \ "You may also use TLS without verification by setting the tls parameter to true." \
% (self.auth_params['tls_hostname'], match.group(1)) % (self.auth_params['tls_hostname'], match.group(1), match.group(1))
self.fail(msg) self.fail(msg)
self.fail("SSL Exception: %s" % (error)) self.fail("SSL Exception: %s" % (error))

@ -372,7 +372,7 @@ def get_stack_facts(cfn, stack_name):
#except AmazonCloudFormationException as e: #except AmazonCloudFormationException as e:
except (botocore.exceptions.ValidationError,botocore.exceptions.ClientError) as err: except (botocore.exceptions.ValidationError,botocore.exceptions.ClientError) as err:
error_msg = boto_exception(err) error_msg = boto_exception(err)
if 'does not exist'.format(stack_name) in error_msg: if 'does not exist' in error_msg:
# missing stack, don't bail. # missing stack, don't bail.
return None return None

@ -305,7 +305,7 @@ def _delete_disks_when_detached(azure, wait_timeout, disk_names):
azure.delete_disk(disk.name, True) azure.delete_disk(disk.name, True)
disk_names.remove(disk_name) disk_names.remove(disk_name)
except AzureException as e: except AzureException as e:
module.fail_json(msg="failed to get or delete disk, error was: %s" % (disk_name, str(e))) module.fail_json(msg="failed to get or delete disk %s, error was: %s" % (disk_name, str(e)))
finally: finally:
signal.alarm(0) signal.alarm(0)

@ -211,7 +211,7 @@ class AzureRMNetworkInterfaceFacts(AzureRMModuleBase):
try: try:
response = self.network_client.network_interfaces.list_all() response = self.network_client.network_interfaces.list_all()
except Exception as exc: except Exception as exc:
self.fail("Error listing all - {1}".format(self.resource_group, str(exc))) self.fail("Error listing all - {0}".format(str(exc)))
results = [] results = []
for item in response: for item in response:

@ -200,8 +200,7 @@ class AzureRMResourceGroup(AzureRMModuleBase):
# Create resource group # Create resource group
self.log("Creating resource group {0}".format(self.name)) self.log("Creating resource group {0}".format(self.name))
if not self.location: if not self.location:
self.fail("Parameter error: location is required when creating a resource " self.fail("Parameter error: location is required when creating a resource group.")
"group.".format(self.name))
if self.name_exists(): if self.name_exists():
self.fail("Error: a resource group with the name {0} already exists in your subscription." self.fail("Error: a resource group with the name {0} already exists in your subscription."
.format(self.name)) .format(self.name))

@ -688,8 +688,7 @@ class AzureRMVirtualMachine(AzureRMModuleBase):
except CloudError: except CloudError:
self.log('Virtual machine {0} does not exist'.format(self.name)) self.log('Virtual machine {0} does not exist'.format(self.name))
if self.state == 'present': if self.state == 'present':
self.log("CHANGED: virtual machine does not exist but state is present." \ self.log("CHANGED: virtual machine {0} does not exist but state is 'present'.".format(self.name))
.format(self.name))
changed = True changed = True
self.results['changed'] = changed self.results['changed'] = changed
@ -887,7 +886,7 @@ class AzureRMVirtualMachine(AzureRMModuleBase):
vm = self.compute_client.virtual_machines.get(self.resource_group, self.name, expand='instanceview') vm = self.compute_client.virtual_machines.get(self.resource_group, self.name, expand='instanceview')
return vm return vm
except Exception as exc: except Exception as exc:
self.fail("Error getting virtual machine (0) - {1}".format(self.name, str(exc))) self.fail("Error getting virtual machine {0} - {1}".format(self.name, str(exc)))
def serialize_vm(self, vm): def serialize_vm(self, vm):
''' '''

@ -449,7 +449,7 @@ class RHEVConn(object):
currentdisk = VM.disks.get(name=diskname) currentdisk = VM.disks.get(name=diskname)
if attempt == 100: if attempt == 100:
setMsg("Error, disk %s, state %s" % (diskname, str(currentdisk.status.state))) setMsg("Error, disk %s, state %s" % (diskname, str(currentdisk.status.state)))
raise raise Exception()
else: else:
attempt += 1 attempt += 1
time.sleep(2) time.sleep(2)
@ -489,7 +489,7 @@ class RHEVConn(object):
currentnic = VM.nics.get(name=nicname) currentnic = VM.nics.get(name=nicname)
if attempt == 100: if attempt == 100:
setMsg("Error, iface %s, state %s" % (nicname, str(currentnic.active))) setMsg("Error, iface %s, state %s" % (nicname, str(currentnic.active)))
raise raise Exception()
else: else:
attempt += 1 attempt += 1
time.sleep(2) time.sleep(2)

@ -178,7 +178,7 @@ def _create_stack(module, stack, cloud):
return stack return stack
else: else:
return False return False
module.fail_json(msg = "Failure in creating stack: ".format(stack)) module.fail_json(msg="Failure in creating stack: {0}".format(stack))
except shade.OpenStackCloudException as e: except shade.OpenStackCloudException as e:
module.fail_json(msg=str(e)) module.fail_json(msg=str(e))

@ -38,7 +38,7 @@ class Become:
_become_flags = FieldAttribute(isa='string') _become_flags = FieldAttribute(isa='string')
def __init__(self): def __init__(self):
return super(Become, self).__init__() super(Become, self).__init__()
def _detect_privilege_escalation_conflict(self, ds): def _detect_privilege_escalation_conflict(self, ds):

@ -125,7 +125,7 @@ class LookupModule(LookupBase):
for param in params[1:]: for param in params[1:]:
if param and len(param) > 0: if param and len(param) > 0:
name, value = param.split('=') name, value = param.split('=')
assert name in paramvals, "% not a valid consul lookup parameter" % name assert name in paramvals, "%s not a valid consul lookup parameter" % name
paramvals[name] = value paramvals[name] = value
except (ValueError, AssertionError) as e: except (ValueError, AssertionError) as e:
raise AnsibleError(e) raise AnsibleError(e)

@ -1,13 +1,11 @@
access-member-before-definition access-member-before-definition
assignment-from-no-return assignment-from-no-return
bad-format-character
C C
function-redefined function-redefined
import-error import-error
locally-disabled locally-disabled
locally-enabled locally-enabled
method-hidden method-hidden
misplaced-bare-raise
no-member no-member
no-name-in-module no-name-in-module
no-value-for-parameter no-value-for-parameter
@ -17,11 +15,7 @@ not-callable
R R
raising-bad-type raising-bad-type
raising-non-exception raising-non-exception
return-in-init
too-few-format-args
too-many-format-args
too-many-function-args too-many-function-args
truncated-format-string
undefined-variable undefined-variable
unexpected-keyword-arg unexpected-keyword-arg
unsubscriptable-object unsubscriptable-object

Loading…
Cancel
Save