From 11e56d9c27cdee08e0fd94efe530a9f09e4aaa43 Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Fri, 6 Sep 2024 16:57:05 -0400 Subject: [PATCH] iptables, use existing validation (#83907) also remove redundant and wrong test --- lib/ansible/modules/iptables.py | 5 +---- test/units/modules/test_iptables.py | 14 -------------- 2 files changed, 1 insertion(+), 18 deletions(-) diff --git a/lib/ansible/modules/iptables.py b/lib/ansible/modules/iptables.py index 9976d805c8d..fad9b405ae4 100644 --- a/lib/ansible/modules/iptables.py +++ b/lib/ansible/modules/iptables.py @@ -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' diff --git a/test/units/modules/test_iptables.py b/test/units/modules/test_iptables.py index 67e39098391..2b93b4b62d8 100644 --- a/test/units/modules/test_iptables.py +++ b/test/units/modules/test_iptables.py @@ -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."""