Fix W504 and remove exclusion

This is a topic where there are two points of view. While neither
is fundamentally better than the other in reality, what's best is
to not have any arguments about it. The tox.ini comments about 503
and 504 that were in place make the argument that:

  - 503 is intended to be disabled and 504 enabled by default
  - Donald Knuth believes 504 is the right way

Since Donald Knuth is smarter than all of us, align with 504, match
the comments in the file and turn on enforcement to keep it that way.

Change-Id: I92d4d1e82935e30ae42a0e14e641cbe36fd6e811
This commit is contained in:
Monty Taylor 2020-02-27 09:21:21 -06:00
parent 72ba76f156
commit 92d7d7caeb
13 changed files with 96 additions and 54 deletions

View File

@ -184,8 +184,10 @@ class InventoryModule(BaseInventoryPlugin, Constructable, Cacheable):
if not source_data: if not source_data:
clouds_yaml_path = self._config_data.get('clouds_yaml_path') clouds_yaml_path = self._config_data.get('clouds_yaml_path')
if clouds_yaml_path: if clouds_yaml_path:
config_files = (clouds_yaml_path + config_files = (
client_config.CONFIG_FILES) clouds_yaml_path
+ client_config.CONFIG_FILES
)
else: else:
config_files = None config_files = None

View File

@ -185,10 +185,12 @@ def main():
network_id = None network_id = None
# check if we have floating ip on given nat_destination network # check if we have floating ip on given nat_destination network
if nat_destination: if nat_destination:
nat_floating_addrs = [addr for addr in server.addresses.get( nat_floating_addrs = [
cloud.get_network(nat_destination)['name'], []) addr for addr in server.addresses.get(
if addr['addr'] == public_ip and cloud.get_network(nat_destination)['name'], [])
addr['OS-EXT-IPS:type'] == 'floating'] if addr['addr'] == public_ip
and addr['OS-EXT-IPS:type'] == 'floating'
]
if len(nat_floating_addrs) == 0: if len(nat_floating_addrs) == 0:
module.fail_json(msg="server {server} already has a " module.fail_json(msg="server {server} already has a "

View File

@ -240,13 +240,17 @@ def main():
if not HAS_JSONPATCH: if not HAS_JSONPATCH:
module.fail_json(msg='jsonpatch is required for this module') module.fail_json(msg='jsonpatch is required for this module')
if (module.params['auth_type'] in [None, 'None'] and if (
module.params['ironic_url'] is None): module.params['auth_type'] in [None, 'None']
and module.params['ironic_url'] is None
):
module.fail_json(msg="Authentication appears to be disabled, " module.fail_json(msg="Authentication appears to be disabled, "
"Please define an ironic_url parameter") "Please define an ironic_url parameter")
if (module.params['ironic_url'] and if (
module.params['auth_type'] in [None, 'None']): module.params['ironic_url']
and module.params['auth_type'] in [None, 'None']
):
module.params['auth'] = dict( module.params['auth'] = dict(
endpoint=module.params['ironic_url'] endpoint=module.params['ironic_url']
) )

View File

@ -106,13 +106,17 @@ def main():
module_kwargs = openstack_module_kwargs() module_kwargs = openstack_module_kwargs()
module = AnsibleModule(argument_spec, **module_kwargs) module = AnsibleModule(argument_spec, **module_kwargs)
if (module.params['auth_type'] in [None, 'None'] and if (
module.params['ironic_url'] is None): module.params['auth_type'] in [None, 'None']
and module.params['ironic_url'] is None
):
module.fail_json(msg="Authentication appears to be disabled, " module.fail_json(msg="Authentication appears to be disabled, "
"Please define an ironic_url parameter") "Please define an ironic_url parameter")
if (module.params['ironic_url'] and if (
module.params['auth_type'] in [None, 'None']): module.params['ironic_url']
and module.params['auth_type'] in [None, 'None']
):
module.params['auth'] = dict( module.params['auth'] = dict(
endpoint=module.params['ironic_url'] endpoint=module.params['ironic_url']
) )

View File

@ -194,11 +194,15 @@ def _check_set_power_state(module, cloud, node):
cloud.set_machine_power_off(node['uuid']) cloud.set_machine_power_off(node['uuid'])
module.exit_json(changed=True, msg="Power requested off") module.exit_json(changed=True, msg="Power requested off")
if 'power off' in str(node['power_state']): if 'power off' in str(node['power_state']):
if (_is_false(module.params['power']) and if (
_is_false(module.params['state'])): _is_false(module.params['power'])
and _is_false(module.params['state'])
):
return False return False
if (_is_false(module.params['power']) and if (
_is_false(module.params['state'])): _is_false(module.params['power'])
and _is_false(module.params['state'])
):
module.exit_json( module.exit_json(
changed=False, changed=False,
msg="Power for node is %s, node must be reactivated " msg="Power for node is %s, node must be reactivated "
@ -207,8 +211,10 @@ def _check_set_power_state(module, cloud, node):
# In the event the power has been toggled on and # In the event the power has been toggled on and
# deployment has been requested, we need to skip this # deployment has been requested, we need to skip this
# step. # step.
if (_is_true(module.params['power']) and if (
_is_false(module.params['deploy'])): _is_true(module.params['power'])
and _is_false(module.params['deploy'])
):
# Node is powered down when it is not awaiting to be provisioned # Node is powered down when it is not awaiting to be provisioned
cloud.set_machine_power_on(node['uuid']) cloud.set_machine_power_on(node['uuid'])
return True return True
@ -234,19 +240,25 @@ def main():
module_kwargs = openstack_module_kwargs() module_kwargs = openstack_module_kwargs()
module = AnsibleModule(argument_spec, **module_kwargs) module = AnsibleModule(argument_spec, **module_kwargs)
if (module.params['auth_type'] in [None, 'None'] and if (
module.params['ironic_url'] is None): module.params['auth_type'] in [None, 'None']
and module.params['ironic_url'] is None
):
module.fail_json(msg="Authentication appears disabled, Please " module.fail_json(msg="Authentication appears disabled, Please "
"define an ironic_url parameter") "define an ironic_url parameter")
if (module.params['ironic_url'] and if (
module.params['auth_type'] in [None, 'None']): module.params['ironic_url']
and module.params['auth_type'] in [None, 'None']
):
module.params['auth'] = dict( module.params['auth'] = dict(
endpoint=module.params['ironic_url'] endpoint=module.params['ironic_url']
) )
if (module.params['config_drive'] and if (
not isinstance(module.params['config_drive'], (str, dict))): module.params['config_drive']
and not isinstance(module.params['config_drive'], (str, dict))
):
config_drive_type = type(module.params['config_drive']) config_drive_type = type(module.params['config_drive'])
msg = ('argument config_drive is of type %s and we expected' msg = ('argument config_drive is of type %s and we expected'
' str or dict') % config_drive_type ' str or dict') % config_drive_type

View File

@ -76,10 +76,12 @@ def _needs_update(module, aggregate):
if module.params['availability_zone'] is not None: if module.params['availability_zone'] is not None:
new_metadata['availability_zone'] = module.params['availability_zone'] new_metadata['availability_zone'] = module.params['availability_zone']
if ((module.params['name'] != aggregate.name) or if (
(module.params['hosts'] is not None and set(module.params['hosts']) != set(aggregate.hosts)) or (module.params['name'] != aggregate.name)
(module.params['availability_zone'] is not None and module.params['availability_zone'] != aggregate.availability_zone) or or (module.params['hosts'] is not None and set(module.params['hosts']) != set(aggregate.hosts))
(module.params['metadata'] is not None and new_metadata != aggregate.metadata)): or (module.params['availability_zone'] is not None and module.params['availability_zone'] != aggregate.availability_zone)
or (module.params['metadata'] is not None and new_metadata != aggregate.metadata)
):
return True return True
return False return False

View File

@ -252,8 +252,10 @@ def _needs_update(module, port, cloud):
if module.params[key] is not None and module.params[key] != port[key]: if module.params[key] is not None and module.params[key] != port[key]:
return True return True
for key in compare_list: for key in compare_list:
if module.params[key] is not None and (set(module.params[key]) != if (
set(port[key])): module.params[key] is not None
and set(module.params[key]) != set(port[key])
):
return True return True
for key in compare_list_dict: for key in compare_list_dict:

View File

@ -223,9 +223,13 @@ def _ports_match(protocol, module_min, module_max, rule_min, rule_max):
module_min = None module_min = None
module_max = None module_max = None
if ((module_min is None and module_max is None) and if (
(rule_min and int(rule_min) == 1 and (module_min is None and module_max is None)
rule_max and int(rule_max) == 65535)): and (
rule_min and int(rule_min) == 1
and rule_max and int(rule_max) == 65535
)
):
# (None, None) == (1, 65535) # (None, None) == (1, 65535)
return True return True
@ -254,16 +258,19 @@ def _find_matching_rule(module, secgroup, remotegroup):
remote_group_id = remotegroup['id'] remote_group_id = remotegroup['id']
for rule in secgroup['security_group_rules']: for rule in secgroup['security_group_rules']:
if (protocol == rule['protocol'] and if (
remote_ip_prefix == rule['remote_ip_prefix'] and protocol == rule['protocol']
ethertype == rule['ethertype'] and and remote_ip_prefix == rule['remote_ip_prefix']
direction == rule['direction'] and and ethertype == rule['ethertype']
remote_group_id == rule['remote_group_id'] and and direction == rule['direction']
_ports_match(protocol, and remote_group_id == rule['remote_group_id']
module.params['port_range_min'], and _ports_match(
module.params['port_range_max'], protocol,
rule['port_range_min'], module.params['port_range_min'],
rule['port_range_max'])): module.params['port_range_max'],
rule['port_range_min'],
rule['port_range_max'])
):
return rule return rule
return None return None

View File

@ -572,8 +572,10 @@ def _check_security_groups(module, cloud, server):
# server security groups were added to shade in 1.19. Until then this # server security groups were added to shade in 1.19. Until then this
# module simply ignored trying to update security groups and only set them # module simply ignored trying to update security groups and only set them
# on newly created hosts. # on newly created hosts.
if not (hasattr(cloud, 'add_server_security_groups') and if not (
hasattr(cloud, 'remove_server_security_groups')): hasattr(cloud, 'add_server_security_groups')
and hasattr(cloud, 'remove_server_security_groups')
):
return changed, server return changed, server
module_security_groups = set(module.params['security_groups']) module_security_groups = set(module.params['security_groups'])

View File

@ -272,8 +272,11 @@ def main():
if state == 'present': if state == 'present':
if not module.params['network_name']: if not module.params['network_name']:
module.fail_json(msg='network_name required with present state') module.fail_json(msg='network_name required with present state')
if (not module.params['cidr'] and not use_default_subnetpool and if (
not extra_specs.get('subnetpool_id', False)): not module.params['cidr']
and not use_default_subnetpool
and not extra_specs.get('subnetpool_id', False)
):
module.fail_json(msg='cidr or use_default_subnetpool or ' module.fail_json(msg='cidr or use_default_subnetpool or '
'subnetpool_id required with present state') 'subnetpool_id required with present state')

View File

@ -150,8 +150,10 @@ def _needs_update(params_dict, user):
# We don't get password back in the user object, so assume any supplied # We don't get password back in the user object, so assume any supplied
# password is a change. # password is a change.
if (params_dict['password'] is not None and if (
params_dict['update_password'] == 'always'): params_dict['password'] is not None
and params_dict['update_password'] == 'always'
):
return True return True
return False return False

View File

@ -106,8 +106,8 @@ class YamlTestUtils(object):
assert yaml_string == yaml_string_obj_from_stream assert yaml_string == yaml_string_obj_from_stream
assert yaml_string == yaml_string_obj_from_stream == yaml_string_obj_from_string assert yaml_string == yaml_string_obj_from_stream == yaml_string_obj_from_string
assert (yaml_string == yaml_string_obj_from_stream == yaml_string_obj_from_string == yaml_string_stream_obj_from_stream == assert (yaml_string == yaml_string_obj_from_stream == yaml_string_obj_from_string == yaml_string_stream_obj_from_stream
yaml_string_stream_obj_from_string) == yaml_string_stream_obj_from_string)
assert obj == obj_from_stream assert obj == obj_from_stream
assert obj == obj_from_string assert obj == obj_from_string
assert obj == yaml_string_obj_from_stream assert obj == yaml_string_obj_from_stream

View File

@ -51,7 +51,7 @@ commands = {posargs}
# H4 are rules for docstrings. Maybe we should clean them? # H4 are rules for docstrings. Maybe we should clean them?
# E501,E402,H301,H236,F401 are ignored so we can import the existing # E501,E402,H301,H236,F401 are ignored so we can import the existing
# modules unchanged and then clean them in subsequent patches. # modules unchanged and then clean them in subsequent patches.
ignore = W503,H4,E501,E402,H301,H236,F401,W504 ignore = W503,H4,E501,E402,H301,H236,F401
show-source = True show-source = True
exclude=.venv,.git,.tox,dist,doc,*lib/python*,*egg,build,ansible_collections exclude=.venv,.git,.tox,dist,doc,*lib/python*,*egg,build,ansible_collections