iptables, use existing validation (#83907)

also remove redundant  and wrong test
This commit is contained in:
Brian Coca
2024-09-06 16:57:05 -04:00
committed by GitHub
parent 59b3e49d70
commit 11e56d9c27
2 changed files with 1 additions and 18 deletions
+1 -4
View File
@@ -848,6 +848,7 @@ def main():
required_if=[
['jump', 'TEE', ['gateway']],
['jump', 'tee', ['gateway']],
['flush', False, ['chain']],
]
)
args = dict(
@@ -865,10 +866,6 @@ def main():
ip_version = module.params['ip_version']
iptables_path = module.get_bin_path(BINS[ip_version], True)
# Check if chain option is required
if args['flush'] is False and args['chain'] is None:
module.fail_json(msg="Either chain or flush parameter must be specified.")
if module.params.get('log_prefix', None) or module.params.get('log_level', None):
if module.params['jump'] is None:
module.params['jump'] = 'LOG'
-14
View File
@@ -22,20 +22,6 @@ def _mock_basic_commands(mocker):
mocker.patch("ansible.modules.iptables.get_iptables_version", return_value=IPTABLES_VERSION)
def test_without_required_parameters(mocker):
"""Test module without any parameters."""
mocker.patch(
"ansible.module_utils.basic.AnsibleModule.fail_json",
side_effect=fail_json,
)
set_module_args({})
with pytest.raises(AnsibleFailJson) as exc:
iptables.main()
assert exc.value.args[0]["failed"]
assert "Failed to find required executable" in exc.value.args[0]["msg"]
@pytest.mark.usefixtures('_mock_basic_commands')
def test_flush_table_without_chain(mocker):
"""Test flush without chain, flush the table."""