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)
* do not convert undefined lists to empty strings * add changelog fragment (#4813)
This commit is contained in:
parent
e51221896b
commit
72faebffc6
3 changed files with 41 additions and 1 deletions
2
changelogs/fragments/4813-fix-nmcli-convert-list.yaml
Normal file
2
changelogs/fragments/4813-fix-nmcli-convert-list.yaml
Normal 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).
|
|
@ -1836,7 +1836,10 @@ class Nmcli(object):
|
|||
|
||||
@staticmethod
|
||||
def list_to_string(lst):
|
||||
return ",".join(lst or [""])
|
||||
if lst is None:
|
||||
return None
|
||||
else:
|
||||
return ",".join(lst)
|
||||
|
||||
@staticmethod
|
||||
def settings_type(setting):
|
||||
|
|
|
@ -455,6 +455,17 @@ ipv6.ignore-auto-dns: 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 = [
|
||||
{
|
||||
'type': 'bond',
|
||||
|
@ -1888,6 +1899,30 @@ def test_generic_connection_zone_unchanged(mocked_generic_connection_zone_unchan
|
|||
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'])
|
||||
def test_zone_none(mocked_connection_exists, capfd):
|
||||
"""
|
||||
|
|
Loading…
Reference in a new issue