From 3dd130a0bc1099ed7b8c1dee4119599ad551cb51 Mon Sep 17 00:00:00 2001 From: Aayush Anand Date: Tue, 19 Nov 2024 20:55:04 +0530 Subject: [PATCH] fix port-security-bug in nxos (#906) * fix port-security-bug * added unit tests for port-security * chore: auto fixes from pre-commit.com hooks * added changelog --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- changelogs/fragments/nxos_feature.yaml | 3 +++ plugins/modules/nxos_feature.py | 4 ++-- .../nxos/fixtures/nxos_feature/show_feature.txt | 1 + tests/unit/modules/network/nxos/test_nxos_feature.py | 10 ++++++++++ 4 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/nxos_feature.yaml diff --git a/changelogs/fragments/nxos_feature.yaml b/changelogs/fragments/nxos_feature.yaml new file mode 100644 index 000000000..48398e965 --- /dev/null +++ b/changelogs/fragments/nxos_feature.yaml @@ -0,0 +1,3 @@ +--- +bugfixes: + - Fixed the invalid feature name error for port-security by updating the feature mapping from `eth_port_sec` to `eth-port-sec`. diff --git a/plugins/modules/nxos_feature.py b/plugins/modules/nxos_feature.py index c9229c4d5..bf2ad69bd 100644 --- a/plugins/modules/nxos_feature.py +++ b/plugins/modules/nxos_feature.py @@ -234,7 +234,7 @@ def validate_feature(module, mode="show"): "tacacs+": "tacacs", "telnet": "telnetServer", "ethernet-link-oam": "elo", - "port-security": "eth_port_sec", + "port-security": "eth-port-sec", }, "config": { "nve": "nv overlay", @@ -249,7 +249,7 @@ def validate_feature(module, mode="show"): "tacacs": "tacacs+", "telnetServer": "telnet", "elo": "ethernet-link-oam", - "eth_port_sec": "port-security", + "eth-port-sec": "port-security", }, } diff --git a/tests/unit/modules/network/nxos/fixtures/nxos_feature/show_feature.txt b/tests/unit/modules/network/nxos/fixtures/nxos_feature/show_feature.txt index e27c595cf..b55a2089a 100644 --- a/tests/unit/modules/network/nxos/fixtures/nxos_feature/show_feature.txt +++ b/tests/unit/modules/network/nxos/fixtures/nxos_feature/show_feature.txt @@ -2,3 +2,4 @@ Feature Name Instance State -------------------- -------- ----- nve 1 disabled ospf 1 enabled +eth-port-sec 1 enabled diff --git a/tests/unit/modules/network/nxos/test_nxos_feature.py b/tests/unit/modules/network/nxos/test_nxos_feature.py index e98fbce1e..5e9ee5d4f 100644 --- a/tests/unit/modules/network/nxos/test_nxos_feature.py +++ b/tests/unit/modules/network/nxos/test_nxos_feature.py @@ -93,6 +93,11 @@ def test_nxos_feature_disable(self): result = self.execute_module(changed=True) self.assertEqual(result["commands"], ["terminal dont-ask", "no feature ospf"]) + def test_nxos_feature_port_security_disable(self): + set_module_args(dict(feature="port-security", state="disabled")) + result = self.execute_module(changed=True) + self.assertEqual(result["commands"], ["terminal dont-ask", "no feature port-security"]) + class TestNxosFeatureModuleMDS(TestNxosModule): module = nxos_feature @@ -171,3 +176,8 @@ def test_nxos_feature_disable_already_disabled(self): set_module_args(dict(feature="sftp-server", state="disabled")) result = self.execute_module(changed=False) self.assertEqual(result["commands"], []) + + def test_nxos_feature_port_security_enable(self): + set_module_args(dict(feature="port-security", state="enabled")) + result = self.execute_module(changed=True) + self.assertEqual(result["commands"], ["terminal dont-ask", "feature port-security"])