Skip to content

Commit

Permalink
feat: Support autoconnect_retries
Browse files Browse the repository at this point in the history
There is no fine-grained control over the number of retries for
automatically reconnecting a network connection in the role. This
limitation can be problematic for certain use cases where extending the
retry process is critical, particularly in environments with unstable
networks. Introduce support for the `autoconnect_retries` property in nm
provider of `network_connections` variable. This feature allows users to
configure how many times NetworkManager will attempt to reconnect a
connection after a autoconnect failure, providing more control over
network stability and performance.

Resolves: https://issues.redhat.com/browse/RHEL-61599

Signed-off-by: Wen Liang <[email protected]>
  • Loading branch information
liangwen12year committed Oct 8, 2024
1 parent b08aad2 commit 5d73511
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 0 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,15 @@ By default, profiles are created with autoconnect enabled.

- For `initscripts`, this corresponds to the `ONBOOT` property.

### `autoconnect_retries`

The number of times a connection should be tried when autoactivating before giving up.
Zero means forever, -1 means the global default in NetworkManager (4 times if not
overridden). Setting this to 1 means to try activation only once before blocking
autoconnect. Note that after a timeout, NetworkManager will try to autoconnect again.

- For `NetworkManager`, this corresponds to the `connection.autoconnect-retries` property.

### `mac`

The `mac` address is optional and restricts the profile to be usable only on
Expand Down
1 change: 1 addition & 0 deletions examples/eth_simple_auto.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
state: up
type: ethernet
autoconnect: true
autoconnect_retries: 2
mac: "{{ network_mac1 }}"
mtu: 1450

Expand Down
3 changes: 3 additions & 0 deletions library/network_connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -906,6 +906,9 @@ def connection_create(self, connections, idx, connection_current=None):
s_con.set_property(NM.SETTING_CONNECTION_ID, connection["name"])
s_con.set_property(NM.SETTING_CONNECTION_UUID, connection["nm.uuid"])
s_con.set_property(NM.SETTING_CONNECTION_AUTOCONNECT, connection["autoconnect"])
s_con.set_property(
NM.SETTING_CONNECTION_AUTOCONNECT_RETRIES, connection["autoconnect_retries"]
)
s_con.set_property(
NM.SETTING_CONNECTION_INTERFACE_NAME, connection["interface_name"]
)
Expand Down
6 changes: 6 additions & 0 deletions module_utils/network_lsr/argument_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -1866,6 +1866,12 @@ def __init__(self):
"type", enum_values=ArgValidator_DictConnection.VALID_TYPES
),
ArgValidatorBool("autoconnect", default_value=True),
ArgValidatorNum(
"autoconnect_retries",
val_min=0,
val_max=UINT32_MAX,
default_value=-1,
),
ArgValidatorStr(
"port_type",
enum_values=ArgValidator_DictConnection.VALID_PORT_TYPES,
Expand Down
2 changes: 2 additions & 0 deletions tests/playbooks/tests_dummy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
- name: Play for testing dummy connection
hosts: all
vars:
autocon_retries: 2
interface: dummy0
profile: "{{ interface }}"
lsr_fail_debug:
Expand Down Expand Up @@ -30,6 +31,7 @@
lsr_assert:
- tasks/assert_profile_present.yml
- tasks/assert_device_present.yml
- tasks/assert_autoconnect_retries.yml
lsr_cleanup:
- tasks/cleanup_profile+device.yml
- tasks/check_network_dns.yml
16 changes: 16 additions & 0 deletions tests/tasks/assert_autoconnect_retries.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# SPDX-License-Identifier: BSD-3-Clause
---
- name: Get autoconnect retries
command: >
nmcli -f connection.autoconnect-retries connection show {{ profile }}
register: autoconnect_retries
ignore_errors: true
changed_when: false
- name: "Assert that autoconnect-retries is configured as specified"
assert:
that:
- autoconnect_retries.stdout.split(":")[1] | trim
== autocon_retries | string
msg: "autoconnect-retries is configured as
{{ autoconnect_retries.stdout.split(':')[1] | trim }}
but specified as {{ autocon_retries }}"
1 change: 1 addition & 0 deletions tests/tasks/create_dummy_profile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
vars:
network_connections:
- name: "{{ interface }}"
autoconnect_retries: "{{ autocon_retries }}"
state: up
type: dummy
ip:
Expand Down
36 changes: 36 additions & 0 deletions tests/unit/test_network_connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ def setUp(self):
# default values when "type" is specified and state is not
self.default_connection_settings = {
"autoconnect": True,
"autoconnect_retries": -1,
"check_iface_exists": True,
"ethernet": ETHERNET_DEFAULTS,
"ethtool": ETHTOOL_DEFAULTS,
Expand Down Expand Up @@ -591,6 +592,7 @@ def test_ethernet_two_defaults(self):
{
"actions": ["present"],
"autoconnect": True,
"autoconnect_retries": -1,
"check_iface_exists": True,
"ethernet": ETHERNET_DEFAULTS,
"ethtool": ETHTOOL_DEFAULTS,
Expand Down Expand Up @@ -651,6 +653,7 @@ def test_up_ethernet(self):
{
"actions": ["present", "up"],
"autoconnect": True,
"autoconnect_retries": -1,
"check_iface_exists": True,
"ethernet": ETHERNET_DEFAULTS,
"ethtool": ETHTOOL_DEFAULTS,
Expand Down Expand Up @@ -706,6 +709,7 @@ def test_up_ethernet_no_autoconnect(self):
{
"actions": ["present", "up"],
"autoconnect": False,
"autoconnect_retries": -1,
"check_iface_exists": True,
"ethernet": ETHERNET_DEFAULTS,
"ethtool": ETHTOOL_DEFAULTS,
Expand Down Expand Up @@ -798,6 +802,7 @@ def test_up_ethernet_mac_mtu_static_ip(self):
{
"actions": ["present", "up"],
"autoconnect": True,
"autoconnect_retries": -1,
"check_iface_exists": True,
"ethernet": ETHERNET_DEFAULTS,
"ethtool": ETHTOOL_DEFAULTS,
Expand Down Expand Up @@ -870,6 +875,7 @@ def test_up_single_v4_dns(self):
{
"actions": ["present", "up"],
"autoconnect": True,
"autoconnect_retries": -1,
"check_iface_exists": True,
"ethernet": ETHERNET_DEFAULTS,
"ethtool": ETHTOOL_DEFAULTS,
Expand Down Expand Up @@ -939,6 +945,7 @@ def test_ipv6_static(self):
{
"actions": ["present", "up"],
"autoconnect": True,
"autoconnect_retries": -1,
"check_iface_exists": True,
"ethernet": ETHERNET_DEFAULTS,
"ethtool": ETHTOOL_DEFAULTS,
Expand Down Expand Up @@ -1047,6 +1054,7 @@ def test_routes(self):
{
"actions": ["present", "up"],
"autoconnect": True,
"autoconnect_retries": -1,
"check_iface_exists": True,
"ethernet": ETHERNET_DEFAULTS,
"ethtool": ETHTOOL_DEFAULTS,
Expand Down Expand Up @@ -1105,6 +1113,7 @@ def test_routes(self):
{
"actions": ["present", "up"],
"autoconnect": True,
"autoconnect_retries": -1,
"check_iface_exists": True,
"ethernet": ETHERNET_DEFAULTS,
"ethtool": ETHTOOL_DEFAULTS,
Expand Down Expand Up @@ -1209,6 +1218,7 @@ def test_auto_gateway_true(self):
{
"actions": ["present", "up"],
"autoconnect": True,
"autoconnect_retries": -1,
"check_iface_exists": True,
"ethernet": ETHERNET_DEFAULTS,
"ethtool": ETHTOOL_DEFAULTS,
Expand Down Expand Up @@ -1290,6 +1300,7 @@ def test_auto_gateway_false(self):
{
"actions": ["present", "up"],
"autoconnect": True,
"autoconnect_retries": -1,
"check_iface_exists": True,
"ethernet": ETHERNET_DEFAULTS,
"ethtool": ETHTOOL_DEFAULTS,
Expand Down Expand Up @@ -1389,6 +1400,7 @@ def test_vlan(self):
{
"actions": ["present", "up"],
"autoconnect": True,
"autoconnect_retries": -1,
"check_iface_exists": True,
"ethernet": ETHERNET_DEFAULTS,
"ethtool": ETHTOOL_DEFAULTS,
Expand Down Expand Up @@ -1447,6 +1459,7 @@ def test_vlan(self):
{
"actions": ["present", "up"],
"autoconnect": True,
"autoconnect_retries": -1,
"check_iface_exists": True,
"ethernet": ETHERNET_DEFAULTS,
"ethtool": ETHTOOL_DEFAULTS,
Expand Down Expand Up @@ -1551,6 +1564,7 @@ def test_macvlan(self):
{
"actions": ["present", "up"],
"autoconnect": True,
"autoconnect_retries": -1,
"check_iface_exists": True,
"ethernet": ETHERNET_DEFAULTS,
"ethtool": ETHTOOL_DEFAULTS,
Expand Down Expand Up @@ -1604,6 +1618,7 @@ def test_macvlan(self):
{
"actions": ["present", "up"],
"autoconnect": True,
"autoconnect_retries": -1,
"check_iface_exists": True,
"ethtool": ETHTOOL_DEFAULTS,
"force_state_change": None,
Expand Down Expand Up @@ -1668,6 +1683,7 @@ def test_macvlan(self):
{
"actions": ["present", "up"],
"autoconnect": True,
"autoconnect_retries": -1,
"check_iface_exists": True,
"ethtool": ETHTOOL_DEFAULTS,
"force_state_change": None,
Expand Down Expand Up @@ -1781,6 +1797,7 @@ def test_bridge_no_dhcp4_auto6(self):
{
"actions": ["present", "up"],
"autoconnect": True,
"autoconnect_retries": -1,
"check_iface_exists": True,
"ethernet": ETHERNET_DEFAULTS,
"ethtool": ETHTOOL_DEFAULTS,
Expand Down Expand Up @@ -1828,6 +1845,7 @@ def test_bridge_no_dhcp4_auto6(self):
{
"actions": ["present", "up"],
"autoconnect": True,
"autoconnect_retries": -1,
"check_iface_exists": True,
"ethernet": ETHERNET_DEFAULTS,
"ethtool": ETHTOOL_DEFAULTS,
Expand Down Expand Up @@ -1898,6 +1916,7 @@ def test_bond(self):
{
"actions": ["present", "up"],
"autoconnect": True,
"autoconnect_retries": -1,
"bond": {
"mode": "balance-rr",
"ad_actor_sys_prio": None,
Expand Down Expand Up @@ -1981,6 +2000,7 @@ def test_bond_active_backup(self):
{
"actions": ["present", "up"],
"autoconnect": True,
"autoconnect_retries": -1,
"bond": {
"mode": "active-backup",
"ad_actor_sys_prio": None,
Expand Down Expand Up @@ -2076,6 +2096,7 @@ def test_ethernet_mac_address(self):
{
"actions": ["present"],
"autoconnect": True,
"autoconnect_retries": -1,
"check_iface_exists": True,
"ethernet": ETHERNET_DEFAULTS,
"ethtool": ETHTOOL_DEFAULTS,
Expand Down Expand Up @@ -2129,6 +2150,7 @@ def test_ethernet_speed_settings(self):
{
"actions": ["present", "up"],
"autoconnect": True,
"autoconnect_retries": -1,
"check_iface_exists": True,
"ethernet": {"autoneg": False, "duplex": "half", "speed": 400},
"ethtool": ETHTOOL_DEFAULTS,
Expand Down Expand Up @@ -2211,6 +2233,7 @@ def test_bridge2(self):
{
"actions": ["present", "up"],
"autoconnect": True,
"autoconnect_retries": -1,
"check_iface_exists": True,
"ethernet": ETHERNET_DEFAULTS,
"ethtool": ETHTOOL_DEFAULTS,
Expand Down Expand Up @@ -2258,6 +2281,7 @@ def test_bridge2(self):
{
"actions": ["present", "up"],
"autoconnect": True,
"autoconnect_retries": -1,
"check_iface_exists": True,
"ethernet": ETHERNET_DEFAULTS,
"ethtool": ETHTOOL_DEFAULTS,
Expand Down Expand Up @@ -2321,6 +2345,7 @@ def test_infiniband(self):
{
"actions": ["present", "up"],
"autoconnect": True,
"autoconnect_retries": -1,
"check_iface_exists": True,
"ethtool": ETHTOOL_DEFAULTS,
"force_state_change": None,
Expand Down Expand Up @@ -2401,6 +2426,7 @@ def test_infiniband2(self):
{
"actions": ["present", "up"],
"autoconnect": True,
"autoconnect_retries": -1,
"check_iface_exists": True,
"ethtool": ETHTOOL_DEFAULTS,
"force_state_change": None,
Expand Down Expand Up @@ -2488,6 +2514,7 @@ def test_infiniband3(self):
{
"actions": ["present"],
"autoconnect": True,
"autoconnect_retries": -1,
"check_iface_exists": True,
"ethtool": ETHTOOL_DEFAULTS,
"ignore_errors": None,
Expand Down Expand Up @@ -2533,6 +2560,7 @@ def test_infiniband3(self):
{
"actions": ["present", "up"],
"autoconnect": True,
"autoconnect_retries": -1,
"check_iface_exists": True,
"ethtool": ETHTOOL_DEFAULTS,
"force_state_change": None,
Expand Down Expand Up @@ -2644,6 +2672,7 @@ def test_route_metric_prefix(self):
{
"actions": ["present", "up"],
"autoconnect": True,
"autoconnect_retries": -1,
"check_iface_exists": True,
"ethernet": ETHERNET_DEFAULTS,
"ethtool": ETHTOOL_DEFAULTS,
Expand Down Expand Up @@ -2752,6 +2781,7 @@ def test_route_v6(self):
{
"actions": ["present", "up"],
"autoconnect": True,
"autoconnect_retries": -1,
"check_iface_exists": True,
"ethernet": ETHERNET_DEFAULTS,
"ethtool": ETHTOOL_DEFAULTS,
Expand Down Expand Up @@ -2911,6 +2941,7 @@ def test_route_without_interface_name(self):
{
"actions": ["present", "up"],
"autoconnect": True,
"autoconnect_retries": -1,
"check_iface_exists": True,
"ethernet": ETHERNET_DEFAULTS,
"ethtool": ETHTOOL_DEFAULTS,
Expand Down Expand Up @@ -3071,6 +3102,7 @@ def test_802_1x_1(self):
{
"actions": ["present", "up"],
"autoconnect": True,
"autoconnect_retries": -1,
"check_iface_exists": True,
"ethernet": ETHERNET_DEFAULTS,
"ethtool": ETHTOOL_DEFAULTS,
Expand Down Expand Up @@ -3155,6 +3187,7 @@ def test_802_1x_2(self):
{
"actions": ["present", "up"],
"autoconnect": True,
"autoconnect_retries": -1,
"check_iface_exists": True,
"ethernet": ETHERNET_DEFAULTS,
"ethtool": ETHTOOL_DEFAULTS,
Expand Down Expand Up @@ -3239,6 +3272,7 @@ def test_802_1x_3(self):
{
"actions": ["present", "up"],
"autoconnect": True,
"autoconnect_retries": -1,
"check_iface_exists": True,
"ethernet": ETHERNET_DEFAULTS,
"ethtool": ETHTOOL_DEFAULTS,
Expand Down Expand Up @@ -3322,6 +3356,7 @@ def test_wireless_psk(self):
{
"actions": ["present", "up"],
"autoconnect": True,
"autoconnect_retries": -1,
"check_iface_exists": True,
"ethtool": ETHTOOL_DEFAULTS,
"force_state_change": None,
Expand Down Expand Up @@ -3394,6 +3429,7 @@ def test_wireless_eap(self):
{
"actions": ["present", "up"],
"autoconnect": True,
"autoconnect_retries": -1,
"check_iface_exists": True,
"ethtool": ETHTOOL_DEFAULTS,
"force_state_change": None,
Expand Down

0 comments on commit 5d73511

Please sign in to comment.