Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix dummy interface returning changed #3625

Prev Previous commit
Next Next commit
Fix pylint problems and remove 2 lines from previous version of bugfix
  • Loading branch information
haddystuff committed Nov 8, 2021
commit 88eca359e3ba9cac4a2e5b17c83f8b6218de6b37
5 changes: 1 addition & 4 deletions plugins/modules/net_tools/nmcli.py
Original file line number Diff line number Diff line change
Expand Up @@ -1697,9 +1697,6 @@ def _compare_conn_params(self, conn_info, options):
current_value = current_value.strip('"')
if key == self.mtu_setting and self.mtu is None:
self.mtu = 0
elif key == self.mtu_setting:
# if self.mtu_setting parameter doesn't exist, NetworkManager behave like it's set to 'auto'
current_value = 'auto'
else:
# parameter does not exist
current_value = None
Expand All @@ -1709,7 +1706,7 @@ def _compare_conn_params(self, conn_info, options):
if sorted(current_value) != sorted(value):
changed = True
elif all([key == self.mtu_setting, self.type == 'dummy', current_value is None, value =='auto', self.mtu is None]):
value = None
value = None
else:
if current_value != to_text(value):
changed = True
Expand Down
10 changes: 6 additions & 4 deletions tests/unit/plugins/modules/net_tools/test_nmcli.py
Original file line number Diff line number Diff line change
Expand Up @@ -993,12 +993,14 @@ def mocked_dummy_connection_static_unchanged(mocker):
connection_exists=True,
execute_return=(0, TESTCASE_DUMMY_STATIC_SHOW_OUTPUT, ""))


@pytest.fixture
def mocked_dummy_connection_static_without_mtu_unchanged(mocker):
mocker_set(mocker,
connection_exists=True,
execute_return=(0, TESTCASE_DUMMY_STATIC_WITHOUT_MTU_SHOW_OUTPUT, ""))


@pytest.fixture
def mocked_dummy_connection_static_with_custom_mtu_modify(mocker):
mocker_set(mocker,
Expand All @@ -1009,6 +1011,7 @@ def mocked_dummy_connection_static_with_custom_mtu_modify(mocker):
(0, "", ""),
))


@pytest.fixture
def mocked_gsm_connection_unchanged(mocker):
mocker_set(mocker,
Expand Down Expand Up @@ -2358,9 +2361,9 @@ def test_dummy_connection_static_with_custom_mtu_modify(mocked_dummy_connection_
"""
with pytest.raises(SystemExit):
nmcli.main()

assert nmcli.Nmcli.execute_command.call_count == 2

arg_list = nmcli.Nmcli.execute_command.call_args_list
args, kwargs = arg_list[1]

Expand All @@ -2379,7 +2382,6 @@ def test_dummy_connection_static_with_custom_mtu_modify(mocked_dummy_connection_
assert results['changed']



@pytest.mark.parametrize('patch_ansible_module', TESTCASE_GSM, indirect=['patch_ansible_module'])
def test_create_gsm(mocked_generic_connection_create, capfd):
"""
Expand Down Expand Up @@ -2453,4 +2455,4 @@ def test_gsm_connection_unchanged(mocked_gsm_connection_unchanged, capfd):
out, err = capfd.readouterr()
results = json.loads(out)
assert not results.get('failed')
assert not results['changed']
assert not results['changed']