[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.cipull/158/head
parent
b54230531e
commit
c4ad14f305
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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"))
|
||||||
|
|
|
@ -205,10 +205,12 @@ 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 = (
|
||||||
|
"At '{schema_path}' {message}. ".format(
|
||||||
schema_path=error["schema_path"],
|
schema_path=error["schema_path"],
|
||||||
message=error["message"],
|
message=error["message"],
|
||||||
)
|
)
|
||||||
|
)
|
||||||
error_messages.append(error_message)
|
error_messages.append(error_message)
|
||||||
if error_messages:
|
if error_messages:
|
||||||
if "msg" not in self._result:
|
if "msg" not in self._result:
|
||||||
|
|
|
@ -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": {
|
||||||
|
@ -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"},
|
||||||
|
@ -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"),
|
||||||
|
@ -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)
|
||||||
|
@ -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 = (
|
||||||
|
|
|
@ -71,9 +71,11 @@ 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 = (
|
||||||
|
'Action in criteria {item} is not one of "warn" or "fail"'.format(
|
||||||
item=original
|
item=original
|
||||||
)
|
)
|
||||||
|
)
|
||||||
assert error == expected_error
|
assert error == expected_error
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue