1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Remove nmcli modify dependency on type parameter (#4108) (#4320)

* Remove nmcli modify dependency on type parameter

* Add fragment

* Add newline for lint

* Fixed linting for tests

* Fix fragment

* Move aliases to ip_conn_type function

* Remove connection_map

* Updated fragment

* Fixed fragment

Co-authored-by: Trey West <--local>
(cherry picked from commit 1ca7894d30)

Co-authored-by: Trey West <treywest45th@gmail.com>
This commit is contained in:
patchback[bot] 2022-03-06 09:26:37 +01:00 committed by GitHub
parent a0b22e4402
commit d4740ff387
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 135 additions and 0 deletions

View file

@ -0,0 +1,3 @@
minor_changes:
- nmcli - remove nmcli modify dependency on ``type`` parameter (https://github.com/ansible-collections/community.general/issues/2858).
- nmcli - add missing connection aliases ``802-3-ethernet`` and ``802-11-wireless`` (https://github.com/ansible-collections/community.general/pull/4108).

View file

@ -1528,6 +1528,7 @@ class Nmcli(object):
'bridge', 'bridge',
'dummy', 'dummy',
'ethernet', 'ethernet',
'802-3-ethernet',
'generic', 'generic',
'gre', 'gre',
'infiniband', 'infiniband',
@ -1536,6 +1537,7 @@ class Nmcli(object):
'team', 'team',
'vlan', 'vlan',
'wifi', 'wifi',
'802-11-wireless',
'gsm', 'gsm',
'wireguard', 'wireguard',
) )
@ -1895,6 +1897,12 @@ class Nmcli(object):
options = { options = {
'connection.interface-name': self.ifname, 'connection.interface-name': self.ifname,
} }
if not self.type:
current_con_type = self.show_connection().get('connection.type')
if current_con_type:
self.type = current_con_type
options.update(self.connection_options(detect_change=True)) options.update(self.connection_options(detect_change=True))
return self._compare_conn_params(self.show_connection(), options) return self._compare_conn_params(self.show_connection(), options)

View file

@ -188,6 +188,48 @@ ipv6.ignore-auto-dns: no
ipv6.ignore-auto-routes: no ipv6.ignore-auto-routes: no
""" """
TESTCASE_ETHERNET_MOD_IPV4_INT_WITH_ROUTE_AND_METRIC = [
{
'type': 'ethernet',
'conn_name': 'non_existent_nw_device',
'routes4': ['192.168.200.0/24 192.168.1.1'],
'route_metric4': 10,
'state': 'present',
'_ansible_check_mode': False,
},
]
TESTCASE_ETHERNET_MOD_IPV4_INT_WITH_ROUTE_AND_METRIC_SHOW_OUTPUT = """\
connection.id: non_existent_nw_device
connection.interface-name: ethernet_non_existant
connection.autoconnect: yes
ipv4.method: manual
ipv4.addresses: 192.168.1.10
ipv4.routes: { ip = 192.168.200.0/24, nh = 192.168.1.1 }
ipv4.route-metric: 10
"""
TESTCASE_ETHERNET_MOD_IPV6_INT_WITH_ROUTE_AND_METRIC = [
{
'type': 'ethernet',
'conn_name': 'non_existent_nw_device',
'routes6': ['fd2e:446f:d85d:5::/64 2001:beef:cafe:10::2'],
'route_metric6': 10,
'state': 'present',
'_ansible_check_mode': False,
},
]
TESTCASE_ETHERNET_MOD_IPV6_INT_WITH_ROUTE_AND_METRIC_SHOW_OUTPUT = """\
connection.id: non_existent_nw_device
connection.interface-name: ethernet_non_existant
connection.autoconnect: yes
ipv6.method: manual
ipv6.addresses: 2001:beef:cafe:10::1/64
ipv6.routes: { ip = fd2e:446f:d85d:5::/64, nh = 2001:beef:cafe:10::2 }
ipv6.route-metric 10
"""
TESTCASE_ETHERNET_ADD_IPV6_INT_WITH_MULTIPLE_ROUTES = [ TESTCASE_ETHERNET_ADD_IPV6_INT_WITH_MULTIPLE_ROUTES = [
{ {
'type': 'ethernet', 'type': 'ethernet',
@ -1273,6 +1315,28 @@ def mocked_ethernet_connection_with_ipv6_static_address_static_route_create(mock
)) ))
@pytest.fixture
def mocked_ethernet_connection_with_ipv4_static_address_static_route_metric_modify(mocker):
mocker_set(mocker,
connection_exists=True,
execute_return=None,
execute_side_effect=(
(0, TESTCASE_ETHERNET_MOD_IPV4_INT_WITH_ROUTE_AND_METRIC_SHOW_OUTPUT, ""),
(0, "", ""),
))
@pytest.fixture
def mocked_ethernet_connection_with_ipv6_static_address_static_route_metric_modify(mocker):
mocker_set(mocker,
connection_exists=True,
execute_return=None,
execute_side_effect=(
(0, TESTCASE_ETHERNET_MOD_IPV6_INT_WITH_ROUTE_AND_METRIC_SHOW_OUTPUT, ""),
(0, "", ""),
))
@pytest.fixture @pytest.fixture
def mocked_ethernet_connection_with_ipv6_static_address_multiple_static_routes_create(mocker): def mocked_ethernet_connection_with_ipv6_static_address_multiple_static_routes_create(mocker):
mocker_set(mocker, mocker_set(mocker,
@ -2424,6 +2488,36 @@ def test_ethernet_connection_static_unchanged(mocked_ethernet_connection_static_
assert not results['changed'] assert not results['changed']
@pytest.mark.parametrize('patch_ansible_module', TESTCASE_ETHERNET_MOD_IPV4_INT_WITH_ROUTE_AND_METRIC, indirect=['patch_ansible_module'])
def test_ethernet_connection_static_ipv4_address_static_route_with_metric_modify(
mocked_ethernet_connection_with_ipv4_static_address_static_route_metric_modify, capfd):
"""
Test : Modify ethernet connection with static IPv4 address and static route
"""
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 ['ipv4.routes', '192.168.200.0/24 192.168.1.1',
'ipv4.route-metric', '10']:
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')
@pytest.mark.parametrize('patch_ansible_module', TESTCASE_ETHERNET_ADD_IPV6_INT_WITH_ROUTE, indirect=['patch_ansible_module']) @pytest.mark.parametrize('patch_ansible_module', TESTCASE_ETHERNET_ADD_IPV6_INT_WITH_ROUTE, indirect=['patch_ansible_module'])
def test_ethernet_connection_static_ipv6_address_static_route_create(mocked_ethernet_connection_with_ipv6_static_address_static_route_create, capfd): def test_ethernet_connection_static_ipv6_address_static_route_create(mocked_ethernet_connection_with_ipv6_static_address_static_route_create, capfd):
""" """
@ -2459,6 +2553,36 @@ def test_ethernet_connection_static_ipv6_address_static_route_create(mocked_ethe
assert results['changed'] assert results['changed']
@pytest.mark.parametrize('patch_ansible_module', TESTCASE_ETHERNET_MOD_IPV6_INT_WITH_ROUTE_AND_METRIC, indirect=['patch_ansible_module'])
def test_ethernet_connection_static_ipv6_address_static_route_metric_modify(
mocked_ethernet_connection_with_ipv6_static_address_static_route_metric_modify, capfd):
"""
Test : Modify ethernet connection with static IPv6 address and static route
"""
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 ['ipv6.routes', 'fd2e:446f:d85d:5::/64 2001:beef:cafe:10::2',
'ipv6.route-metric', '10']:
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')
@pytest.mark.parametrize('patch_ansible_module', TESTCASE_ETHERNET_ADD_IPV6_INT_WITH_MULTIPLE_ROUTES, indirect=['patch_ansible_module']) @pytest.mark.parametrize('patch_ansible_module', TESTCASE_ETHERNET_ADD_IPV6_INT_WITH_MULTIPLE_ROUTES, indirect=['patch_ansible_module'])
def test_ethernet_connection_static_ipv6_address_multiple_static_routes_with_metric_create( def test_ethernet_connection_static_ipv6_address_multiple_static_routes_with_metric_create(
mocked_ethernet_connection_with_ipv6_static_address_multiple_static_routes_with_metric_create, capfd): mocked_ethernet_connection_with_ipv6_static_address_multiple_static_routes_with_metric_create, capfd):