From 48eeab8a5374ac9a84d337f892b2bb85089cf83b Mon Sep 17 00:00:00 2001 From: Matt Clay Date: Thu, 6 Apr 2017 16:58:16 -0700 Subject: [PATCH] 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. --- contrib/inventory/docker.py | 2 +- contrib/inventory/linode.py | 2 +- lib/ansible/module_utils/aos.py | 4 ++-- lib/ansible/module_utils/basic.py | 2 +- lib/ansible/module_utils/docker_common.py | 2 +- lib/ansible/modules/cloud/amazon/cloudformation.py | 2 +- lib/ansible/modules/cloud/azure/azure.py | 2 +- .../modules/cloud/azure/azure_rm_networkinterface_facts.py | 2 +- lib/ansible/modules/cloud/azure/azure_rm_resourcegroup.py | 3 +-- lib/ansible/modules/cloud/azure/azure_rm_virtualmachine.py | 5 ++--- lib/ansible/modules/cloud/misc/rhevm.py | 4 ++-- lib/ansible/modules/cloud/openstack/os_stack.py | 2 +- lib/ansible/playbook/become.py | 2 +- lib/ansible/plugins/lookup/consul_kv.py | 2 +- test/sanity/pylint/disable.txt | 6 ------ 15 files changed, 17 insertions(+), 25 deletions(-) diff --git a/contrib/inventory/docker.py b/contrib/inventory/docker.py index cc7b61e6d2f..da051dd4118 100755 --- a/contrib/inventory/docker.py +++ b/contrib/inventory/docker.py @@ -525,7 +525,7 @@ class AnsibleDockerClient(Client): 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. " \ "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("SSL Exception: %s" % (error)) diff --git a/contrib/inventory/linode.py b/contrib/inventory/linode.py index 1f54ba605bc..6fd922fa6a9 100755 --- a/contrib/inventory/linode.py +++ b/contrib/inventory/linode.py @@ -197,7 +197,7 @@ class LinodeInventory(object): try: return Linode.find(api_id=linode_id) 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): """Creates self._datacenter_cache, containing all Datacenters indexed by ID.""" diff --git a/lib/ansible/module_utils/aos.py b/lib/ansible/module_utils/aos.py index 806e5194d2c..42c60b8bb37 100644 --- a/lib/ansible/module_utils/aos.py +++ b/lib/ansible/module_utils/aos.py @@ -135,11 +135,11 @@ def content_to_dict(module, content): content_dict = yaml.safe_load(content) if not isinstance(content_dict, dict): - raise + raise Exception() # Check if dict is empty and return an error if it's if not content_dict: - raise + raise Exception() except: module.fail_json(msg="Unable to convert 'content' to a dict, please check if valid") diff --git a/lib/ansible/module_utils/basic.py b/lib/ansible/module_utils/basic.py index af26d81ee47..fb1f6f5130c 100644 --- a/lib/ansible/module_utils/basic.py +++ b/lib/ansible/module_utils/basic.py @@ -1882,7 +1882,7 @@ class AnsibleModule(object): try: cwd = os.getcwd() if not os.access(cwd, os.F_OK|os.R_OK): - raise + raise Exception() return cwd except: # we don't have access to the cwd, probably because of sudo. diff --git a/lib/ansible/module_utils/docker_common.py b/lib/ansible/module_utils/docker_common.py index bdf64d0cfdd..c143b2b2c64 100644 --- a/lib/ansible/module_utils/docker_common.py +++ b/lib/ansible/module_utils/docker_common.py @@ -330,7 +330,7 @@ class AnsibleDockerClient(Client): 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. " \ "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("SSL Exception: %s" % (error)) diff --git a/lib/ansible/modules/cloud/amazon/cloudformation.py b/lib/ansible/modules/cloud/amazon/cloudformation.py index 6ad843e641e..529ac575c31 100644 --- a/lib/ansible/modules/cloud/amazon/cloudformation.py +++ b/lib/ansible/modules/cloud/amazon/cloudformation.py @@ -372,7 +372,7 @@ def get_stack_facts(cfn, stack_name): #except AmazonCloudFormationException as e: except (botocore.exceptions.ValidationError,botocore.exceptions.ClientError) as 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. return None diff --git a/lib/ansible/modules/cloud/azure/azure.py b/lib/ansible/modules/cloud/azure/azure.py index a5a7b5542fd..a1fd362825c 100644 --- a/lib/ansible/modules/cloud/azure/azure.py +++ b/lib/ansible/modules/cloud/azure/azure.py @@ -305,7 +305,7 @@ def _delete_disks_when_detached(azure, wait_timeout, disk_names): azure.delete_disk(disk.name, True) disk_names.remove(disk_name) 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: signal.alarm(0) diff --git a/lib/ansible/modules/cloud/azure/azure_rm_networkinterface_facts.py b/lib/ansible/modules/cloud/azure/azure_rm_networkinterface_facts.py index 2428a2aea26..5251ae47911 100644 --- a/lib/ansible/modules/cloud/azure/azure_rm_networkinterface_facts.py +++ b/lib/ansible/modules/cloud/azure/azure_rm_networkinterface_facts.py @@ -211,7 +211,7 @@ class AzureRMNetworkInterfaceFacts(AzureRMModuleBase): try: response = self.network_client.network_interfaces.list_all() 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 = [] for item in response: diff --git a/lib/ansible/modules/cloud/azure/azure_rm_resourcegroup.py b/lib/ansible/modules/cloud/azure/azure_rm_resourcegroup.py index c7eac4f346d..64330847fc1 100644 --- a/lib/ansible/modules/cloud/azure/azure_rm_resourcegroup.py +++ b/lib/ansible/modules/cloud/azure/azure_rm_resourcegroup.py @@ -200,8 +200,7 @@ class AzureRMResourceGroup(AzureRMModuleBase): # Create resource group self.log("Creating resource group {0}".format(self.name)) if not self.location: - self.fail("Parameter error: location is required when creating a resource " - "group.".format(self.name)) + self.fail("Parameter error: location is required when creating a resource group.") if self.name_exists(): self.fail("Error: a resource group with the name {0} already exists in your subscription." .format(self.name)) diff --git a/lib/ansible/modules/cloud/azure/azure_rm_virtualmachine.py b/lib/ansible/modules/cloud/azure/azure_rm_virtualmachine.py index b32cbd03254..053a103cea8 100644 --- a/lib/ansible/modules/cloud/azure/azure_rm_virtualmachine.py +++ b/lib/ansible/modules/cloud/azure/azure_rm_virtualmachine.py @@ -688,8 +688,7 @@ class AzureRMVirtualMachine(AzureRMModuleBase): except CloudError: self.log('Virtual machine {0} does not exist'.format(self.name)) if self.state == 'present': - self.log("CHANGED: virtual machine does not exist but state is present." \ - .format(self.name)) + self.log("CHANGED: virtual machine {0} does not exist but state is 'present'.".format(self.name)) changed = True 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') return vm 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): ''' diff --git a/lib/ansible/modules/cloud/misc/rhevm.py b/lib/ansible/modules/cloud/misc/rhevm.py index 36741a3ffc4..b742ba7ec1d 100644 --- a/lib/ansible/modules/cloud/misc/rhevm.py +++ b/lib/ansible/modules/cloud/misc/rhevm.py @@ -449,7 +449,7 @@ class RHEVConn(object): currentdisk = VM.disks.get(name=diskname) if attempt == 100: setMsg("Error, disk %s, state %s" % (diskname, str(currentdisk.status.state))) - raise + raise Exception() else: attempt += 1 time.sleep(2) @@ -489,7 +489,7 @@ class RHEVConn(object): currentnic = VM.nics.get(name=nicname) if attempt == 100: setMsg("Error, iface %s, state %s" % (nicname, str(currentnic.active))) - raise + raise Exception() else: attempt += 1 time.sleep(2) diff --git a/lib/ansible/modules/cloud/openstack/os_stack.py b/lib/ansible/modules/cloud/openstack/os_stack.py index 858dff55689..c466e935dd4 100644 --- a/lib/ansible/modules/cloud/openstack/os_stack.py +++ b/lib/ansible/modules/cloud/openstack/os_stack.py @@ -178,7 +178,7 @@ def _create_stack(module, stack, cloud): return stack else: 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: module.fail_json(msg=str(e)) diff --git a/lib/ansible/playbook/become.py b/lib/ansible/playbook/become.py index 69a87bfe588..1ad5fbadd18 100644 --- a/lib/ansible/playbook/become.py +++ b/lib/ansible/playbook/become.py @@ -38,7 +38,7 @@ class Become: _become_flags = FieldAttribute(isa='string') def __init__(self): - return super(Become, self).__init__() + super(Become, self).__init__() def _detect_privilege_escalation_conflict(self, ds): diff --git a/lib/ansible/plugins/lookup/consul_kv.py b/lib/ansible/plugins/lookup/consul_kv.py index 27cf3dbef38..c6d12d31c59 100644 --- a/lib/ansible/plugins/lookup/consul_kv.py +++ b/lib/ansible/plugins/lookup/consul_kv.py @@ -125,7 +125,7 @@ class LookupModule(LookupBase): for param in params[1:]: if param and len(param) > 0: 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 except (ValueError, AssertionError) as e: raise AnsibleError(e) diff --git a/test/sanity/pylint/disable.txt b/test/sanity/pylint/disable.txt index 82410745876..55c2238f73e 100644 --- a/test/sanity/pylint/disable.txt +++ b/test/sanity/pylint/disable.txt @@ -1,13 +1,11 @@ access-member-before-definition assignment-from-no-return -bad-format-character C function-redefined import-error locally-disabled locally-enabled method-hidden -misplaced-bare-raise no-member no-name-in-module no-value-for-parameter @@ -17,11 +15,7 @@ not-callable R raising-bad-type raising-non-exception -return-in-init -too-few-format-args -too-many-format-args too-many-function-args -truncated-format-string undefined-variable unexpected-keyword-arg unsubscriptable-object