# Unit test failed locally on test\_iptables

**URL:** <https://forum.ansible.com/t/unit-test-failed-locally-on-test-iptables/7122>\
**Category:** Get Help\
**Tags:** ansible-test, ubuntu\
**Created:** [July 8, 2024, 7:43am UTC](https://forum.ansible.com/t/unit-test-failed-locally-on-test-iptables/7122 "2024-07-08T07:43:20Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![hakula](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/hakula/32/4126_2.png) [@hakula](https://forum.ansible.com/u/hakula)\
**Post date:** [July 8, 2024, 7:43am UTC](https://forum.ansible.com/t/unit-test-failed-locally-on-test-iptables/7122/1 "2024-07-08T07:43:21Z")

</div>

I’m new to Ansible and this forum, so uncertain if this is the right place to post. I’m learning how to contribute to the project. Before making any changes, I ran a unit test, which failed. Here are the steps to reproduce the issue:

- Install the required dependencies, and execute `source hacking/env-setup`.
- Execute `ansible-test units -v iptables --python=3.12`.
- Received an `AssertionError: assert 'Failed to find required executable' in 'Either chain or flush parameter must be specified.'`

The output is as follows. _(All home directory paths are replaced with `~`.)_

```plaintext
=================================== FAILURES ===================================
_______________________test_without_required_parameters_______________________
[gw0] linux -- Python 3.12.4 ~/ansible/venv/bin/python

mocker = <pytest_mock.plugin.MockerFixture object at 0x7fd09e207ef0>

    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"]
E AssertionError: assert 'Failed to find required executable' in 'Either chain or flush parameter must be specified.'

test/units/modules/test_iptables.py:36: AssertionError
- generated xml file: ~/ansible/test/results/junit/python3.12-modules-units.xml -

```

Here’s my local environment:

- OS: Ubuntu 22.04.4 LTS (5.10.16.3-microsoft-standard-WSL2)

- Python: 3.12.4

- Ansible:

I’ve checked the result from [Azure Pipeline](https://dev.azure.com/ansible/ansible/_build/results?buildId=116948&view=logs&j=62bae1aa-811d-5f3b-a44f-cf68dc674f86&t=01808b31-9561-58ed-cfa7-cc2d70afc012&l=494), and the test passed, so the issue is likely on my end. However, after some investigation, the output seemed quite logical to me. The execution flow is as follows:

1. `iptables.main()` is called without module arguments.
2. With `ip_version` defaulting to `'ipv4'`, `BINS[ip_version]` resolves to `'iptables'`.
3. `module.get_bin_path(BINS[ip_version], True)` is invoked, which in turn calls `get_bin_path(arg=arg, opt_dirs=opt_dirs)`, where `arg` is `'iptables'`.
4. Within `get_bin_path` (located in `process.py`), the path includes `'/usr/sbin'`, leading to the discovery of `/usr/sbin/iptables`, and thus not triggering a `ValueError`.
5. Returning back to `iptables.main()`, both `args['flush'] is False` and `args['chain'] is None` hold true, resulting in an error message stating: `Either chain or flush parameter must be specified.`
6. An `AssertionError` is raised with the message `assert 'Failed to find required executable' in 'Either chain or flush parameter must be specified.'`, as the error message does not match.

I’m wondering if I’ve missed something or if my code analysis is flawed. As a non-native speaker, I apologize for any grammatical inaccuracies. Any assistance would be appreciated. Thanks in advance!

---

<div class="post-metadata">

**Author:** ![hakula](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/hakula/32/4126_2.png) [@hakula](https://forum.ansible.com/u/hakula)\
**Post date:** [July 9, 2024, 2:44am UTC](https://forum.ansible.com/t/unit-test-failed-locally-on-test-iptables/7122/2 "2024-07-09T02:44:58Z")

</div>

The issue will be continued [here](https://github.com/ansible/ansible/issues/83554).
