nmcli: Introduce IPIP Tunnel (#45933)

This work enables to add ipip tunnel via nmcli module

```
  - nmcli:
       state: present
       type: ipip
       conn_name: ipip_test1
       autoconnect: yes
       ip_tunnel_dev: enp0s8
       ip_tunnel_local: 192.168.1.2
       ip_tunnel_remote: 192.168.1.5
```

version2: Added tests
Signed-off-by: Susant Sahani <susant@redhat.com>

Rebase
This commit is contained in:
Susant Sahani 2018-11-17 10:27:11 +05:30 committed by ansibot
parent a4921cd5d9
commit 88dcb11695
2 changed files with 154 additions and 2 deletions

View file

@ -58,6 +58,13 @@ TESTCASE_CONNECTION = [
'state': 'absent',
'_ansible_check_mode': True,
},
{
'type': 'ipip',
'conn_name': 'non_existent_nw_device',
'state': 'absent',
'_ansible_check_mode': True,
},
]
TESTCASE_GENERIC = [
@ -150,6 +157,19 @@ TESTCASE_VXLAN = [
}
]
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,
}
]
TESTCASE_ETHERNET_DHCP = [
{
'type': 'ethernet',
@ -500,6 +520,57 @@ def test_vxlan_mod(mocked_generic_connection_modify):
assert param in args[0]
@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]
@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):
"""