2017-12-20 08:18:22 +01:00
|
|
|
# Copyright: (c) 2017 Ansible Project
|
|
|
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
|
|
|
|
|
|
|
import json
|
|
|
|
|
2018-01-26 17:21:59 +01:00
|
|
|
import pytest
|
|
|
|
|
2017-12-20 08:18:22 +01:00
|
|
|
from ansible.modules.net_tools import nmcli
|
|
|
|
|
|
|
|
pytestmark = pytest.mark.usefixtures('patch_ansible_module')
|
|
|
|
|
2018-01-02 12:37:22 +01:00
|
|
|
TESTCASE_CONNECTION = [
|
2017-12-20 08:18:22 +01:00
|
|
|
{
|
|
|
|
'type': 'ethernet',
|
|
|
|
'conn_name': 'non_existent_nw_device',
|
|
|
|
'state': 'absent',
|
|
|
|
'_ansible_check_mode': True,
|
2018-01-02 12:37:22 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
'type': 'generic',
|
|
|
|
'conn_name': 'non_existent_nw_device',
|
|
|
|
'state': 'absent',
|
|
|
|
'_ansible_check_mode': True,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'type': 'team',
|
|
|
|
'conn_name': 'non_existent_nw_device',
|
|
|
|
'state': 'absent',
|
|
|
|
'_ansible_check_mode': True,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'type': 'bond',
|
|
|
|
'conn_name': 'non_existent_nw_device',
|
|
|
|
'state': 'absent',
|
|
|
|
'_ansible_check_mode': True,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'type': 'bond-slave',
|
|
|
|
'conn_name': 'non_existent_nw_device',
|
|
|
|
'state': 'absent',
|
|
|
|
'_ansible_check_mode': True,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'type': 'bridge',
|
|
|
|
'conn_name': 'non_existent_nw_device',
|
|
|
|
'state': 'absent',
|
|
|
|
'_ansible_check_mode': True,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'type': 'vlan',
|
|
|
|
'conn_name': 'non_existent_nw_device',
|
|
|
|
'state': 'absent',
|
|
|
|
'_ansible_check_mode': True,
|
|
|
|
},
|
2018-10-30 08:17:33 +01:00
|
|
|
{
|
|
|
|
'type': 'vxlan',
|
|
|
|
'conn_name': 'non_existent_nw_device',
|
|
|
|
'state': 'absent',
|
|
|
|
'_ansible_check_mode': True,
|
|
|
|
},
|
2018-11-17 05:57:11 +01:00
|
|
|
{
|
|
|
|
'type': 'ipip',
|
|
|
|
'conn_name': 'non_existent_nw_device',
|
|
|
|
'state': 'absent',
|
|
|
|
'_ansible_check_mode': True,
|
|
|
|
},
|
2018-12-13 05:06:09 +01:00
|
|
|
{
|
|
|
|
'type': 'sit',
|
|
|
|
'conn_name': 'non_existent_nw_device',
|
|
|
|
'state': 'absent',
|
|
|
|
'_ansible_check_mode': True,
|
|
|
|
},
|
2018-01-02 12:37:22 +01:00
|
|
|
]
|
|
|
|
|
|
|
|
TESTCASE_GENERIC = [
|
|
|
|
{
|
|
|
|
'type': 'generic',
|
|
|
|
'conn_name': 'non_existent_nw_device',
|
|
|
|
'ifname': 'generic_non_existant',
|
|
|
|
'ip4': '10.10.10.10',
|
|
|
|
'gw4': '10.10.10.1',
|
|
|
|
'state': 'present',
|
|
|
|
'_ansible_check_mode': False,
|
2018-01-16 08:58:40 +01:00
|
|
|
},
|
|
|
|
]
|
|
|
|
|
|
|
|
TESTCASE_GENERIC_DNS4_SEARCH = [
|
|
|
|
{
|
|
|
|
'type': 'generic',
|
|
|
|
'conn_name': 'non_existent_nw_device',
|
|
|
|
'ifname': 'generic_non_existant',
|
|
|
|
'ip4': '10.10.10.10',
|
|
|
|
'gw4': '10.10.10.1',
|
|
|
|
'state': 'present',
|
|
|
|
'dns4_search': 'search.redhat.com',
|
|
|
|
'dns6_search': 'search6.redhat.com',
|
|
|
|
'_ansible_check_mode': False,
|
2017-12-20 08:18:22 +01:00
|
|
|
}
|
|
|
|
]
|
|
|
|
|
2018-01-08 22:37:21 +01:00
|
|
|
TESTCASE_BOND = [
|
|
|
|
{
|
|
|
|
'type': 'bond',
|
|
|
|
'conn_name': 'non_existent_nw_device',
|
|
|
|
'ifname': 'bond_non_existant',
|
|
|
|
'mode': 'active-backup',
|
|
|
|
'ip4': '10.10.10.10',
|
|
|
|
'gw4': '10.10.10.1',
|
|
|
|
'state': 'present',
|
|
|
|
'primary': 'non_existent_primary',
|
|
|
|
'_ansible_check_mode': False,
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
2018-01-24 06:30:09 +01:00
|
|
|
TESTCASE_BRIDGE = [
|
|
|
|
{
|
|
|
|
'type': 'bridge',
|
|
|
|
'conn_name': 'non_existent_nw_device',
|
|
|
|
'ifname': 'br0_non_existant',
|
|
|
|
'ip4': '10.10.10.10',
|
|
|
|
'gw4': '10.10.10.1',
|
2019-02-22 12:28:57 +01:00
|
|
|
'maxage': 100,
|
2018-01-24 06:30:09 +01:00
|
|
|
'stp': True,
|
|
|
|
'state': 'present',
|
|
|
|
'_ansible_check_mode': False,
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
|
|
|
TESTCASE_BRIDGE_SLAVE = [
|
|
|
|
{
|
|
|
|
'type': 'bridge-slave',
|
|
|
|
'conn_name': 'non_existent_nw_device',
|
|
|
|
'ifname': 'br0_non_existant',
|
|
|
|
'path_cost': 100,
|
|
|
|
'state': 'present',
|
|
|
|
'_ansible_check_mode': False,
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
2018-01-26 17:21:59 +01:00
|
|
|
TESTCASE_VLAN = [
|
|
|
|
{
|
|
|
|
'type': 'vlan',
|
|
|
|
'conn_name': 'non_existent_nw_device',
|
|
|
|
'ifname': 'vlan_not_exists',
|
|
|
|
'ip4': '10.10.10.10',
|
|
|
|
'gw4': '10.10.10.1',
|
|
|
|
'state': 'present',
|
|
|
|
'_ansible_check_mode': False,
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
2018-10-30 08:17:33 +01:00
|
|
|
TESTCASE_VXLAN = [
|
|
|
|
{
|
|
|
|
'type': 'vxlan',
|
|
|
|
'conn_name': 'non_existent_nw_device',
|
|
|
|
'ifname': 'vxlan-existent_nw_device',
|
2019-02-22 12:28:57 +01:00
|
|
|
'vxlan_id': 11,
|
2018-10-30 08:17:33 +01:00
|
|
|
'vxlan_local': '192.168.225.5',
|
|
|
|
'vxlan_remote': '192.168.225.6',
|
|
|
|
'state': 'present',
|
|
|
|
'_ansible_check_mode': False,
|
|
|
|
}
|
|
|
|
]
|
2018-01-08 22:37:21 +01:00
|
|
|
|
2018-11-17 05:57:11 +01:00
|
|
|
TESTCASE_IPIP = [
|
|
|
|
{
|
|
|
|
'type': 'ipip',
|
|
|
|
'conn_name': 'non_existent_nw_device',
|
|
|
|
'ifname': 'ipip-existent_nw_device',
|
|
|
|
'ip_tunnel_dev': 'non_existent_ipip_device',
|
|
|
|
'ip_tunnel_local': '192.168.225.5',
|
|
|
|
'ip_tunnel_remote': '192.168.225.6',
|
|
|
|
'state': 'present',
|
|
|
|
'_ansible_check_mode': False,
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
2018-12-13 05:06:09 +01:00
|
|
|
TESTCASE_SIT = [
|
|
|
|
{
|
|
|
|
'type': 'sit',
|
|
|
|
'conn_name': 'non_existent_nw_device',
|
|
|
|
'ifname': 'sit-existent_nw_device',
|
|
|
|
'ip_tunnel_dev': 'non_existent_sit_device',
|
|
|
|
'ip_tunnel_local': '192.168.225.5',
|
|
|
|
'ip_tunnel_remote': '192.168.225.6',
|
|
|
|
'state': 'present',
|
|
|
|
'_ansible_check_mode': False,
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
2018-01-30 00:02:46 +01:00
|
|
|
TESTCASE_ETHERNET_DHCP = [
|
|
|
|
{
|
|
|
|
'type': 'ethernet',
|
|
|
|
'conn_name': 'non_existent_nw_device',
|
|
|
|
'ifname': 'ethernet_non_existant',
|
|
|
|
'ip4': '10.10.10.10',
|
|
|
|
'gw4': '10.10.10.1',
|
|
|
|
'state': 'present',
|
|
|
|
'_ansible_check_mode': False,
|
|
|
|
'dhcp_client_id': '00:11:22:AA:BB:CC:DD',
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
|
|
|
|
2018-01-08 22:37:21 +01:00
|
|
|
def mocker_set(mocker, connection_exists=False):
|
|
|
|
"""
|
|
|
|
Common mocker object
|
|
|
|
"""
|
|
|
|
mocker.patch('ansible.modules.net_tools.nmcli.HAVE_DBUS', True)
|
|
|
|
mocker.patch('ansible.modules.net_tools.nmcli.HAVE_NM_CLIENT', True)
|
|
|
|
get_bin_path = mocker.patch('ansible.module_utils.basic.AnsibleModule.get_bin_path')
|
|
|
|
get_bin_path.return_value = '/usr/bin/nmcli'
|
|
|
|
connection = mocker.patch.object(nmcli.Nmcli, 'connection_exists')
|
|
|
|
connection.return_value = connection_exists
|
|
|
|
return connection
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def mocked_generic_connection_create(mocker):
|
|
|
|
mocker_set(mocker)
|
|
|
|
command_result = mocker.patch.object(nmcli.Nmcli, 'execute_command')
|
|
|
|
command_result.return_value = {"rc": 100, "out": "aaa", "err": "none"}
|
|
|
|
return command_result
|
|
|
|
|
|
|
|
|
2018-01-16 08:58:40 +01:00
|
|
|
@pytest.fixture
|
|
|
|
def mocked_generic_connection_modify(mocker):
|
|
|
|
mocker_set(mocker, connection_exists=True)
|
|
|
|
command_result = mocker.patch.object(nmcli.Nmcli, 'execute_command')
|
|
|
|
command_result.return_value = {"rc": 100, "out": "aaa", "err": "none"}
|
|
|
|
return command_result
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def mocked_connection_exists(mocker):
|
|
|
|
connection = mocker_set(mocker, connection_exists=True)
|
|
|
|
return connection
|
|
|
|
|
|
|
|
|
2018-01-08 22:37:21 +01:00
|
|
|
@pytest.mark.parametrize('patch_ansible_module', TESTCASE_BOND, indirect=['patch_ansible_module'])
|
|
|
|
def test_bond_connection_create(mocked_generic_connection_create):
|
|
|
|
"""
|
|
|
|
Test : Bond connection created
|
|
|
|
"""
|
|
|
|
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 args[0][0] == '/usr/bin/nmcli'
|
|
|
|
assert args[0][1] == 'con'
|
|
|
|
assert args[0][2] == 'add'
|
|
|
|
assert args[0][3] == 'type'
|
|
|
|
assert args[0][4] == 'bond'
|
|
|
|
assert args[0][5] == 'con-name'
|
|
|
|
assert args[0][6] == 'non_existent_nw_device'
|
|
|
|
assert args[0][7] == 'ifname'
|
|
|
|
assert args[0][8] == 'bond_non_existant'
|
|
|
|
|
2018-01-16 08:58:40 +01:00
|
|
|
for param in ['ipv4.gateway', 'primary', 'autoconnect', 'mode', 'active-backup', 'ipv4.address']:
|
|
|
|
assert param in args[0]
|
2018-01-02 12:37:22 +01:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize('patch_ansible_module', TESTCASE_GENERIC, indirect=['patch_ansible_module'])
|
|
|
|
def test_generic_connection_create(mocked_generic_connection_create):
|
|
|
|
"""
|
|
|
|
Test : Generic connection created
|
|
|
|
"""
|
|
|
|
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 args[0][0] == '/usr/bin/nmcli'
|
|
|
|
assert args[0][1] == 'con'
|
|
|
|
assert args[0][2] == 'add'
|
|
|
|
assert args[0][3] == 'type'
|
|
|
|
assert args[0][4] == 'generic'
|
|
|
|
assert args[0][5] == 'con-name'
|
|
|
|
assert args[0][6] == 'non_existent_nw_device'
|
2018-01-16 08:58:40 +01:00
|
|
|
|
|
|
|
for param in ['autoconnect', 'ipv4.gateway', 'ipv4.address']:
|
|
|
|
assert param in args[0]
|
2018-01-02 12:37:22 +01:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize('patch_ansible_module', TESTCASE_GENERIC, indirect=['patch_ansible_module'])
|
|
|
|
def test_generic_connection_modify(mocked_generic_connection_modify):
|
|
|
|
"""
|
|
|
|
Test : Generic connection modify
|
|
|
|
"""
|
|
|
|
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 args[0][0] == '/usr/bin/nmcli'
|
|
|
|
assert args[0][1] == 'con'
|
|
|
|
assert args[0][2] == 'mod'
|
|
|
|
assert args[0][3] == 'non_existent_nw_device'
|
2018-01-16 08:58:40 +01:00
|
|
|
|
|
|
|
for param in ['ipv4.gateway', 'ipv4.address']:
|
|
|
|
assert param in args[0]
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize('patch_ansible_module', TESTCASE_GENERIC_DNS4_SEARCH, indirect=['patch_ansible_module'])
|
|
|
|
def test_generic_connection_create_dns_search(mocked_generic_connection_create):
|
|
|
|
"""
|
|
|
|
Test : Generic connection created with dns search
|
|
|
|
"""
|
|
|
|
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 'ipv4.dns-search' in args[0]
|
|
|
|
assert 'ipv6.dns-search' in args[0]
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize('patch_ansible_module', TESTCASE_GENERIC_DNS4_SEARCH, indirect=['patch_ansible_module'])
|
|
|
|
def test_generic_connection_modify_dns_search(mocked_generic_connection_create):
|
|
|
|
"""
|
|
|
|
Test : Generic connection modified with dns search
|
|
|
|
"""
|
|
|
|
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 'ipv4.dns-search' in args[0]
|
|
|
|
assert 'ipv6.dns-search' in args[0]
|
2018-01-02 12:37:22 +01:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize('patch_ansible_module', TESTCASE_CONNECTION, indirect=['patch_ansible_module'])
|
2017-12-20 08:18:22 +01:00
|
|
|
def test_dns4_none(mocked_connection_exists, capfd):
|
|
|
|
"""
|
|
|
|
Test if DNS4 param is None
|
|
|
|
"""
|
|
|
|
with pytest.raises(SystemExit):
|
|
|
|
nmcli.main()
|
|
|
|
|
|
|
|
out, err = capfd.readouterr()
|
|
|
|
results = json.loads(out)
|
|
|
|
assert results['changed']
|
2018-01-24 06:30:09 +01:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize('patch_ansible_module', TESTCASE_BRIDGE, indirect=['patch_ansible_module'])
|
|
|
|
def test_create_bridge(mocked_generic_connection_create):
|
|
|
|
"""
|
|
|
|
Test if Bridge created
|
|
|
|
"""
|
|
|
|
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 args[0][0] == '/usr/bin/nmcli'
|
|
|
|
assert args[0][1] == 'con'
|
|
|
|
assert args[0][2] == 'add'
|
|
|
|
assert args[0][3] == 'type'
|
|
|
|
assert args[0][4] == 'bridge'
|
|
|
|
assert args[0][5] == 'con-name'
|
|
|
|
assert args[0][6] == 'non_existent_nw_device'
|
|
|
|
|
2019-02-22 12:28:57 +01:00
|
|
|
for param in ['ip4', '10.10.10.10', 'gw4', '10.10.10.1', 'bridge.max-age', 100, 'bridge.stp', 'yes']:
|
2018-01-24 06:30:09 +01:00
|
|
|
assert param in args[0]
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize('patch_ansible_module', TESTCASE_BRIDGE, indirect=['patch_ansible_module'])
|
|
|
|
def test_mod_bridge(mocked_generic_connection_modify):
|
|
|
|
"""
|
|
|
|
Test if Bridge modified
|
|
|
|
"""
|
|
|
|
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 args[0][0] == '/usr/bin/nmcli'
|
|
|
|
assert args[0][1] == 'con'
|
|
|
|
assert args[0][2] == 'mod'
|
|
|
|
assert args[0][3] == 'non_existent_nw_device'
|
2019-02-22 12:28:57 +01:00
|
|
|
for param in ['ip4', '10.10.10.10', 'gw4', '10.10.10.1', 'bridge.max-age', 100, 'bridge.stp', 'yes']:
|
2018-01-24 06:30:09 +01:00
|
|
|
assert param in args[0]
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize('patch_ansible_module', TESTCASE_BRIDGE_SLAVE, indirect=['patch_ansible_module'])
|
|
|
|
def test_create_bridge_slave(mocked_generic_connection_create):
|
|
|
|
"""
|
|
|
|
Test if Bridge_slave created
|
|
|
|
"""
|
|
|
|
|
|
|
|
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 args[0][0] == '/usr/bin/nmcli'
|
|
|
|
assert args[0][1] == 'con'
|
|
|
|
assert args[0][2] == 'add'
|
|
|
|
assert args[0][3] == 'type'
|
|
|
|
assert args[0][4] == 'bridge-slave'
|
|
|
|
assert args[0][5] == 'con-name'
|
|
|
|
assert args[0][6] == 'non_existent_nw_device'
|
|
|
|
|
2019-02-22 12:28:57 +01:00
|
|
|
for param in ['bridge-port.path-cost', 100]:
|
2018-01-24 06:30:09 +01:00
|
|
|
assert param in args[0]
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize('patch_ansible_module', TESTCASE_BRIDGE_SLAVE, indirect=['patch_ansible_module'])
|
|
|
|
def test_mod_bridge_slave(mocked_generic_connection_modify):
|
|
|
|
"""
|
|
|
|
Test if Bridge_slave modified
|
|
|
|
"""
|
|
|
|
|
|
|
|
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 args[0][0] == '/usr/bin/nmcli'
|
|
|
|
assert args[0][1] == 'con'
|
|
|
|
assert args[0][2] == 'mod'
|
|
|
|
assert args[0][3] == 'non_existent_nw_device'
|
|
|
|
|
2019-02-22 12:28:57 +01:00
|
|
|
for param in ['bridge-port.path-cost', 100]:
|
2018-01-24 06:30:09 +01:00
|
|
|
assert param in args[0]
|
2018-01-26 17:21:59 +01:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize('patch_ansible_module', TESTCASE_VLAN, indirect=['patch_ansible_module'])
|
|
|
|
def test_create_vlan_con(mocked_generic_connection_create):
|
|
|
|
"""
|
2018-01-30 00:02:46 +01:00
|
|
|
Test if VLAN created
|
2018-01-26 17:21:59 +01:00
|
|
|
"""
|
|
|
|
|
|
|
|
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]
|
|
|
|
|
2018-10-11 13:52:18 +02:00
|
|
|
assert args[0][0] == '/usr/bin/nmcli'
|
|
|
|
assert args[0][1] == 'con'
|
|
|
|
assert args[0][2] == 'add'
|
|
|
|
assert args[0][3] == 'type'
|
|
|
|
assert args[0][4] == 'vlan'
|
|
|
|
assert args[0][5] == 'con-name'
|
|
|
|
assert args[0][6] == 'non_existent_nw_device'
|
|
|
|
|
|
|
|
for param in ['ip4', '10.10.10.10', 'gw4', '10.10.10.1']:
|
2018-01-26 17:21:59 +01:00
|
|
|
assert param in args[0]
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize('patch_ansible_module', TESTCASE_VLAN, indirect=['patch_ansible_module'])
|
|
|
|
def test_mod_vlan_conn(mocked_generic_connection_modify):
|
|
|
|
"""
|
2018-01-30 00:02:46 +01:00
|
|
|
Test if VLAN modified
|
2018-01-26 17:21:59 +01:00
|
|
|
"""
|
|
|
|
|
|
|
|
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]
|
|
|
|
|
2018-10-11 13:52:18 +02:00
|
|
|
assert args[0][0] == '/usr/bin/nmcli'
|
|
|
|
assert args[0][1] == 'con'
|
|
|
|
assert args[0][2] == 'mod'
|
|
|
|
assert args[0][3] == 'non_existent_nw_device'
|
|
|
|
|
|
|
|
for param in ['ipv4.address', '10.10.10.10', 'ipv4.gateway', '10.10.10.1']:
|
2018-01-26 17:21:59 +01:00
|
|
|
assert param in args[0]
|
2018-01-30 00:02:46 +01:00
|
|
|
|
|
|
|
|
2018-10-30 08:17:33 +01:00
|
|
|
@pytest.mark.parametrize('patch_ansible_module', TESTCASE_VXLAN, indirect=['patch_ansible_module'])
|
|
|
|
def test_create_vxlan(mocked_generic_connection_create):
|
|
|
|
"""
|
|
|
|
Test if vxlan created
|
|
|
|
"""
|
|
|
|
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 args[0][0] == '/usr/bin/nmcli'
|
|
|
|
assert args[0][1] == 'con'
|
|
|
|
assert args[0][2] == 'add'
|
|
|
|
assert args[0][3] == 'type'
|
|
|
|
assert args[0][4] == 'vxlan'
|
|
|
|
assert args[0][5] == 'con-name'
|
|
|
|
assert args[0][6] == 'non_existent_nw_device'
|
|
|
|
assert args[0][7] == 'ifname'
|
|
|
|
|
2019-02-22 12:28:57 +01:00
|
|
|
for param in ['vxlan.local', '192.168.225.5', 'vxlan.remote', '192.168.225.6', 'vxlan.id', 11]:
|
2018-10-30 08:17:33 +01:00
|
|
|
assert param in args[0]
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize('patch_ansible_module', TESTCASE_VXLAN, indirect=['patch_ansible_module'])
|
|
|
|
def test_vxlan_mod(mocked_generic_connection_modify):
|
|
|
|
"""
|
|
|
|
Test if vxlan modified
|
|
|
|
"""
|
|
|
|
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 args[0][0] == '/usr/bin/nmcli'
|
|
|
|
assert args[0][1] == 'con'
|
|
|
|
assert args[0][2] == 'mod'
|
|
|
|
assert args[0][3] == 'non_existent_nw_device'
|
|
|
|
|
2019-02-22 12:28:57 +01:00
|
|
|
for param in ['vxlan.local', '192.168.225.5', 'vxlan.remote', '192.168.225.6', 'vxlan.id', 11]:
|
2018-10-30 08:17:33 +01:00
|
|
|
assert param in args[0]
|
|
|
|
|
|
|
|
|
2018-11-17 05:57:11 +01:00
|
|
|
@pytest.mark.parametrize('patch_ansible_module', TESTCASE_IPIP, indirect=['patch_ansible_module'])
|
|
|
|
def test_create_ipip(mocked_generic_connection_create):
|
|
|
|
"""
|
|
|
|
Test if ipip created
|
|
|
|
"""
|
|
|
|
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 args[0][0] == '/usr/bin/nmcli'
|
|
|
|
assert args[0][1] == 'con'
|
|
|
|
assert args[0][2] == 'add'
|
|
|
|
assert args[0][3] == 'type'
|
|
|
|
assert args[0][4] == 'ip-tunnel'
|
|
|
|
assert args[0][5] == 'mode'
|
|
|
|
assert args[0][6] == 'ipip'
|
|
|
|
assert args[0][7] == 'con-name'
|
|
|
|
assert args[0][8] == 'non_existent_nw_device'
|
|
|
|
assert args[0][9] == 'ifname'
|
|
|
|
assert args[0][10] == 'ipip-existent_nw_device'
|
|
|
|
assert args[0][11] == 'dev'
|
|
|
|
assert args[0][12] == 'non_existent_ipip_device'
|
|
|
|
|
|
|
|
for param in ['ip-tunnel.local', '192.168.225.5', 'ip-tunnel.remote', '192.168.225.6']:
|
|
|
|
assert param in args[0]
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize('patch_ansible_module', TESTCASE_IPIP, indirect=['patch_ansible_module'])
|
|
|
|
def test_ipip_mod(mocked_generic_connection_modify):
|
|
|
|
"""
|
|
|
|
Test if ipip modified
|
|
|
|
"""
|
|
|
|
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 args[0][0] == '/usr/bin/nmcli'
|
|
|
|
assert args[0][1] == 'con'
|
|
|
|
assert args[0][2] == 'mod'
|
|
|
|
assert args[0][3] == 'non_existent_nw_device'
|
|
|
|
|
|
|
|
for param in ['ip-tunnel.local', '192.168.225.5', 'ip-tunnel.remote', '192.168.225.6']:
|
|
|
|
assert param in args[0]
|
|
|
|
|
|
|
|
|
2018-12-13 05:06:09 +01:00
|
|
|
@pytest.mark.parametrize('patch_ansible_module', TESTCASE_SIT, indirect=['patch_ansible_module'])
|
|
|
|
def test_create_sit(mocked_generic_connection_create):
|
|
|
|
"""
|
|
|
|
Test if sit created
|
|
|
|
"""
|
|
|
|
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 args[0][0] == '/usr/bin/nmcli'
|
|
|
|
assert args[0][1] == 'con'
|
|
|
|
assert args[0][2] == 'add'
|
|
|
|
assert args[0][3] == 'type'
|
|
|
|
assert args[0][4] == 'ip-tunnel'
|
|
|
|
assert args[0][5] == 'mode'
|
|
|
|
assert args[0][6] == 'sit'
|
|
|
|
assert args[0][7] == 'con-name'
|
|
|
|
assert args[0][8] == 'non_existent_nw_device'
|
|
|
|
assert args[0][9] == 'ifname'
|
|
|
|
assert args[0][10] == 'sit-existent_nw_device'
|
|
|
|
assert args[0][11] == 'dev'
|
|
|
|
assert args[0][12] == 'non_existent_sit_device'
|
|
|
|
|
|
|
|
for param in ['ip-tunnel.local', '192.168.225.5', 'ip-tunnel.remote', '192.168.225.6']:
|
|
|
|
assert param in args[0]
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize('patch_ansible_module', TESTCASE_SIT, indirect=['patch_ansible_module'])
|
|
|
|
def test_sit_mod(mocked_generic_connection_modify):
|
|
|
|
"""
|
|
|
|
Test if sit modified
|
|
|
|
"""
|
|
|
|
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 args[0][0] == '/usr/bin/nmcli'
|
|
|
|
assert args[0][1] == 'con'
|
|
|
|
assert args[0][2] == 'mod'
|
|
|
|
assert args[0][3] == 'non_existent_nw_device'
|
|
|
|
|
|
|
|
for param in ['ip-tunnel.local', '192.168.225.5', 'ip-tunnel.remote', '192.168.225.6']:
|
|
|
|
assert param in args[0]
|
|
|
|
|
|
|
|
|
2018-01-30 00:02:46 +01:00
|
|
|
@pytest.mark.parametrize('patch_ansible_module', TESTCASE_ETHERNET_DHCP, indirect=['patch_ansible_module'])
|
|
|
|
def test_eth_dhcp_client_id_con_create(mocked_generic_connection_create):
|
|
|
|
"""
|
|
|
|
Test : Ethernet connection created with DHCP_CLIENT_ID
|
|
|
|
"""
|
|
|
|
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 'ipv4.dhcp-client-id' in args[0]
|