From 273f184bd2c625c6b032aad66a139af3351e59b3 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 8 Jan 2024 13:26:53 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- .../module_utils/network/eos/utils/utils.py | 4 ++- plugins/modules/eos_config.py | 18 ++++++---- .../templates/defaults/candidate.j2 | 4 +-- .../modules/network/eos/test_eos_config.py | 34 ++++++++++--------- 4 files changed, 35 insertions(+), 25 deletions(-) diff --git a/plugins/module_utils/network/eos/utils/utils.py b/plugins/module_utils/network/eos/utils/utils.py index 8f0c16348..109ea7fb1 100644 --- a/plugins/module_utils/network/eos/utils/utils.py +++ b/plugins/module_utils/network/eos/utils/utils.py @@ -12,6 +12,7 @@ import difflib + def get_interface_number(name): digits = "" for char in name: @@ -84,9 +85,10 @@ def numerical_sort(string_int_list): as_int_list.sort() return list(set(as_int_list)) + def unified_diff(content1, content2, count): """ Provide the unified diff in context to number of lines specified with count """ - unified_diff = difflib.unified_diff(content1, content2, n=count, lineterm='\n') + unified_diff = difflib.unified_diff(content1, content2, n=count, lineterm="\n") return "\n".join(unified_diff) diff --git a/plugins/modules/eos_config.py b/plugins/modules/eos_config.py index 32d8efc65..3ed03a576 100644 --- a/plugins/modules/eos_config.py +++ b/plugins/modules/eos_config.py @@ -348,7 +348,6 @@ NetworkConfig, dumps, ) -from ansible_collections.arista.eos.plugins.module_utils.network.eos.utils.utils import unified_diff from ansible_collections.arista.eos.plugins.module_utils.network.eos.eos import ( get_config, @@ -357,6 +356,7 @@ load_config, run_commands, ) +from ansible_collections.arista.eos.plugins.module_utils.network.eos.utils.utils import unified_diff def get_candidate(module): @@ -406,9 +406,13 @@ def main(): parents=dict(type="list", elements="str"), before=dict(type="list", elements="str"), after=dict(type="list", elements="str"), - context_diff=dict(type="dict", options=dict( - enable=dict(type="bool"), context_lines=dict(type="int") - )), + context_diff=dict( + type="dict", + options=dict( + enable=dict(type="bool"), + context_lines=dict(type="int"), + ), + ), match=dict( default="line", choices=["line", "strict", "exact", "none"], @@ -523,13 +527,15 @@ def main(): result["changed"] = True if module.params["diff_against"] == "session": if "diff" in response: - context_diff = module.params.get("context_diff") + context_diff = module.params.get("context_diff") if context_diff and context_diff.get("enable"): if context_diff.get("context_lines"): count = context_diff.get("context_lines") else: count = max(len(candidate), len(running)) - result["context_diff"] = unified_diff(candidate.split("\n"), running.split("\n"), count) + result["context_diff"] = unified_diff( + candidate.split("\n"), running.split("\n"), count + ) else: result["diff"] = {"prepared": response["diff"]} else: diff --git a/tests/integration/targets/eos_config/templates/defaults/candidate.j2 b/tests/integration/targets/eos_config/templates/defaults/candidate.j2 index d18ff28b0..a8ac1b2f2 100644 --- a/tests/integration/targets/eos_config/templates/defaults/candidate.j2 +++ b/tests/integration/targets/eos_config/templates/defaults/candidate.j2 @@ -1,8 +1,8 @@ ! Command: show running-config ! interface Ethernet2 - description "This is candidate config sample" + description "This is candidate config sample" shutdown no switchport ! -end \ No newline at end of file +end diff --git a/tests/unit/modules/network/eos/test_eos_config.py b/tests/unit/modules/network/eos/test_eos_config.py index 47bedb645..959c5c2f9 100644 --- a/tests/unit/modules/network/eos/test_eos_config.py +++ b/tests/unit/modules/network/eos/test_eos_config.py @@ -301,14 +301,15 @@ def test_eos_config_src_replace(self): def test_eos_config_context_diff(self): src = load_fixture("eos_candidate.cfg") - args = dict(src=src, - backup=True, - context_diff=dict(enable=True), - backup_options=dict( - filename="backup.cfg", - dir_path="./" - ), - ) + args = dict( + src=src, + backup=True, + context_diff=dict(enable=True), + backup_options=dict( + filename="backup.cfg", + dir_path="./", + ), + ) set_module_args(args) self.conn.get_diff = MagicMock( return_value=self.cliconf_obj.get_diff(src, self.running_config), @@ -318,14 +319,15 @@ def test_eos_config_context_diff(self): def test_eos_config_context_diff_lines(self): src = load_fixture("eos_candidate.cfg") - args = dict(src=src, - backup=True, - context_diff=dict(enable=True, context_lines=10), - backup_options=dict( - filename="backup.cfg", - dir_path="./" - ), - ) + args = dict( + src=src, + backup=True, + context_diff=dict(enable=True, context_lines=10), + backup_options=dict( + filename="backup.cfg", + dir_path="./", + ), + ) set_module_args(args) self.conn.get_diff = MagicMock( return_value=self.cliconf_obj.get_diff(src, self.running_config),