Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Support autoconnect_retries #737

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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(

Check warning on line 909 in library/network_connections.py

View check run for this annotation

Codecov / codecov/patch

library/network_connections.py#L909

Added line #L909 was not covered by tests
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
@@ -1,4 +1,4 @@
# SPDX-License-Identifier: BSD-3-Clause

Check warning on line 1 in tests/tasks/create_dummy_profile.yml

View workflow job for this annotation

GitHub Actions / Detect non-inclusive language

Filename finding: `create_dummy_profile` may be insensitive, use `placeholder`, `sample` instead
---
- name: Include network role
include_role:
Expand All @@ -6,8 +6,9 @@
vars:
network_connections:
- name: "{{ interface }}"
autoconnect_retries: "{{ autocon_retries }}"
state: up
type: dummy

Check warning on line 11 in tests/tasks/create_dummy_profile.yml

View workflow job for this annotation

GitHub Actions / Detect non-inclusive language

`dummy` may be insensitive, use `placeholder`, `sample` instead
ip:
address:
- "192.0.2.42/30"
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
Loading