mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-06-03 14:59:09 -07:00
* change ip4 type to list of str
* Add several tests and change documentation
* Update changelogs/fragments/1088-nmcli_add_multiple_addresses_support.yml
Co-authored-by: Andrew Pantuso <ajpantuso@gmail.com>
Co-authored-by: Andrew Pantuso <ajpantuso@gmail.com>
(cherry picked from commit 50c2f3a97d
)
Co-authored-by: Alex Groshev <38885591+haddystuff@users.noreply.github.com>
This commit is contained in:
parent
342a1a7faa
commit
c7df82652f
3 changed files with 153 additions and 5 deletions
|
@ -563,6 +563,37 @@ ipv6.ignore-auto-dns: no
|
|||
ipv6.ignore-auto-routes: no
|
||||
"""
|
||||
|
||||
TESTCASE_ETHERNET_STATIC_MULTIPLE_IP4_ADDRESSES = [
|
||||
{
|
||||
'type': 'ethernet',
|
||||
'conn_name': 'non_existent_nw_device',
|
||||
'ifname': 'ethernet_non_existant',
|
||||
'ip4': ['10.10.10.10/24', '10.10.20.10/24'],
|
||||
'gw4': '10.10.10.1',
|
||||
'dns4': ['1.1.1.1', '8.8.8.8'],
|
||||
'state': 'present',
|
||||
'_ansible_check_mode': False,
|
||||
}
|
||||
]
|
||||
|
||||
TESTCASE_ETHERNET_STATIC_MULTIPLE_IP4_ADDRESSES_SHOW_OUTPUT = """\
|
||||
connection.id: non_existent_nw_device
|
||||
connection.interface-name: ethernet_non_existant
|
||||
connection.autoconnect: yes
|
||||
802-3-ethernet.mtu: auto
|
||||
ipv4.method: manual
|
||||
ipv4.addresses: 10.10.10.10/24,10.10.20.10/24
|
||||
ipv4.gateway: 10.10.10.1
|
||||
ipv4.ignore-auto-dns: no
|
||||
ipv4.ignore-auto-routes: no
|
||||
ipv4.never-default: no
|
||||
ipv4.may-fail: yes
|
||||
ipv4.dns: 1.1.1.1,8.8.8.8
|
||||
ipv6.method: auto
|
||||
ipv6.ignore-auto-dns: no
|
||||
ipv6.ignore-auto-routes: no
|
||||
"""
|
||||
|
||||
TESTCASE_WIRELESS = [
|
||||
{
|
||||
'type': 'wifi',
|
||||
|
@ -920,6 +951,24 @@ def mocked_ethernet_connection_static_unchanged(mocker):
|
|||
execute_return=(0, TESTCASE_ETHERNET_STATIC_SHOW_OUTPUT, ""))
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mocked_ethernet_connection_static_multiple_ip4_addresses_unchanged(mocker):
|
||||
mocker_set(mocker,
|
||||
connection_exists=True,
|
||||
execute_return=(0, TESTCASE_ETHERNET_STATIC_MULTIPLE_IP4_ADDRESSES_SHOW_OUTPUT, ""))
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mocked_ethernet_connection_static_modify(mocker):
|
||||
mocker_set(mocker,
|
||||
connection_exists=True,
|
||||
execute_return=None,
|
||||
execute_side_effect=(
|
||||
(0, TESTCASE_ETHERNET_STATIC_SHOW_OUTPUT, ""),
|
||||
(0, "", ""),
|
||||
))
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mocked_ethernet_connection_dhcp_to_static(mocker):
|
||||
mocker_set(mocker,
|
||||
|
@ -2456,3 +2505,83 @@ def test_gsm_connection_unchanged(mocked_gsm_connection_unchanged, capfd):
|
|||
results = json.loads(out)
|
||||
assert not results.get('failed')
|
||||
assert not results['changed']
|
||||
|
||||
|
||||
@pytest.mark.parametrize('patch_ansible_module', TESTCASE_ETHERNET_STATIC_MULTIPLE_IP4_ADDRESSES, indirect=['patch_ansible_module'])
|
||||
def test_create_ethernet_with_mulitple_ip4_addresses_static(mocked_generic_connection_create, capfd):
|
||||
"""
|
||||
Test : Create ethernet connection with static IP configuration
|
||||
"""
|
||||
|
||||
with pytest.raises(SystemExit):
|
||||
nmcli.main()
|
||||
|
||||
assert nmcli.Nmcli.execute_command.call_count == 2
|
||||
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] == 'ethernet'
|
||||
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', 'ethernet_non_existant',
|
||||
'ipv4.addresses', '10.10.10.10/24,10.10.20.10/24',
|
||||
'ipv4.gateway', '10.10.10.1',
|
||||
'ipv4.dns', '1.1.1.1,8.8.8.8']:
|
||||
assert param in add_args_text
|
||||
|
||||
up_args, up_kw = arg_list[1]
|
||||
assert up_args[0][0] == '/usr/bin/nmcli'
|
||||
assert up_args[0][1] == 'con'
|
||||
assert up_args[0][2] == 'up'
|
||||
assert up_args[0][3] == 'non_existent_nw_device'
|
||||
|
||||
out, err = capfd.readouterr()
|
||||
results = json.loads(out)
|
||||
assert not results.get('failed')
|
||||
assert results['changed']
|
||||
|
||||
|
||||
@pytest.mark.parametrize('patch_ansible_module', TESTCASE_ETHERNET_STATIC_MULTIPLE_IP4_ADDRESSES, indirect=['patch_ansible_module'])
|
||||
def test_ethernet_connection_static_with_mulitple_ip4_addresses_unchanged(mocked_ethernet_connection_static_multiple_ip4_addresses_unchanged, capfd):
|
||||
"""
|
||||
Test : Ethernet connection with static IP configuration unchanged
|
||||
"""
|
||||
with pytest.raises(SystemExit):
|
||||
nmcli.main()
|
||||
|
||||
out, err = capfd.readouterr()
|
||||
results = json.loads(out)
|
||||
assert not results.get('failed')
|
||||
assert not results['changed']
|
||||
|
||||
|
||||
@pytest.mark.parametrize('patch_ansible_module', TESTCASE_ETHERNET_STATIC_MULTIPLE_IP4_ADDRESSES, indirect=['patch_ansible_module'])
|
||||
def test_add_second_ip4_address_to_ethernet_connection(mocked_ethernet_connection_static_modify, capfd):
|
||||
"""
|
||||
Test : Modify ethernet connection from DHCP to static
|
||||
"""
|
||||
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]
|
||||
|
||||
assert args[0][0] == '/usr/bin/nmcli'
|
||||
assert args[0][1] == 'con'
|
||||
assert args[0][2] == 'modify'
|
||||
assert args[0][3] == 'non_existent_nw_device'
|
||||
|
||||
for param in ['ipv4.addresses', '10.10.10.10/24,10.10.20.10/24']:
|
||||
assert param in args[0]
|
||||
|
||||
out, err = capfd.readouterr()
|
||||
results = json.loads(out)
|
||||
assert not results.get('failed')
|
||||
assert results['changed']
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue