Merge branch 'main' into copy_ingore_txt

pull/159/head
Bradley A. Thornton 2022-04-07 13:19:38 -07:00 committed by GitHub
commit 836437c359
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
83 changed files with 191 additions and 221 deletions

View File

@ -1,4 +1,10 @@
--- ---
ci:
skip:
# pre-commit.ci has trouble with this one
- update-docs
- end-of-file-fixer
- trailing-whitespace
repos: repos:
- repo: https://github.com/pre-commit/pre-commit-hooks - repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.1.0 rev: v3.1.0
@ -10,7 +16,7 @@ repos:
args: [--branch, main] args: [--branch, main]
- id: trailing-whitespace - id: trailing-whitespace
- repo: https://github.com/psf/black - repo: https://github.com/psf/black
rev: 19.3b0 rev: 22.3.0
hooks: hooks:
- id: black - id: black
args: [-l, "79"] args: [-l, "79"]

View File

@ -0,0 +1,4 @@
---
trivial:
- Enable black via pre-commit.ci
- Update black version to latest

View File

@ -0,0 +1,6 @@
---
trivial:
- Exempt update-docs from pre-commit.ci
- Disable black temporarily until it can be upgraded
- Disable end-of-file-fixer
- Disable trailing-whitespace

View File

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

View File

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

View File

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

View File

@ -98,7 +98,7 @@ RETURN = """
@pass_environment @pass_environment
def _hwaddr(*args, **kwargs): 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"] keys = ["value", "query", "alias"]
data = dict(zip(keys, args[1:])) data = dict(zip(keys, args[1:]))
data.update(kwargs) data.update(kwargs)
@ -112,8 +112,7 @@ def _hwaddr(*args, **kwargs):
class FilterModule(object): class FilterModule(object):
"""IP address and network manipulation filters """IP address and network manipulation filters"""
"""
filter_map = { filter_map = {
# IP addresses and networks # IP addresses and networks
@ -121,7 +120,7 @@ class FilterModule(object):
} }
def filters(self): def filters(self):
""" ipaddr filter """ """ipaddr filter"""
if HAS_NETADDR: if HAS_NETADDR:
return self.filter_map return self.filter_map
else: else:

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -95,7 +95,7 @@ RETURN = """
@pass_environment @pass_environment
def _macaddr(*args, **kwargs): 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"] keys = ["value", "query"]
data = dict(zip(keys, args[1:])) data = dict(zip(keys, args[1:]))
data.update(kwargs) data.update(kwargs)
@ -113,8 +113,7 @@ def macaddr(value, query=""):
class FilterModule(object): class FilterModule(object):
"""IP address and network manipulation filters """IP address and network manipulation filters"""
"""
filter_map = { filter_map = {
# IP addresses and networks # IP addresses and networks
@ -122,7 +121,7 @@ class FilterModule(object):
} }
def filters(self): def filters(self):
""" ipaddr filter """ """ipaddr filter"""
if HAS_NETADDR: if HAS_NETADDR:
return self.filter_map return self.filter_map
else: else:

View File

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

View File

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

View File

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

View File

@ -110,7 +110,7 @@ def _nthhost(*args, **kwargs):
def nthhost(value, query=""): 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: try:
vtype = ipaddr(value, "type") vtype = ipaddr(value, "type")
if vtype == "address": if vtype == "address":
@ -137,8 +137,7 @@ def nthhost(value, query=""):
class FilterModule(object): class FilterModule(object):
"""IP address and network manipulation filters """IP address and network manipulation filters"""
"""
filter_map = { filter_map = {
# IP addresses and networks # IP addresses and networks
@ -146,7 +145,7 @@ class FilterModule(object):
} }
def filters(self): def filters(self):
""" ipaddr filter """ """ipaddr filter"""
if HAS_NETADDR: if HAS_NETADDR:
return self.filter_map return self.filter_map
else: else:

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -7,7 +7,7 @@ __metaclass__ = type
class CliParserBase: class CliParserBase:
""" The base class for cli parsers """The base class for cli parsers
Provides a _debug function to normalize parser debug output 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"): 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 = { query_func_extra_args = {
"": ("vtype",), "": ("vtype",),
@ -686,7 +686,7 @@ def _win_query(v):
# ---- HWaddr / MAC address filters ---- # ---- HWaddr / MAC address filters ----
def hwaddr(value, query="", alias="hwaddr"): 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",)} query_func_extra_args = {"": ("value",)}

View File

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

View File

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

View File

@ -53,7 +53,7 @@ except ImportError:
class CliParser(CliParserBase): class CliParser(CliParserBase):
""" The textfsm parser class """The textfsm parser class
Convert raw text to structured data using textfsm Convert raw text to structured data using textfsm
""" """
@ -62,7 +62,7 @@ class CliParser(CliParserBase):
@staticmethod @staticmethod
def _check_reqs(): 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 :return dict: A dict with errors or a template_path
""" """
@ -74,7 +74,7 @@ class CliParser(CliParserBase):
return {"errors": errors} return {"errors": errors}
def parse(self, *_args, **_kwargs): 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 :return: Errors or parsed text as structured data
:rtype: dict :rtype: dict

View File

@ -53,7 +53,7 @@ except ImportError:
class CliParser(CliParserBase): class CliParser(CliParserBase):
""" The ttp parser class """The ttp parser class
Convert raw text to structured data using ttp Convert raw text to structured data using ttp
""" """
@ -62,7 +62,7 @@ class CliParser(CliParserBase):
@staticmethod @staticmethod
def _check_reqs(): 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 :return dict: A dict with errors or a template_path
""" """
@ -74,7 +74,7 @@ class CliParser(CliParserBase):
return {"errors": errors} return {"errors": errors}
def parse(self, *_args, **_kwargs): 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 :return: Errors or parsed text as structured data
:rtype: dict :rtype: dict

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -88,7 +88,7 @@ RETURN = """
@_need_ipaddress @_need_ipaddress
def _ipv6_ipv4_mapped(ip): 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} params = {"ip": ip}
_validate_args("ipv6_ipv4_mapped", DOCUMENTATION, params) _validate_args("ipv6_ipv4_mapped", DOCUMENTATION, params)
@ -102,7 +102,7 @@ def _ipv6_ipv4_mapped(ip):
class TestModule(object): class TestModule(object):
""" network jinja test""" """network jinja test"""
test_map = {"ipv6_ipv4_mapped": _ipv6_ipv4_mapped} test_map = {"ipv6_ipv4_mapped": _ipv6_ipv4_mapped}

View File

@ -90,7 +90,7 @@ RETURN = """
@_need_ipaddress @_need_ipaddress
def _ipv6_sixtofour(ip): 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} params = {"ip": ip}
_validate_args("ipv6_sixtofour", DOCUMENTATION, params) _validate_args("ipv6_sixtofour", DOCUMENTATION, params)
@ -104,7 +104,7 @@ def _ipv6_sixtofour(ip):
class TestModule(object): class TestModule(object):
""" network jinja test""" """network jinja test"""
test_map = {"ipv6_sixtofour": _ipv6_sixtofour} test_map = {"ipv6_sixtofour": _ipv6_sixtofour}

View File

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

View File

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

View File

@ -109,7 +109,7 @@ RETURN = """
def _mac(mac): 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} params = {"mac": mac}
_validate_args("mac", DOCUMENTATION, params) _validate_args("mac", DOCUMENTATION, params)
@ -125,7 +125,7 @@ def _mac(mac):
class TestModule(object): class TestModule(object):
""" network jinja test""" """network jinja test"""
test_map = {"mac": _mac} test_map = {"mac": _mac}

View File

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

View File

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

View File

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

View File

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

View File

@ -123,7 +123,7 @@ RETURN = """
@_need_ipaddress @_need_ipaddress
def _resolvable(host): 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} params = {"host": host}
_validate_args("resolvable", DOCUMENTATION, params) _validate_args("resolvable", DOCUMENTATION, params)
@ -148,7 +148,7 @@ def _resolvable(host):
class TestModule(object): class TestModule(object):
""" network jinja tests """ """network jinja tests"""
test_map = {"resolvable": _resolvable} test_map = {"resolvable": _resolvable}

View File

@ -80,7 +80,7 @@ RETURN = """
@_need_ipaddress @_need_ipaddress
def _subnet_of(network_a, network_b): 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} params = {"network_a": network_a, "network_b": network_b}
_validate_args("subnet_of", DOCUMENTATION, params) _validate_args("subnet_of", DOCUMENTATION, params)
@ -92,7 +92,7 @@ def _subnet_of(network_a, network_b):
class TestModule(object): class TestModule(object):
""" network jinja test """ """network jinja test"""
test_map = {"subnet_of": _subnet_of} test_map = {"subnet_of": _subnet_of}

View File

@ -82,7 +82,7 @@ RETURN = """
@_need_ipaddress @_need_ipaddress
def _supernet_of(network_a, network_b): 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} params = {"network_a": network_a, "network_b": network_b}
_validate_args("supernet_of", DOCUMENTATION, params) _validate_args("supernet_of", DOCUMENTATION, params)
@ -94,7 +94,7 @@ def _supernet_of(network_a, network_b):
class TestModule(object): class TestModule(object):
""" network jinja test """ """network jinja test"""
test_map = {"supernet_of": _supernet_of} test_map = {"supernet_of": _supernet_of}

View File

@ -101,7 +101,7 @@ RETURN = """
@_need_ipaddress @_need_ipaddress
def _unspecified(ip): def _unspecified(ip):
""" Test for an unspecified IP address """ """Test for an unspecified IP address"""
params = {"ip": ip} params = {"ip": ip}
_validate_args("unspecified", DOCUMENTATION, params) _validate_args("unspecified", DOCUMENTATION, params)
@ -113,7 +113,7 @@ def _unspecified(ip):
class TestModule(object): class TestModule(object):
""" network jinja test""" """network jinja test"""
test_map = {"unspecified": _unspecified} 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 coverage==4.5.4
flake8 flake8
ipaddress ; python_version < '3.0' ipaddress ; python_version < '3.0'

View File

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

View File

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

View File

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