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:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.1.0
@ -10,7 +16,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

@ -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):
"""IP address and network manipulation filters
"""
"""IP address and network manipulation filters"""
filter_map = {
# IP addresses and networks

View File

@ -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

View File

@ -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

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

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

View File

@ -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

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

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

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

View File

@ -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

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

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

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

View File

@ -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

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

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

View File

@ -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

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

@ -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"))

View File

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

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

@ -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": {
@ -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"},
@ -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"),
@ -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)
@ -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

@ -71,9 +71,11 @@ 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(
expected_error = (
'Action in criteria {item} is not one of "warn" or "fail"'.format(
item=original
)
)
assert error == expected_error