From 5961eb94353c86cf637626ebc62a31ea1193c53d Mon Sep 17 00:00:00 2001 From: "Gareth J. Greenaway" Date: Thu, 22 Sep 2022 11:01:23 -0700 Subject: [PATCH] adding changelog. updating tests to reflect changes. --- changelog/60467.fixed | 1 + tests/pytests/unit/modules/test_iptables.py | 14 ++++++++------ 2 files changed, 9 insertions(+), 6 deletions(-) create mode 100644 changelog/60467.fixed diff --git a/changelog/60467.fixed b/changelog/60467.fixed new file mode 100644 index 00000000000..6adc3e29cbf --- /dev/null +++ b/changelog/60467.fixed @@ -0,0 +1 @@ +Use return code in iptables --check to verify rule exists. diff --git a/tests/pytests/unit/modules/test_iptables.py b/tests/pytests/unit/modules/test_iptables.py index a7b52311abc..63943462429 100644 --- a/tests/pytests/unit/modules/test_iptables.py +++ b/tests/pytests/unit/modules/test_iptables.py @@ -473,9 +473,10 @@ def test_check(): with patch.object(iptables, "_has_option", mock_has): with patch.dict(iptables.__salt__, {"cmd.run_stderr": mock_cmd}): - assert iptables.check( - table="filter", chain="INPUT", rule=mock_rule, family="ipv4" - ) + with patch.dict(iptables.__context__, {"retcode": 1}): + assert not iptables.check( + table="filter", chain="INPUT", rule=mock_rule, family="ipv4" + ) mock_cmd = MagicMock(return_value="-A 0x4d2") mock_uuid = MagicMock(return_value=1234) @@ -483,9 +484,10 @@ def test_check(): with patch.object(iptables, "_has_option", mock_has): with patch.object(uuid, "getnode", mock_uuid): with patch.dict(iptables.__salt__, {"cmd.run_stderr": mock_cmd}): - assert iptables.check( - table="filter", chain="0x4d2", rule=mock_rule, family="ipv4" - ) + with patch.dict(iptables.__context__, {"retcode": 0}): + assert iptables.check( + table="filter", chain="0x4d2", rule=mock_rule, family="ipv4" + ) # 'check_chain' function tests: 1