nmcli: Fix change detection for Wi-Fi security options (#3136)

* Fixed `wifi_sec` option changes are not detected

Also updated `docs` URL and formatting to match that of the `wifi`
option

* Removed extraneous `appends` to `cmd` in `connection_update`

These really should have only been added to `connection_options` whose 
return values get `extended` onto `cmd`
This commit is contained in:
David Hummel 2021-08-07 06:20:44 -07:00 committed by GitHub
commit 6bfa6e40f4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 66 additions and 20 deletions

View file

@ -491,6 +491,22 @@ TESTCASE_WIRELESS = [
}
]
TESTCASE_SECURE_WIRELESS = [
{
'type': 'wifi',
'conn_name': 'non_existent_nw_device',
'ifname': 'wireless_non_existant',
'ip4': '10.10.10.10/24',
'ssid': 'Brittany',
'wifi_sec': {
'key-mgmt': 'wpa-psk',
'psk': 'VERY_SECURE_PASSWORD',
},
'state': 'present',
'_ansible_check_mode': False,
}
]
TESTCASE_DUMMY_STATIC = [
{
'type': 'dummy',
@ -1630,6 +1646,41 @@ def test_create_wireless(mocked_generic_connection_create, capfd):
assert results['changed']
@pytest.mark.parametrize('patch_ansible_module', TESTCASE_SECURE_WIRELESS, indirect=['patch_ansible_module'])
def test_create_secure_wireless(mocked_generic_connection_create, capfd):
"""
Test : Create secure wireless connection
"""
with pytest.raises(SystemExit):
nmcli.main()
assert nmcli.Nmcli.execute_command.call_count == 1
arg_list = nmcli.Nmcli.execute_command.call_args_list
add_args, add_kw = arg_list[0]
assert add_args[0][0] == '/usr/bin/nmcli'
assert add_args[0][1] == 'con'
assert add_args[0][2] == 'add'
assert add_args[0][3] == 'type'
assert add_args[0][4] == 'wifi'
assert add_args[0][5] == 'con-name'
assert add_args[0][6] == 'non_existent_nw_device'
add_args_text = list(map(to_text, add_args[0]))
for param in ['connection.interface-name', 'wireless_non_existant',
'ipv4.addresses', '10.10.10.10/24',
'802-11-wireless.ssid', 'Brittany',
'802-11-wireless-security.key-mgmt', 'wpa-psk',
'802-11-wireless-security.psk', 'VERY_SECURE_PASSWORD']:
assert param in add_args_text
out, err = capfd.readouterr()
results = json.loads(out)
assert not results.get('failed')
assert results['changed']
@pytest.mark.parametrize('patch_ansible_module', TESTCASE_DUMMY_STATIC, indirect=['patch_ansible_module'])
def test_create_dummy_static(mocked_generic_connection_create, capfd):
"""