Enable additional pylint rules and resolve issues found. (#47221)

* Resolve unneeded-not.
* Resolve global-at-module-level.
* Resolve useless-import-alias.
* Resolve bad-whitespace.
* Resolve global-variable-not-assigned.
* Resolve logging-not-lazy.
* Resolve comparison-with-itself.
This commit is contained in:
Matt Clay
2018-10-18 13:38:08 -07:00
committed by GitHub
parent 77d32b8f57
commit 37b013aca3
29 changed files with 42 additions and 53 deletions

View File

@@ -69,7 +69,7 @@ def check_aos_version(module, min=False):
import apstra.aosom
AOS_PYEZ_VERSION = apstra.aosom.__version__
if not LooseVersion(AOS_PYEZ_VERSION) >= LooseVersion(min):
if LooseVersion(AOS_PYEZ_VERSION) < LooseVersion(min):
module.fail_json(msg='aos-pyez >= %s is required for this module' % min)
return True

View File

@@ -129,7 +129,7 @@ def load_configuration(module, candidate=None, action='merge', rollback=None, fo
module.fail_json(msg='invalid action for format json')
elif format in ('text', 'xml') and action not in ACTIONS:
module.fail_json(msg='invalid action format %s' % format)
if action == 'set' and not format == 'text':
if action == 'set' and format != 'text':
module.fail_json(msg='format must be text when action is set')
conn = get_connection(module)

View File

@@ -209,7 +209,7 @@ def do_grant(kms, keyarn, role_arn, granttypes, mode='grant', dry_run=True, clea
ret['new_policy'] = policy
if dry_run:
# true if changes > 0
ret['changed'] = (not len(changes_needed) == 0)
ret['changed'] = len(changes_needed) > 0
return ret

View File

@@ -363,7 +363,7 @@ def main():
# The server could be in a changeing or error state.
# Wait for one of the allowed states before doing anything.
# If an allowed state can't be reached, this module fails.
if not server.info['state'] in ALLOWED_STATES:
if server.info['state'] not in ALLOWED_STATES:
server.wait_for_state(ALLOWED_STATES)
current_state = server.info['state']

View File

@@ -316,7 +316,6 @@ RHEV_UNAVAILABLE = 2
RHEV_TYPE_OPTS = ['server', 'desktop', 'host']
STATE_OPTS = ['ping', 'present', 'absent', 'up', 'down', 'restart', 'cd', 'info']
global msg, changed, failed
msg = []
changed = False
failed = False

View File

@@ -228,7 +228,7 @@ try:
# Import PubNub BLOCKS client.
from pubnub_blocks_client import User, Account, Owner, Application, Keyset
from pubnub_blocks_client import Block, EventHandler
import pubnub_blocks_client.exceptions as exceptions
from pubnub_blocks_client import exceptions
HAS_PUBNUB_BLOCKS_CLIENT = True
except ImportError:
HAS_PUBNUB_BLOCKS_CLIENT = False

View File

@@ -376,7 +376,7 @@ def absent_strategy(compute_api, wished_server):
return changed, {"status": "Server %s would be made absent." % target_server["id"]}
# A server MUST be stopped to be deleted.
while not fetch_state(compute_api=compute_api, server=target_server) == "stopped":
while fetch_state(compute_api=compute_api, server=target_server) != "stopped":
wait_to_complete_state_transition(compute_api=compute_api, server=target_server)
response = stop_server(compute_api=compute_api, server=target_server)

View File

@@ -370,7 +370,7 @@ def main():
if proxysql_schedule.state == "present":
try:
if not proxysql_schedule.check_schedule_config(cursor) > 0:
if proxysql_schedule.check_schedule_config(cursor) <= 0:
proxysql_schedule.create_schedule(module.check_mode,
result,
cursor)

View File

@@ -343,11 +343,11 @@ def main():
module.params["minor_release"],
module.params["patch_release"],
module.params["adom"])
if not results[0] == 0:
if results[0] != 0:
module.fail_json(msg="Create model failed", **results)
results = update_flags(fmg, module.params["name"])
if not results[0] == 0:
if results[0] != 0:
module.fail_json(msg="Update device flags failed", **results)
# results = assign_dev_grp(fmg, 'Ansible', 'FGVM000000117992', 'root', 'root')
@@ -355,11 +355,11 @@ def main():
# module.fail_json(msg="Setting device group failed", **results)
results = update_install_target(fmg, module.params["name"], module.params["policy_package"])
if not results[0] == 0:
if results[0] != 0:
module.fail_json(msg="Adding device target to package failed", **results)
results = install_pp(fmg, module.params["name"], module.params["policy_package"])
if not results[0] == 0:
if results[0] != 0:
module.fail_json(msg="Installing policy package failed", **results)
fmg.logout()

View File

@@ -249,18 +249,18 @@ def main():
# if state is present (default), then add the script
if state == "present":
results = set_script(fmg, script_name, script_type, script_content, script_description, script_target, adom)
if not results[0] == 0:
if results[0] != 0:
if isinstance(results[1], list):
module.fail_json(msg="Adding Script Failed", **results)
else:
module.fail_json(msg="Adding Script Failed")
elif state == "execute":
results = execute_script(fmg, script_name, script_scope, script_package, adom, vdom)
if not results[0] == 0:
if results[0] != 0:
module.fail_json(msg="Script Execution Failed", **results)
elif state == "delete":
results = delete_script(fmg, script_name, adom)
if not results[0] == 0:
if results[0] != 0:
module.fail_json(msg="Script Deletion Failed", **results)
fmg.logout()

View File

@@ -483,7 +483,6 @@ FACT_SUBSETS = dict(
VALID_SUBSETS = frozenset(FACT_SUBSETS.keys())
global warnings
warnings = list()

View File

@@ -363,7 +363,6 @@ FACT_SUBSETS = dict(
VALID_SUBSETS = frozenset(FACT_SUBSETS.keys())
global warnings
warnings = list()

View File

@@ -247,7 +247,6 @@ class GitLabUser(object):
def main():
global user_id
module = AnsibleModule(
argument_spec=dict(
server_url=dict(required=True),

View File

@@ -264,11 +264,11 @@ class NetAppCDOTLicense(object):
codes.add_new_child('license-code-v2', str_value)
# Remove requested licenses.
if not len(remove_list) == 0:
if len(remove_list) != 0:
self.remove_licenses(remove_list)
# Add requested licenses
if not len(codes.get_children()) == 0:
if len(codes.get_children()) != 0:
license_add.add_child_elem(codes)
try:
self.server.invoke_successfully(license_add,
@@ -284,7 +284,7 @@ class NetAppCDOTLicense(object):
self.update_licenses()
new_license_status = self.get_licensing_status()
if not license_status == new_license_status:
if license_status != new_license_status:
changed = True
self.module.exit_json(changed=changed)

View File

@@ -550,7 +550,7 @@ class MgmtInterface(object):
url_address_info = socket.getaddrinfo(iface["address"], 8443)
update_used_matching_address = any(info in url_address_info for info in address_info)
self._logger.info("update_used_matching_address: " + str(update_used_matching_address))
self._logger.info("update_used_matching_address: %s", update_used_matching_address)
# Populate the body of the request and check for changes
if self.enable_interface is not None:

View File

@@ -698,7 +698,7 @@ def main():
changed = True
# no changes to env/job, but existing crontab needs a terminating newline
if not changed and not crontab.existing == '':
if not changed and crontab.existing != '':
if not (crontab.existing.endswith('\r') or crontab.existing.endswith('\n')):
changed = True

View File

@@ -24,7 +24,7 @@ import os
# Note, sha1 is the only hash algorithm compatible with python2.4 and with
# FIPS-140 mode (as of 11-2014)
try:
from hashlib import sha1 as sha1
from hashlib import sha1
except ImportError:
from sha import sha as sha1