1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

nmcli: do not convert undefined lists to empty strings (#4813) (#4834)

* do not convert undefined lists to empty strings

* add changelog fragment (#4813)

(cherry picked from commit 72faebffc6)

Co-authored-by: geichelberger <35195803+geichelberger@users.noreply.github.com>
This commit is contained in:
patchback[bot] 2022-06-13 12:13:05 +02:00 committed by GitHub
parent 1206900488
commit 100fffb4c1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 41 additions and 1 deletions

View file

@ -0,0 +1,2 @@
bugfixes:
- nmcli - fix error caused by adding undefined module arguments for list options (https://github.com/ansible-collections/community.general/issues/4373, https://github.com/ansible-collections/community.general/pull/4813).

View file

@ -1836,7 +1836,10 @@ class Nmcli(object):
@staticmethod @staticmethod
def list_to_string(lst): def list_to_string(lst):
return ",".join(lst or [""]) if lst is None:
return None
else:
return ",".join(lst)
@staticmethod @staticmethod
def settings_type(setting): def settings_type(setting):

View file

@ -455,6 +455,17 @@ ipv6.ignore-auto-dns: no
ipv6.ignore-auto-routes: no ipv6.ignore-auto-routes: no
""" """
TESTCASE_GENERIC_ZONE_ONLY = [
{
'type': 'generic',
'conn_name': 'non_existent_nw_device',
'ifname': 'generic_non_existant',
'state': 'present',
'zone': 'public',
'_ansible_check_mode': False,
}
]
TESTCASE_BOND = [ TESTCASE_BOND = [
{ {
'type': 'bond', 'type': 'bond',
@ -1888,6 +1899,30 @@ def test_generic_connection_zone_unchanged(mocked_generic_connection_zone_unchan
assert not results['changed'] assert not results['changed']
@pytest.mark.parametrize('patch_ansible_module', TESTCASE_GENERIC_ZONE_ONLY, indirect=['patch_ansible_module'])
def test_generic_connection_modify_zone_only(mocked_generic_connection_modify, capfd):
"""
Test : Generic connection modified with zone only
"""
with pytest.raises(SystemExit):
nmcli.main()
assert nmcli.Nmcli.execute_command.call_count == 1
arg_list = nmcli.Nmcli.execute_command.call_args_list
args, kwargs = arg_list[0]
assert 'connection.zone' in args[0]
assert 'ipv4.addresses' not in args[0]
assert 'ipv4.gateway' not in args[0]
assert 'ipv6.addresses' not in args[0]
assert 'ipv6.gateway' not in args[0]
out, err = capfd.readouterr()
results = json.loads(out)
assert not results.get('failed')
assert results['changed']
@pytest.mark.parametrize('patch_ansible_module', TESTCASE_CONNECTION, indirect=['patch_ansible_module']) @pytest.mark.parametrize('patch_ansible_module', TESTCASE_CONNECTION, indirect=['patch_ansible_module'])
def test_zone_none(mocked_connection_exists, capfd): def test_zone_none(mocked_connection_exists, capfd):
""" """