sanity fixex updated

pull/156/head
KB-perByte 2022-04-04 17:58:09 +05:30
parent 66bd592df4
commit 141c175cff
No known key found for this signature in database
GPG Key ID: F49472BE1744C3D5
64 changed files with 166 additions and 202 deletions

View File

@ -10,7 +10,7 @@ repos:
args: [--branch, main]
- id: trailing-whitespace
- repo: https://github.com/psf/black
rev: 19.3b0
rev: 22.3.0
hooks:
- id: black
args: [-l, "79"]

View File

@ -177,8 +177,7 @@ def cidr_merge(value, action="merge"):
class FilterModule(object):
"""IP address and network manipulation filters
"""
"""IP address and network manipulation filters"""
filter_map = {
# IP addresses and networks

View File

@ -333,7 +333,9 @@ def _consolidate(*args, **kwargs):
]
data = dict(zip(keys, args[1:]))
data.update(kwargs)
aav = AnsibleArgSpecValidator(data=data, schema=DOCUMENTATION, name="consolidate")
aav = AnsibleArgSpecValidator(
data=data, schema=DOCUMENTATION, name="consolidate"
)
valid, errors, updated_data = aav.validate()
if not valid:
raise AnsibleFilterError(errors)

View File

@ -141,7 +141,7 @@ def _from_xml(*args, **kwargs):
class FilterModule(object):
""" from_xml """
"""from_xml"""
def filters(self):

View File

@ -180,7 +180,7 @@ def _get_path(*args, **kwargs):
class FilterModule(object):
""" path filters """
"""path filters"""
def filters(self):
return {"get_path": _get_path}

View File

@ -98,7 +98,7 @@ RETURN = """
@pass_environment
def _hwaddr(*args, **kwargs):
"""This filter check if string is a HW/MAC address and filter it """
"""This filter check if string is a HW/MAC address and filter it"""
keys = ["value", "query", "alias"]
data = dict(zip(keys, args[1:]))
data.update(kwargs)
@ -112,8 +112,7 @@ def _hwaddr(*args, **kwargs):
class FilterModule(object):
"""IP address and network manipulation filters
"""
"""IP address and network manipulation filters"""
filter_map = {
# IP addresses and networks
@ -121,7 +120,7 @@ class FilterModule(object):
}
def filters(self):
""" ipaddr filter """
"""ipaddr filter"""
if HAS_NETADDR:
return self.filter_map
else:

View File

@ -338,7 +338,7 @@ def _index_of(*args, **kwargs):
class FilterModule(object):
""" index_of """
"""index_of"""
def filters(self):
"""a mapping of filter names to functions"""

View File

@ -109,7 +109,7 @@ def _ip4_hex(*args, **kwargs):
def ip4_hex(arg, delimiter=""):
""" Convert an IPv4 address to Hexadecimal notation """
"""Convert an IPv4 address to Hexadecimal notation"""
numbers = list(map(int, arg.split(".")))
return "{0:02x}{sep}{1:02x}{sep}{2:02x}{sep}{3:02x}".format(
*numbers, sep=delimiter
@ -117,8 +117,7 @@ def ip4_hex(arg, delimiter=""):
class FilterModule(object):
"""IP address and network manipulation filters
"""
"""IP address and network manipulation filters"""
filter_map = {
# IP addresses and networks
@ -126,7 +125,7 @@ class FilterModule(object):
}
def filters(self):
""" ip4_hex filter """
"""ip4_hex filter"""
if HAS_NETADDR:
return self.filter_map
else:

View File

@ -281,8 +281,7 @@ def _ipaddr(*args, **kwargs):
class FilterModule(object):
"""IP address and network manipulation filters
"""
"""IP address and network manipulation filters"""
filter_map = {
# IP addresses and networks
@ -290,7 +289,7 @@ class FilterModule(object):
}
def filters(self):
""" ipaddr filter """
"""ipaddr filter"""
if HAS_NETADDR:
return self.filter_map
else:

View File

@ -169,8 +169,7 @@ def ipmath(value, amount):
class FilterModule(object):
"""IP address and network manipulation filters
"""
"""IP address and network manipulation filters"""
filter_map = {
# This filter is designed to do simple IP math/arithmetic
@ -178,7 +177,7 @@ class FilterModule(object):
}
def filters(self):
""" ipmath filter"""
"""ipmath filter"""
if HAS_NETADDR:
return self.filter_map
else:

View File

@ -253,7 +253,7 @@ def _ipsubnet(*args, **kwargs):
def ipsubnet(value, query="", index="x"):
""" Manipulate IPv4/IPv6 subnets """
"""Manipulate IPv4/IPv6 subnets"""
try:
vtype = ipaddr(value, "type")
@ -323,8 +323,7 @@ def ipsubnet(value, query="", index="x"):
class FilterModule(object):
"""IP address and network manipulation filters
"""
"""IP address and network manipulation filters"""
filter_map = {
# IP addresses and networks
@ -332,7 +331,7 @@ class FilterModule(object):
}
def filters(self):
""" ipsubnet filter """
"""ipsubnet filter"""
if HAS_NETADDR:
return self.filter_map
else:

View File

@ -160,8 +160,7 @@ def ipv4(value, query=""):
class FilterModule(object):
"""IP address and network manipulation filters
"""
"""IP address and network manipulation filters"""
filter_map = {
# IP addresses and networks
@ -169,7 +168,7 @@ class FilterModule(object):
}
def filters(self):
""" ipaddr filter """
"""ipaddr filter"""
if netaddr:
return self.filter_map
else:

View File

@ -178,8 +178,7 @@ def ipv6(value, query=""):
class FilterModule(object):
"""IP address and network manipulation filters
"""
"""IP address and network manipulation filters"""
filter_map = {
# IP addresses and networks
@ -187,7 +186,7 @@ class FilterModule(object):
}
def filters(self):
""" ipv6 filter """
"""ipv6 filter"""
if HAS_NETADDR:
return self.filter_map
else:

View File

@ -200,8 +200,7 @@ def ipwrap(value, query=""):
class FilterModule(object):
"""IP address and network manipulation filters
"""
"""IP address and network manipulation filters"""
filter_map = {
# IP addresses and networks
@ -209,7 +208,7 @@ class FilterModule(object):
}
def filters(self):
""" ipwrap filter """
"""ipwrap filter"""
if HAS_NETADDR:
return self.filter_map
else:

View File

@ -95,7 +95,7 @@ RETURN = """
@pass_environment
def _macaddr(*args, **kwargs):
"""This filter check if string is a HW/MAC address and filter it """
"""This filter check if string is a HW/MAC address and filter it"""
keys = ["value", "query"]
data = dict(zip(keys, args[1:]))
data.update(kwargs)
@ -113,8 +113,7 @@ def macaddr(value, query=""):
class FilterModule(object):
"""IP address and network manipulation filters
"""
"""IP address and network manipulation filters"""
filter_map = {
# IP addresses and networks
@ -122,7 +121,7 @@ class FilterModule(object):
}
def filters(self):
""" ipaddr filter """
"""ipaddr filter"""
if HAS_NETADDR:
return self.filter_map
else:

View File

@ -147,8 +147,7 @@ def network_in_network(value, test):
class FilterModule(object):
"""IP address and network manipulation filters
"""
"""IP address and network manipulation filters"""
filter_map = {
# IP addresses and networks
@ -156,7 +155,7 @@ class FilterModule(object):
}
def filters(self):
""" ipaddr filter """
"""ipaddr filter"""
if HAS_NETADDR:
return self.filter_map
else:

View File

@ -149,8 +149,7 @@ def network_in_usable(value, test):
class FilterModule(object):
"""IP address and network manipulation filters
"""
"""IP address and network manipulation filters"""
filter_map = {
# IP addresses and networks
@ -158,7 +157,7 @@ class FilterModule(object):
}
def filters(self):
""" ipaddr filter """
"""ipaddr filter"""
if HAS_NETADDR:
return self.filter_map
else:

View File

@ -137,8 +137,7 @@ def next_nth_usable(value, offset):
class FilterModule(object):
"""IP address and network manipulation filters
"""
"""IP address and network manipulation filters"""
filter_map = {
# IP addresses and networks
@ -146,7 +145,7 @@ class FilterModule(object):
}
def filters(self):
""" ipaddr filter """
"""ipaddr filter"""
if HAS_NETADDR:
return self.filter_map
else:

View File

@ -110,7 +110,7 @@ def _nthhost(*args, **kwargs):
def nthhost(value, query=""):
""" Returns the nth host within a network described by value. """
"""Returns the nth host within a network described by value."""
try:
vtype = ipaddr(value, "type")
if vtype == "address":
@ -137,8 +137,7 @@ def nthhost(value, query=""):
class FilterModule(object):
"""IP address and network manipulation filters
"""
"""IP address and network manipulation filters"""
filter_map = {
# IP addresses and networks
@ -146,7 +145,7 @@ class FilterModule(object):
}
def filters(self):
""" ipaddr filter """
"""ipaddr filter"""
if HAS_NETADDR:
return self.filter_map
else:

View File

@ -212,7 +212,7 @@ def param_list_compare(*args, **kwargs):
class FilterModule(object):
""" param_list_compare """
"""param_list_compare"""
def filters(self):
"""a mapping of filter names to functions"""

View File

@ -136,8 +136,7 @@ def previous_nth_usable(value, offset):
class FilterModule(object):
"""IP address and network manipulation filters
"""
"""IP address and network manipulation filters"""
filter_map = {
# IP addresses and networks
@ -145,7 +144,7 @@ class FilterModule(object):
}
def filters(self):
""" ipaddr filter """
"""ipaddr filter"""
if HAS_NETADDR:
return self.filter_map
else:

View File

@ -137,8 +137,7 @@ def reduce_on_network(value, network):
class FilterModule(object):
"""IP address and network manipulation filters
"""
"""IP address and network manipulation filters"""
filter_map = {
# IP addresses and networks
@ -146,7 +145,7 @@ class FilterModule(object):
}
def filters(self):
""" ipaddr filter """
"""ipaddr filter"""
if HAS_NETADDR:
return self.filter_map
else:

View File

@ -100,7 +100,7 @@ def _slaac(*args, **kwargs):
def slaac(value, query=""):
""" Get the SLAAC address within given network """
"""Get the SLAAC address within given network"""
try:
vtype = ipaddr(value, "type")
if vtype == "address":
@ -129,8 +129,7 @@ def slaac(value, query=""):
class FilterModule(object):
"""IP address and network manipulation filters
"""
"""IP address and network manipulation filters"""
filter_map = {
# IP addresses and networks
@ -138,7 +137,7 @@ class FilterModule(object):
}
def filters(self):
""" ipaddr filter """
"""ipaddr filter"""
if HAS_NETADDR:
return self.filter_map
else:

View File

@ -141,7 +141,7 @@ def _to_paths(*args, **kwargs):
class FilterModule(object):
""" path filters """
"""path filters"""
def filters(self):
return {"to_paths": _to_paths}

View File

@ -135,7 +135,7 @@ def _to_xml(*args, **kwargs):
class FilterModule(object):
""" to_xml """
"""to_xml"""
def filters(self):
"""a mapping of filter names to functions"""

View File

@ -188,7 +188,7 @@ def _usable_range(ip):
class FilterModule(object):
""" usable_range """
"""usable_range"""
def filters(self):

View File

@ -7,7 +7,7 @@ __metaclass__ = type
class CliParserBase:
""" The base class for cli parsers
"""The base class for cli parsers
Provides a _debug function to normalize parser debug output
"""

View File

@ -368,7 +368,7 @@ def _wrap_query(v, vtype, value):
def ipaddr(value, query="", version=False, alias="ipaddr"):
""" Check if string is an IP address or network and filter it """
"""Check if string is an IP address or network and filter it"""
query_func_extra_args = {
"": ("vtype",),
@ -686,7 +686,7 @@ def _win_query(v):
# ---- HWaddr / MAC address filters ----
def hwaddr(value, query="", alias="hwaddr"):
""" Check if string is a HW/MAC address and filter it """
"""Check if string is a HW/MAC address and filter it"""
query_func_extra_args = {"": ("value",)}

View File

@ -29,8 +29,7 @@ except ImportError:
def ip_network(ip):
""" PY2 compat shim, PY2 requires unicode
"""
"""PY2 compat shim, PY2 requires unicode"""
if not HAS_IPADDRESS:
raise AnsibleError(missing_required_lib("ipaddress"))
@ -39,8 +38,7 @@ def ip_network(ip):
def ip_address(ip):
""" PY2 compat shim, PY2 requires unicode
"""
"""PY2 compat shim, PY2 requires unicode"""
if not HAS_IPADDRESS:
raise AnsibleError(missing_required_lib("ipaddress"))
@ -71,8 +69,7 @@ def _is_subnet_of(network_a, network_b):
def _validate_args(plugin, doc, params):
""" argspec validator utility function
"""
"""argspec validator utility function"""
valid, argspec_result, updated_params = check_argspec(
doc, plugin + " test", **params

View File

@ -18,8 +18,7 @@ from ansible_collections.ansible.utils.plugins.module_utils.common.argspec_valid
def _validate_args(plugin, doc, params):
""" argspec validator utility function
"""
"""argspec validator utility function"""
valid, argspec_result, updated_params = check_argspec(
doc, plugin + " test", **params

View File

@ -31,9 +31,13 @@ def fail_on_filter(validator_func):
res, err = validator_func(*args, **kwargs)
if err.get("match_key_err"):
_raise_error("fail_missing_match_key", ", ".join(err["match_key_err"]))
_raise_error(
"fail_missing_match_key", ", ".join(err["match_key_err"])
)
if err.get("match_val_err"):
_raise_error("fail_missing_match_value", ", ".join(err["match_val_err"]))
_raise_error(
"fail_missing_match_value", ", ".join(err["match_val_err"])
)
if err.get("duplicate_err"):
_raise_error("fail_duplicate", ", ".join(err["duplicate_err"]))
return res
@ -67,7 +71,9 @@ def check_missing_match_key_duplicate(
continue
if sorted(set(ds_values)) != sorted(ds_values) and fail_duplicate:
errors_duplicate.append(f"Duplicate values in data source {ds_idx}")
errors_duplicate.append(
f"Duplicate values in data source {ds_idx}"
)
results.append(set(ds_values))
return results, {
"match_key_err": errors_match_key,
@ -94,7 +100,9 @@ def consolidate_facts(data_sources, all_values):
for data_source in data_sources:
match_key = data_source["match_key"]
source = data_source["prefix"]
data_dict = {d[match_key]: d for d in data_source["data"] if match_key in d}
data_dict = {
d[match_key]: d for d in data_source["data"] if match_key in d
}
for value in sorted(all_values):
if value not in consolidated_facts:
consolidated_facts[value] = {}

View File

@ -44,7 +44,7 @@ from ansible_collections.ansible.utils.plugins.plugin_utils.base.cli_parser impo
class CliParser(CliParserBase):
""" The json parser class
"""The json parser class
Convert a string containing valid json into an object
"""
@ -52,7 +52,7 @@ class CliParser(CliParserBase):
PROVIDE_TEMPLATE_CONTENTS = False
def parse(self, *_args, **_kwargs):
""" Std entry point for a cli_parse parse execution
"""Std entry point for a cli_parse parse execution
:return: Errors or parsed text as structured data
:rtype: dict

View File

@ -53,7 +53,7 @@ except ImportError:
class CliParser(CliParserBase):
""" The textfsm parser class
"""The textfsm parser class
Convert raw text to structured data using textfsm
"""
@ -62,7 +62,7 @@ class CliParser(CliParserBase):
@staticmethod
def _check_reqs():
""" Check the prerequisites for the textfsm parser
"""Check the prerequisites for the textfsm parser
:return dict: A dict with errors or a template_path
"""
@ -74,7 +74,7 @@ class CliParser(CliParserBase):
return {"errors": errors}
def parse(self, *_args, **_kwargs):
""" Std entry point for a cli_parse parse execution
"""Std entry point for a cli_parse parse execution
:return: Errors or parsed text as structured data
:rtype: dict

View File

@ -53,7 +53,7 @@ except ImportError:
class CliParser(CliParserBase):
""" The ttp parser class
"""The ttp parser class
Convert raw text to structured data using ttp
"""
@ -62,7 +62,7 @@ class CliParser(CliParserBase):
@staticmethod
def _check_reqs():
""" Check the prerequisites for the ttp parser
"""Check the prerequisites for the ttp parser
:return dict: A dict with errors or a template_path
"""
@ -74,7 +74,7 @@ class CliParser(CliParserBase):
return {"errors": errors}
def parse(self, *_args, **_kwargs):
""" Std entry point for a cli_parse parse execution
"""Std entry point for a cli_parse parse execution
:return: Errors or parsed text as structured data
:rtype: dict

View File

@ -52,7 +52,7 @@ except ImportError:
class CliParser(CliParserBase):
""" The xml parser class
"""The xml parser class
Convert an xml string to structured data using xmltodict
"""
@ -61,8 +61,7 @@ class CliParser(CliParserBase):
@staticmethod
def _check_reqs():
""" Check the prerequisites for the xml parser
"""
"""Check the prerequisites for the xml parser"""
errors = []
if not HAS_XMLTODICT:
errors.append(missing_required_lib("xmltodict"))
@ -70,7 +69,7 @@ class CliParser(CliParserBase):
return errors
def parse(self, *_args, **_kwargs):
""" Std entry point for a cli_parse parse execution
"""Std entry point for a cli_parse parse execution
:return: Errors or parsed text as structured data
:rtype: dict

View File

@ -205,9 +205,11 @@ class Validate(ValidateBase):
"found": validation_error.instance,
}
self._result["errors"].append(error)
error_message = "At '{schema_path}' {message}. ".format(
schema_path=error["schema_path"],
message=error["message"],
error_message = (
"At '{schema_path}' {message}. ".format(
schema_path=error["schema_path"],
message=error["message"],
)
)
error_messages.append(error_message)
if error_messages:

View File

@ -104,7 +104,7 @@ def _in_any_network(ip, networks):
class TestModule(object):
""" network jinja test"""
"""network jinja test"""
test_map = {"in_any_network": _in_any_network}

View File

@ -120,7 +120,7 @@ def _in_network(ip, network):
class TestModule(object):
""" network jinja test"""
"""network jinja test"""
test_map = {"in_network": _in_network}

View File

@ -103,7 +103,7 @@ def _in_one_network(ip, networks):
class TestModule(object):
""" network jinja test"""
"""network jinja test"""
test_map = {"in_one_network": _in_one_network}

View File

@ -114,7 +114,7 @@ RETURN = """
@_need_ipaddress
def _ip(ip):
""" Test if something in an IP address or network """
"""Test if something in an IP address or network"""
params = {"ip": ip}
_validate_args("ip", DOCUMENTATION, params)
@ -127,7 +127,7 @@ def _ip(ip):
class TestModule(object):
""" network jinja test"""
"""network jinja test"""
test_map = {"ip": _ip}

View File

@ -103,7 +103,7 @@ def _ip_address(ip):
class TestModule(object):
""" network jinja test"""
"""network jinja test"""
test_map = {"ip_address": _ip_address}

View File

@ -100,7 +100,7 @@ def _ipv4(ip):
class TestModule(object):
""" network jinja test"""
"""network jinja test"""
test_map = {"ipv4": _ipv4}

View File

@ -102,7 +102,7 @@ def _ipv4_address(ip):
class TestModule(object):
""" network jinja test"""
"""network jinja test"""
test_map = {"ipv4_address": _ipv4_address}

View File

@ -90,7 +90,7 @@ def _ipv4_hostmask(ip):
class TestModule(object):
""" network jinja test"""
"""network jinja test"""
test_map = {"ipv4_hostmask": _ipv4_hostmask}

View File

@ -89,7 +89,7 @@ RETURN = """
@_need_ipaddress
def _ipv4_netmask(mask):
""" Test for a valid IPv4 netmask"""
"""Test for a valid IPv4 netmask"""
params = {"mask": mask}
_validate_args("ipv4_netmask", DOCUMENTATION, params)
@ -102,7 +102,7 @@ def _ipv4_netmask(mask):
class TestModule(object):
""" network jinja test"""
"""network jinja test"""
test_map = {"ipv4_netmask": _ipv4_netmask}

View File

@ -102,7 +102,7 @@ def _ipv6(ip):
class TestModule(object):
""" network jinja test"""
"""network jinja test"""
test_map = {"ipv6": _ipv6}

View File

@ -102,7 +102,7 @@ def _ipv6_address(ip):
class TestModule(object):
""" network jinja test"""
"""network jinja test"""
test_map = {"ipv6_address": _ipv6_address}

View File

@ -88,7 +88,7 @@ RETURN = """
@_need_ipaddress
def _ipv6_ipv4_mapped(ip):
""" Test if something appears to be a mapped IPv6 to IPv4 mapped address """
"""Test if something appears to be a mapped IPv6 to IPv4 mapped address"""
params = {"ip": ip}
_validate_args("ipv6_ipv4_mapped", DOCUMENTATION, params)
@ -102,7 +102,7 @@ def _ipv6_ipv4_mapped(ip):
class TestModule(object):
""" network jinja test"""
"""network jinja test"""
test_map = {"ipv6_ipv4_mapped": _ipv6_ipv4_mapped}

View File

@ -90,7 +90,7 @@ RETURN = """
@_need_ipaddress
def _ipv6_sixtofour(ip):
""" Test if something appears to be a 6to4 address """
"""Test if something appears to be a 6to4 address"""
params = {"ip": ip}
_validate_args("ipv6_sixtofour", DOCUMENTATION, params)
@ -104,7 +104,7 @@ def _ipv6_sixtofour(ip):
class TestModule(object):
""" network jinja test"""
"""network jinja test"""
test_map = {"ipv6_sixtofour": _ipv6_sixtofour}

View File

@ -90,7 +90,7 @@ RETURN = """
@_need_ipaddress
def _ipv6_teredo(ip):
""" Test if something is an IPv6 teredo address """
"""Test if something is an IPv6 teredo address"""
params = {"ip": ip}
_validate_args("ipv6_teredo", DOCUMENTATION, params)
@ -104,7 +104,7 @@ def _ipv6_teredo(ip):
class TestModule(object):
""" network jinja test"""
"""network jinja test"""
test_map = {"ipv6_teredo": _ipv6_teredo}

View File

@ -85,7 +85,7 @@ RETURN = """
@_need_ipaddress
def _loopback(ip):
""" Test if an IP address is a loopback """
"""Test if an IP address is a loopback"""
params = {"ip": ip}
_validate_args("loopback", DOCUMENTATION, params)
@ -97,7 +97,7 @@ def _loopback(ip):
class TestModule(object):
""" network jinja test"""
"""network jinja test"""
test_map = {"loopback": _loopback}

View File

@ -109,7 +109,7 @@ RETURN = """
def _mac(mac):
""" Test if something appears to be a valid mac address """
"""Test if something appears to be a valid mac address"""
params = {"mac": mac}
_validate_args("mac", DOCUMENTATION, params)
@ -125,7 +125,7 @@ def _mac(mac):
class TestModule(object):
""" network jinja test"""
"""network jinja test"""
test_map = {"mac": _mac}

View File

@ -100,7 +100,7 @@ RETURN = """
@_need_ipaddress
def _multicast(ip):
""" Test for a multicast IP address """
"""Test for a multicast IP address"""
params = {"ip": ip}
_validate_args("multicast", DOCUMENTATION, params)
@ -112,7 +112,7 @@ def _multicast(ip):
class TestModule(object):
""" network jinja test"""
"""network jinja test"""
test_map = {"multicast": _multicast}

View File

@ -76,7 +76,7 @@ RETURN = """
@_need_ipaddress
def _private(ip):
""" Test if an IP address is private """
"""Test if an IP address is private"""
params = {"ip": ip}
_validate_args("private", DOCUMENTATION, params)
@ -88,7 +88,7 @@ def _private(ip):
class TestModule(object):
""" network jinja test"""
"""network jinja test"""
test_map = {"private": _private}

View File

@ -74,7 +74,7 @@ RETURN = """
@_need_ipaddress
def _public(ip):
""" Test if an IP address is public """
"""Test if an IP address is public"""
params = {"ip": ip}
_validate_args("public", DOCUMENTATION, params)
@ -86,7 +86,7 @@ def _public(ip):
class TestModule(object):
""" network jinja test"""
"""network jinja test"""
test_map = {"public": _public}

View File

@ -75,7 +75,7 @@ RETURN = """
@_need_ipaddress
def _reserved(ip):
""" Test for a reserved IP address """
"""Test for a reserved IP address"""
params = {"ip": ip}
_validate_args("reserved", DOCUMENTATION, params)
@ -87,7 +87,7 @@ def _reserved(ip):
class TestModule(object):
""" network jinja test"""
"""network jinja test"""
test_map = {"reserved": _reserved}

View File

@ -123,7 +123,7 @@ RETURN = """
@_need_ipaddress
def _resolvable(host):
""" Test if an IP or name can be resolved via /etc/hosts or DNS """
"""Test if an IP or name can be resolved via /etc/hosts or DNS"""
params = {"host": host}
_validate_args("resolvable", DOCUMENTATION, params)
@ -148,7 +148,7 @@ def _resolvable(host):
class TestModule(object):
""" network jinja tests """
"""network jinja tests"""
test_map = {"resolvable": _resolvable}

View File

@ -80,7 +80,7 @@ RETURN = """
@_need_ipaddress
def _subnet_of(network_a, network_b):
""" Test if a network is a subnet of another network """
"""Test if a network is a subnet of another network"""
params = {"network_a": network_a, "network_b": network_b}
_validate_args("subnet_of", DOCUMENTATION, params)
@ -92,7 +92,7 @@ def _subnet_of(network_a, network_b):
class TestModule(object):
""" network jinja test """
"""network jinja test"""
test_map = {"subnet_of": _subnet_of}

View File

@ -82,7 +82,7 @@ RETURN = """
@_need_ipaddress
def _supernet_of(network_a, network_b):
""" Test if an network is a supernet of another network """
"""Test if an network is a supernet of another network"""
params = {"network_a": network_a, "network_b": network_b}
_validate_args("supernet_of", DOCUMENTATION, params)
@ -94,7 +94,7 @@ def _supernet_of(network_a, network_b):
class TestModule(object):
""" network jinja test """
"""network jinja test"""
test_map = {"supernet_of": _supernet_of}

View File

@ -101,7 +101,7 @@ RETURN = """
@_need_ipaddress
def _unspecified(ip):
""" Test for an unspecified IP address """
"""Test for an unspecified IP address"""
params = {"ip": ip}
_validate_args("unspecified", DOCUMENTATION, params)
@ -113,7 +113,7 @@ def _unspecified(ip):
class TestModule(object):
""" network jinja test"""
"""network jinja test"""
test_map = {"unspecified": _unspecified}

View File

@ -1,4 +1,4 @@
black==19.3b0 ; python_version > '3.5'
black==22.3.0 ; python_version > '3.5'
coverage==4.5.4
flake8
ipaddress ; python_version < '3.0'

View File

@ -58,7 +58,7 @@ class TestCli_Parse(unittest.TestCase):
@staticmethod
def _load_fixture(filename):
""" Load a fixture from the filesystem
"""Load a fixture from the filesystem
:param filename: The name of the file to load
:type filename: str
@ -72,23 +72,20 @@ class TestCli_Parse(unittest.TestCase):
return fhand.read()
def test_fn_debug(self):
""" Confirm debug doesn't fail and return None
"""
"""Confirm debug doesn't fail and return None"""
msg = "some message"
result = self._plugin._debug(msg)
self.assertEqual(result, None)
def test_fn_ail_json(self):
""" Confirm fail json replaces basic.py in msg
"""
"""Confirm fail json replaces basic.py in msg"""
msg = "text (basic.py)"
with self.assertRaises(Exception) as error:
self._plugin._fail_json(msg)
self.assertEqual("text cli_parse", str(error.exception))
def test_fn_check_argspec_pass(self):
""" Confirm a valid argspec passes
"""
"""Confirm a valid argspec passes"""
kwargs = {
"text": "text",
"parser": {
@ -102,8 +99,7 @@ class TestCli_Parse(unittest.TestCase):
self.assertEqual(valid, True)
def test_fn_check_argspec_fail_no_test_or_command(self):
""" Confirm failed argpsec w/o text or command
"""
"""Confirm failed argpsec w/o text or command"""
kwargs = {
"parser": {
"name": "ansible.utils.textfsm",
@ -122,8 +118,7 @@ class TestCli_Parse(unittest.TestCase):
)
def test_fn_check_argspec_fail_no_parser_name(self):
""" Confirm failed argspec no parser name
"""
"""Confirm failed argspec no parser name"""
kwargs = {"text": "anything", "parser": {"command": "show version"}}
valid, result, updated_params = check_argspec(
DOCUMENTATION,
@ -137,8 +132,7 @@ class TestCli_Parse(unittest.TestCase):
)
def test_fn_extended_check_argspec_parser_name_not_coll(self):
""" Confirm failed argpsec parser not collection format
"""
"""Confirm failed argpsec parser not collection format"""
self._plugin._task.args = {
"text": "anything",
"parser": {
@ -151,7 +145,7 @@ class TestCli_Parse(unittest.TestCase):
self.assertIn("including collection", self._plugin._result["msg"])
def test_fn_extended_check_argspec_missing_tpath_or_command(self):
""" Confirm failed argpsec missing template_path
"""Confirm failed argpsec missing template_path
or command when text provided
"""
self._plugin._task.args = {
@ -165,8 +159,7 @@ class TestCli_Parse(unittest.TestCase):
)
def test_fn_load_parser_pass(self):
""" Confirm each each of the parsers loads from the filesystem
"""
"""Confirm each each of the parsers loads from the filesystem"""
parser_names = ["json", "textfsm", "ttp", "xml"]
for parser_name in parser_names:
self._plugin._task.args = {
@ -179,8 +172,7 @@ class TestCli_Parse(unittest.TestCase):
self.assertTrue(callable(parser.parse))
def test_fn_load_parser_fail(self):
""" Confirm missing parser fails gracefully
"""
"""Confirm missing parser fails gracefully"""
self._plugin._task.args = {
"text": "anything",
"parser": {"name": "a.b.c"},
@ -191,7 +183,7 @@ class TestCli_Parse(unittest.TestCase):
self.assertIn("No module named", self._plugin._result["msg"])
def test_fn_set_parser_command_missing(self):
""" Confirm parser/command is set if missing
"""Confirm parser/command is set if missing
and command provided
"""
self._plugin._task.args = {
@ -204,8 +196,7 @@ class TestCli_Parse(unittest.TestCase):
)
def test_fn_set_parser_command_present(self):
""" Confirm parser/command is not changed if provided
"""
"""Confirm parser/command is not changed if provided"""
self._plugin._task.args = {
"command": "anything",
"parser": {"command": "something", "name": "a.b.c"},
@ -216,15 +207,13 @@ class TestCli_Parse(unittest.TestCase):
)
def test_fn_set_parser_command_absent(self):
""" Confirm parser/command is not added
"""
"""Confirm parser/command is not added"""
self._plugin._task.args = {"parser": {}}
self._plugin._set_parser_command()
self.assertNotIn("command", self._plugin._task.args["parser"])
def test_fn_set_text_present(self):
""" Check task args text is set to stdout
"""
"""Check task args text is set to stdout"""
expected = "output"
self._plugin._result["stdout"] = expected
self._plugin._task.args = {}
@ -232,16 +221,14 @@ class TestCli_Parse(unittest.TestCase):
self.assertEqual(self._plugin._task.args["text"], expected)
def test_fn_set_text_absent(self):
""" Check task args text is set to stdout
"""
"""Check task args text is set to stdout"""
self._plugin._result["stdout"] = None
self._plugin._task.args = {}
self._plugin._set_text()
self.assertNotIn("text", self._plugin._task.args)
def test_fn_os_from_task_vars(self):
""" Confirm os is set based on task vars
"""
"""Confirm os is set based on task vars"""
checks = [
("ansible_network_os", "cisco.nxos.nxos", "nxos"),
("ansible_network_os", "NXOS", "nxos"),
@ -254,7 +241,7 @@ class TestCli_Parse(unittest.TestCase):
self.assertEqual(result, check[2])
def test_fn_update_template_path_not_exist(self):
""" Check the creation of the template_path if
"""Check the creation of the template_path if
it doesn't exist in the user provided data
"""
self._plugin._task.args = {
@ -269,7 +256,7 @@ class TestCli_Parse(unittest.TestCase):
)
def test_fn_update_template_path_not_exist_os(self):
""" Check the creation of the template_path if
"""Check the creation of the template_path if
it doesn't exist in the user provided data
name based on os provided in task
"""
@ -284,7 +271,7 @@ class TestCli_Parse(unittest.TestCase):
)
def test_fn_update_template_path_mock_find_needle(self):
""" Check the creation of the template_path
"""Check the creation of the template_path
mock the find needle fn so the template doesn't
need to be in the default template folder
"""
@ -302,8 +289,7 @@ class TestCli_Parse(unittest.TestCase):
)
def test_fn_get_template_contents_pass(self):
""" Check the retrieval of the template contents
"""
"""Check the retrieval of the template contents"""
temp = tempfile.NamedTemporaryFile()
contents = "abcdef"
with open(temp.name, "w") as fileh:
@ -314,8 +300,7 @@ class TestCli_Parse(unittest.TestCase):
self.assertEqual(result, contents)
def test_fn_get_template_contents_missing(self):
""" Check the retrieval of the template contents
"""
"""Check the retrieval of the template contents"""
self._plugin._task.args = {"parser": {"template_path": "non-exist"}}
with self.assertRaises(Exception) as error:
self._plugin._get_template_contents()
@ -324,15 +309,13 @@ class TestCli_Parse(unittest.TestCase):
)
def test_fn_get_template_contents_not_specified(self):
""" Check the none when template_path not specified
"""
"""Check the none when template_path not specified"""
self._plugin._task.args = {"parser": {}}
result = self._plugin._get_template_contents()
self.assertIsNone(result)
def test_fn_prune_result_pass(self):
""" Test the removal of stdout and stdout_lines from the _result
"""
"""Test the removal of stdout and stdout_lines from the _result"""
self._plugin._result["stdout"] = "abc"
self._plugin._result["stdout_lines"] = "abc"
self._plugin._prune_result()
@ -340,15 +323,13 @@ class TestCli_Parse(unittest.TestCase):
self.assertNotIn("stdout_lines", self._plugin._result)
def test_fn_prune_result_not_exist(self):
""" Test the removal of stdout and stdout_lines from the _result
"""
"""Test the removal of stdout and stdout_lines from the _result"""
self._plugin._prune_result()
self.assertNotIn("stdout", self._plugin._result)
self.assertNotIn("stdout_lines", self._plugin._result)
def test_fn_run_command_lx_rc0(self):
""" Check run command for non network
"""
"""Check run command for non network"""
response = "abc"
self._plugin._connection.socket_path = None
self._plugin._low_level_execute_command = MagicMock()
@ -363,8 +344,7 @@ class TestCli_Parse(unittest.TestCase):
self.assertEqual(self._plugin._result["stdout_lines"], response)
def test_fn_run_command_lx_rc1(self):
""" Check run command for non network
"""
"""Check run command for non network"""
response = "abc"
self._plugin._connection.socket_path = None
self._plugin._low_level_execute_command = MagicMock()
@ -381,8 +361,7 @@ class TestCli_Parse(unittest.TestCase):
@patch("ansible.module_utils.connection.Connection.__rpc__")
def test_fn_run_command_network(self, mock_rpc):
""" Check run command for network
"""
"""Check run command for network"""
expected = "abc"
mock_rpc.return_value = expected
self._plugin._connection.socket_path = (
@ -394,16 +373,14 @@ class TestCli_Parse(unittest.TestCase):
self.assertEqual(self._plugin._result["stdout_lines"], [expected])
def test_fn_run_command_not_specified(self):
""" Check run command for network
"""
"""Check run command for network"""
self._plugin._task.args = {"command": None}
result = self._plugin._run_command()
self.assertIsNone(result)
@patch("ansible.module_utils.connection.Connection.__rpc__")
def test_fn_run_pass_w_fact(self, mock_rpc):
""" Check full module run with valid params
"""
"""Check full module run with valid params"""
mock_out = self._load_fixture("nxos_show_version.txt")
mock_rpc.return_value = mock_out
self._plugin._connection.socket_path = (
@ -431,8 +408,7 @@ class TestCli_Parse(unittest.TestCase):
@patch("ansible.module_utils.connection.Connection.__rpc__")
def test_fn_run_pass_wo_fact(self, mock_rpc):
""" Check full module run with valid params
"""
"""Check full module run with valid params"""
mock_out = self._load_fixture("nxos_show_version.txt")
mock_rpc.return_value = mock_out
self._plugin._connection.socket_path = (
@ -456,8 +432,7 @@ class TestCli_Parse(unittest.TestCase):
self.assertNotIn("ansible_facts", result)
def test_fn_run_fail_argspec(self):
""" Check full module run with invalid params
"""
"""Check full module run with invalid params"""
self._plugin._task.args = {
"text": "anything",
"parser": {
@ -470,8 +445,7 @@ class TestCli_Parse(unittest.TestCase):
self.assertIn("including collection", self._plugin._result["msg"])
def test_fn_run_fail_command(self):
""" Confirm clean fail with rc 1
"""
"""Confirm clean fail with rc 1"""
self._plugin._connection.socket_path = None
self._plugin._low_level_execute_command = MagicMock()
self._plugin._low_level_execute_command.return_value = {
@ -495,8 +469,7 @@ class TestCli_Parse(unittest.TestCase):
self.assertEqual(result, expected)
def test_fn_run_fail_missing_parser(self):
"""Confirm clean fail with missing parser
"""
"""Confirm clean fail with missing parser"""
self._plugin._task.args = {"text": None, "parser": {"name": "a.b.c"}}
task_vars = {"inventory_hostname": "mockdevice"}
result = self._plugin.run(task_vars=task_vars)
@ -505,7 +478,7 @@ class TestCli_Parse(unittest.TestCase):
@patch("ansible.module_utils.connection.Connection.__rpc__")
def test_fn_run_pass_missing_parser_constants(self, mock_rpc):
""" Check full module run using parser w/o
"""Check full module run using parser w/o
DEFAULT_TEMPLATE_EXTENSION or PROVIDE_TEMPLATE_CONTENTS
defined in the parser
"""
@ -542,7 +515,7 @@ class TestCli_Parse(unittest.TestCase):
@patch("ansible.module_utils.connection.Connection.__rpc__")
def test_fn_run_pass_missing_parser_in_parser(self, mock_rpc):
""" Check full module run using parser w/o
"""Check full module run using parser w/o
a parser function defined in the parser
defined in the parser
"""
@ -577,8 +550,7 @@ class TestCli_Parse(unittest.TestCase):
@patch("ansible.module_utils.connection.Connection.__rpc__")
def test_fn_run_net_device_error(self, mock_rpc):
""" Check full module run mock error from network device
"""
"""Check full module run mock error from network device"""
msg = "I was mocked"
mock_rpc.side_effect = AnsibleConnectionError(msg)
self._plugin._connection.socket_path = (

View File

@ -28,7 +28,7 @@ class TestIpAddr(unittest.TestCase):
self.assertEqual(result, "192.168.1.10")
def test_find_previous_fifth_address(self):
"""Get the previous fifth address """
"""Get the previous fifth address"""
args = ["", "192.168.1.5", -10]
result = _ipmath(*args)

View File

@ -71,8 +71,10 @@ def test_invalid_action(validator, test_rule):
except AnsibleError as exc:
error = to_text(exc)
expected_error = 'Action in criteria {item} is not one of "warn" or "fail"'.format(
item=original
expected_error = (
'Action in criteria {item} is not one of "warn" or "fail"'.format(
item=original
)
)
assert error == expected_error