iptables, use existing validation (#83907)

also remove redundant  and wrong test
pull/83920/head
Brian Coca 3 months ago committed by GitHub
parent 59b3e49d70
commit 11e56d9c27
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -848,6 +848,7 @@ def main():
required_if=[ required_if=[
['jump', 'TEE', ['gateway']], ['jump', 'TEE', ['gateway']],
['jump', 'tee', ['gateway']], ['jump', 'tee', ['gateway']],
['flush', False, ['chain']],
] ]
) )
args = dict( args = dict(
@ -865,10 +866,6 @@ def main():
ip_version = module.params['ip_version'] ip_version = module.params['ip_version']
iptables_path = module.get_bin_path(BINS[ip_version], True) 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.get('log_prefix', None) or module.params.get('log_level', None):
if module.params['jump'] is None: if module.params['jump'] is None:
module.params['jump'] = 'LOG' module.params['jump'] = 'LOG'

@ -22,20 +22,6 @@ def _mock_basic_commands(mocker):
mocker.patch("ansible.modules.iptables.get_iptables_version", return_value=IPTABLES_VERSION) 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') @pytest.mark.usefixtures('_mock_basic_commands')
def test_flush_table_without_chain(mocker): def test_flush_table_without_chain(mocker):
"""Test flush without chain, flush the table.""" """Test flush without chain, flush the table."""

Loading…
Cancel
Save