mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
nmcli: add transport_mode configuration for Infiniband devices (#5361)
* Adds transport_mode configuration for Infiniband devices Adds transport_mode configuration for Infiniband based ipoib devices, which is one of: - datagram (default) - connected * Remove trailing whitespace * Add changelog fragment * Update changelogs/fragments/5361-nmcli-add-infiniband-transport-mode.yaml Co-authored-by: Felix Fontein <felix@fontein.de> * Update plugins/modules/net_tools/nmcli.py Co-authored-by: Felix Fontein <felix@fontein.de> * Update plugins/modules/net_tools/nmcli.py Co-authored-by: Felix Fontein <felix@fontein.de> * Remove default for transport_mode * Add test for changing Infiniband transport_mode * remove blank line at end of file Co-authored-by: Thomas Gebert <thomas.gebert@atos.net> Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
parent
8072d11d06
commit
b54483b52e
3 changed files with 129 additions and 0 deletions
|
@ -0,0 +1,2 @@
|
|||
minor_changes:
|
||||
- "nmcli - add ``transport_mode`` configuration for Infiniband devices (https://github.com/ansible-collections/community.general/pull/5361)."
|
|
@ -67,6 +67,12 @@ options:
|
|||
type: str
|
||||
choices: [ 802.3ad, active-backup, balance-alb, balance-rr, balance-tlb, balance-xor, broadcast ]
|
||||
default: balance-rr
|
||||
transport_mode:
|
||||
description:
|
||||
- This option sets the connection type of Infiniband IPoIB devices.
|
||||
type: str
|
||||
choices: [ datagram, connected ]
|
||||
version_added: 5.8.0
|
||||
master:
|
||||
description:
|
||||
- Master <master (ifname, or connection UUID or conn_name) of bridge, team, bond master connection profile.
|
||||
|
@ -1481,6 +1487,7 @@ class Nmcli(object):
|
|||
self.gsm = module.params['gsm']
|
||||
self.wireguard = module.params['wireguard']
|
||||
self.vpn = module.params['vpn']
|
||||
self.transport_mode = module.params['transport_mode']
|
||||
|
||||
if self.method4:
|
||||
self.ipv4_method = self.method4
|
||||
|
@ -1693,6 +1700,11 @@ class Nmcli(object):
|
|||
options.update({
|
||||
'vpn.data': vpn_data_values,
|
||||
})
|
||||
elif self.type == 'infiniband':
|
||||
options.update({
|
||||
'infiniband.transport-mode': self.transport_mode,
|
||||
})
|
||||
|
||||
# Convert settings values based on the situation.
|
||||
for setting, value in options.items():
|
||||
setting_type = self.settings_type(setting)
|
||||
|
@ -2285,6 +2297,7 @@ def main():
|
|||
gsm=dict(type='dict'),
|
||||
wireguard=dict(type='dict'),
|
||||
vpn=dict(type='dict'),
|
||||
transport_mode=dict(type='str', choices=['datagram', 'connected']),
|
||||
),
|
||||
mutually_exclusive=[['never_default4', 'gw4'],
|
||||
['routes4_extended', 'routes4'],
|
||||
|
|
|
@ -105,6 +105,12 @@ TESTCASE_CONNECTION = [
|
|||
'state': 'absent',
|
||||
'_ansible_check_mode': True,
|
||||
},
|
||||
{
|
||||
'type': 'infiniband',
|
||||
'conn_name': 'non_existent_nw_device',
|
||||
'state': 'absent',
|
||||
'_ansible_check_mode': True,
|
||||
},
|
||||
]
|
||||
|
||||
TESTCASE_GENERIC = [
|
||||
|
@ -1271,6 +1277,53 @@ vpn.service-type: org.freedesktop.NetworkManager.pptp
|
|||
vpn.data: gateway=vpn.example.com, password-flags=2, user=brittany
|
||||
"""
|
||||
|
||||
TESTCASE_INFINIBAND_STATIC = [
|
||||
{
|
||||
'type': 'infiniband',
|
||||
'conn_name': 'non_existent_nw_device',
|
||||
'ifname': 'infiniband_non_existant',
|
||||
'ip4': '10.10.10.10/24',
|
||||
'gw4': '10.10.10.1',
|
||||
'state': 'present',
|
||||
'_ansible_check_mode': False,
|
||||
}
|
||||
]
|
||||
|
||||
TESTCASE_INFINIBAND_STATIC_SHOW_OUTPUT = """\
|
||||
connection.id: non_existent_nw_device
|
||||
connection.type: infiniband
|
||||
connection.interface-name: infiniband_non_existant
|
||||
connection.autoconnect: yes
|
||||
ipv4.method: manual
|
||||
ipv4.addresses: 10.10.10.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
|
||||
ipv6.method: auto
|
||||
ipv6.ignore-auto-dns: no
|
||||
ipv6.ignore-auto-routes: no
|
||||
infiniband.transport-mode datagram
|
||||
"""
|
||||
|
||||
TESTCASE_INFINIBAND_STATIC_MODIFY_TRANSPORT_MODE = [
|
||||
{
|
||||
|
||||
'type': 'infiniband',
|
||||
'conn_name': 'non_existent_nw_device',
|
||||
'transport_mode': 'connected',
|
||||
'state': 'present',
|
||||
'_ansible_check_mode': False,
|
||||
},
|
||||
]
|
||||
|
||||
TESTCASE_INFINIBAND_STATIC_MODIFY_TRANSPORT_MODE_SHOW_OUTPUT = """\
|
||||
connection.id: non_existent_nw_device
|
||||
connection.interface-name: infiniband_non_existant
|
||||
infiniband.transport_mode: connected
|
||||
"""
|
||||
|
||||
|
||||
def mocker_set(mocker,
|
||||
connection_exists=False,
|
||||
|
@ -1655,6 +1708,24 @@ def mocked_vpn_pptp_connection_unchanged(mocker):
|
|||
execute_return=(0, TESTCASE_VPN_PPTP_SHOW_OUTPUT, ""))
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mocked_infiniband_connection_static_unchanged(mocker):
|
||||
mocker_set(mocker,
|
||||
connection_exists=True,
|
||||
execute_return=(0, TESTCASE_INFINIBAND_STATIC_SHOW_OUTPUT, ""))
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mocked_infiniband_connection_static_transport_mode_connected_modify(mocker):
|
||||
mocker_set(mocker,
|
||||
connection_exists=True,
|
||||
execute_return=None,
|
||||
execute_side_effect=(
|
||||
(0, TESTCASE_INFINIBAND_STATIC_MODIFY_TRANSPORT_MODE_SHOW_OUTPUT, ""),
|
||||
(0, "", ""),
|
||||
))
|
||||
|
||||
|
||||
@pytest.mark.parametrize('patch_ansible_module', TESTCASE_BOND, indirect=['patch_ansible_module'])
|
||||
def test_bond_connection_create(mocked_generic_connection_create, capfd):
|
||||
"""
|
||||
|
@ -3696,3 +3767,46 @@ def test_create_vpn_pptp(mocked_generic_connection_create, capfd):
|
|||
results = json.loads(out)
|
||||
assert not results.get('failed')
|
||||
assert results['changed']
|
||||
|
||||
|
||||
@pytest.mark.parametrize('patch_ansible_module', TESTCASE_INFINIBAND_STATIC, indirect=['patch_ansible_module'])
|
||||
def test_infiniband_connection_static_unchanged(mocked_infiniband_connection_static_unchanged, capfd):
|
||||
"""
|
||||
Test : Infiniband connection 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_INFINIBAND_STATIC_MODIFY_TRANSPORT_MODE, indirect=['patch_ansible_module'])
|
||||
def test_infiniband_connection_static_transport_mode_connected(
|
||||
mocked_infiniband_connection_static_transport_mode_connected_modify, capfd):
|
||||
"""
|
||||
Test : Modify Infiniband connection to use connected as transport_mode
|
||||
"""
|
||||
with pytest.raises(SystemExit):
|
||||
nmcli.main()
|
||||
|
||||
arg_list = nmcli.Nmcli.execute_command.call_args_list
|
||||
add_args, add_kw = arg_list[1]
|
||||
|
||||
assert add_args[0][0] == '/usr/bin/nmcli'
|
||||
assert add_args[0][1] == 'con'
|
||||
assert add_args[0][2] == 'modify'
|
||||
assert add_args[0][3] == 'non_existent_nw_device'
|
||||
|
||||
add_args_text = list(map(to_text, add_args[0]))
|
||||
|
||||
for param in ['infiniband.transport-mode', 'connected']:
|
||||
assert param in add_args_text
|
||||
|
||||
out, err = capfd.readouterr()
|
||||
results = json.loads(out)
|
||||
|
||||
assert results.get('changed') is True
|
||||
assert not results.get('failed')
|
||||
|
|
Loading…
Reference in a new issue