From 5b45f9bc46fedbef1ef0008735f5cd2d56cad8eb Mon Sep 17 00:00:00 2001 From: Shannon Mascarenhas <11484405+smasc@users.noreply.github.com> Date: Tue, 29 May 2018 12:52:02 -0500 Subject: [PATCH 1/2] Fix handling of autoconnect parameter This fixes a bug in the `network_connections` module when using the `initscripts` provider and encountering a connection with `autoconnect` set to false. It fails to write any `ONBOOT=` line to the interface's `ifcfg-*` file, which RHEL treats as equivalent to `ONBOOT=yes`. This explicitly sets `ONBOOT` for all interfaces defined, instead of relying on what RHEL considers its default value. --- library/network_connections.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/library/network_connections.py b/library/network_connections.py index 14e3d96..4dca651 100644 --- a/library/network_connections.py +++ b/library/network_connections.py @@ -1302,6 +1302,8 @@ class IfcfgUtil: if connection['autoconnect']: ifcfg['ONBOOT'] = 'yes' + else: + ifcfg['ONBOOT'] = 'no' ifcfg['DEVICE'] = connection['interface_name'] From 70e69226c12a2dbe1a865240c434223c6c6c527b Mon Sep 17 00:00:00 2001 From: Shannon Mascarenhas <11484405+smasc@users.noreply.github.com> Date: Wed, 30 May 2018 08:25:25 -0500 Subject: [PATCH 2/2] Add test for disabling autoconnect --- tests/test_network_connections.py | 65 +++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/tests/test_network_connections.py b/tests/test_network_connections.py index 5207999..7ac042d 100755 --- a/tests/test_network_connections.py +++ b/tests/test_network_connections.py @@ -347,6 +347,71 @@ class TestValidator(unittest.TestCase): }, ], ) + self.do_connections_validate( + [ + { + 'name': '5', + 'state': 'up', + 'type': 'ethernet', + 'autoconnect': False, + 'parent': None, + 'ip': { + 'gateway6': None, + 'gateway4': None, + 'route_metric4': None, + 'auto6': True, + 'dhcp4': True, + 'address': [], + 'route_append_only': False, + 'rule_append_only': False, + 'route': [], + 'dns': [], + 'dns_search': [], + 'route_metric6': None, + 'dhcp4_send_hostname': None, + }, + 'ethernet': { + 'autoneg': None, + 'duplex': None, + 'speed': 0, + }, + 'mac': None, + 'mtu': None, + 'zone': None, + 'master': None, + 'ignore_errors': None, + 'interface_name': None, + 'check_iface_exists': True, + 'force_state_change': None, + 'slave_type': None, + 'wait': None, + }, + ], + [ + { 'name': '5', + 'state': 'up', + 'type': 'ethernet', + 'autoconnect': 'no', + }, + ], + initscripts_dict_expected = [ + { + 'ifcfg': { + 'BOOTPROTO': 'dhcp', + 'IPV6INIT': 'yes', + 'IPV6_AUTOCONF': 'yes', + 'NM_CONTROLLED': 'no', + 'ONBOOT': 'no', + 'TYPE': 'Ethernet', + }, + 'keys': None, + 'route': None, + 'route6': None, + 'rule': None, + 'rule6': None, + }, + ], + ) self.do_connections_check_invalid([ { 'name': 'a', 'autoconnect': True }])