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