From 5129908caa1867c7f584ec8d38607cf56b20521a Mon Sep 17 00:00:00 2001 From: Eduardo Otubo Date: Fri, 7 May 2021 13:36:06 +0200 Subject: [PATCH] Do not write NM_CONTROLLED=no in generated interface config files Conflicts 20.3: - Not appplying patch on cloudinit/net/sysconfig.py since it now has a mechanism to identify if cloud-init is running on RHEL, having the correct settings for NM_CONTROLLED. Merged patches (21.1): - ecbace48 sysconfig: Don't write BOOTPROTO=dhcp for ipv6 dhcp - a1a00383 include 'NOZEROCONF=yes' in /etc/sysconfig/network X-downstream-only: true Signed-off-by: Eduardo Otubo Signed-off-by: Ryan McCabe Signed-off-by: Ani Sinha --- cloudinit/net/sysconfig.py | 12 ++++- tests/unittests/cmd/devel/test_net_convert.py | 1 - tests/unittests/distros/test_netconfig.py | 8 --- tests/unittests/test_net.py | 53 ------------------- 4 files changed, 10 insertions(+), 64 deletions(-) diff --git a/cloudinit/net/sysconfig.py b/cloudinit/net/sysconfig.py index 7570a5e3..f01c4236 100644 --- a/cloudinit/net/sysconfig.py +++ b/cloudinit/net/sysconfig.py @@ -317,7 +317,6 @@ class Renderer(renderer.Renderer): "rhel": { "ONBOOT": True, "USERCTL": False, - "NM_CONTROLLED": False, "BOOTPROTO": "none", }, "suse": {"BOOTPROTO": "static", "STARTMODE": "auto"}, @@ -1030,7 +1029,16 @@ class Renderer(renderer.Renderer): # Distros configuring /etc/sysconfig/network as a file e.g. Centos if sysconfig_path.endswith("network"): util.ensure_dir(os.path.dirname(sysconfig_path)) - netcfg = [_make_header(), "NETWORKING=yes"] + netcfg = [] + for line in util.load_file(sysconfig_path, quiet=True).split("\n"): + if "cloud-init" in line: + break + if not line.startswith( + ("NETWORKING=", "IPV6_AUTOCONF=", "NETWORKING_IPV6=") + ): + netcfg.append(line) + # Now generate the cloud-init portion of sysconfig/network + netcfg.extend([_make_header(), "NETWORKING=yes"]) if network_state.use_ipv6: netcfg.append("NETWORKING_IPV6=yes") netcfg.append("IPV6_AUTOCONF=no") diff --git a/tests/unittests/cmd/devel/test_net_convert.py b/tests/unittests/cmd/devel/test_net_convert.py index fb72963f..7b9121b2 100644 --- a/tests/unittests/cmd/devel/test_net_convert.py +++ b/tests/unittests/cmd/devel/test_net_convert.py @@ -62,7 +62,6 @@ SAMPLE_SYSCONFIG_CONTENT = """\ # BOOTPROTO=dhcp DEVICE=eth0 -NM_CONTROLLED=no ONBOOT=yes TYPE=Ethernet USERCTL=no diff --git a/tests/unittests/distros/test_netconfig.py b/tests/unittests/distros/test_netconfig.py index 7ba430f2..962ff7fb 100644 --- a/tests/unittests/distros/test_netconfig.py +++ b/tests/unittests/distros/test_netconfig.py @@ -723,7 +723,6 @@ class TestNetCfgDistroRedhat(TestNetCfgDistroBase): GATEWAY=192.168.1.254 IPADDR=192.168.1.5 NETMASK=255.255.255.0 - NM_CONTROLLED=no ONBOOT=yes TYPE=Ethernet USERCTL=no @@ -733,7 +732,6 @@ class TestNetCfgDistroRedhat(TestNetCfgDistroBase): """\ BOOTPROTO=dhcp DEVICE=eth1 - NM_CONTROLLED=no ONBOOT=yes TYPE=Ethernet USERCTL=no @@ -764,7 +762,6 @@ class TestNetCfgDistroRedhat(TestNetCfgDistroBase): IPV6_AUTOCONF=no IPV6_DEFAULTGW=2607:f0d0:1002:0011::1 IPV6_FORCE_ACCEPT_RA=no - NM_CONTROLLED=no ONBOOT=yes TYPE=Ethernet USERCTL=no @@ -774,7 +771,6 @@ class TestNetCfgDistroRedhat(TestNetCfgDistroBase): """\ BOOTPROTO=dhcp DEVICE=eth1 - NM_CONTROLLED=no ONBOOT=yes TYPE=Ethernet USERCTL=no @@ -821,7 +817,6 @@ class TestNetCfgDistroRedhat(TestNetCfgDistroBase): HWADDR=00:16:3e:60:7c:df IPADDR=192.10.1.2 NETMASK=255.255.255.0 - NM_CONTROLLED=no ONBOOT=yes TYPE=Ethernet USERCTL=no @@ -833,7 +828,6 @@ class TestNetCfgDistroRedhat(TestNetCfgDistroBase): DEVICE=infra0 IPADDR=10.0.1.2 NETMASK=255.255.0.0 - NM_CONTROLLED=no ONBOOT=yes PHYSDEV=eth0 USERCTL=no @@ -869,7 +863,6 @@ class TestNetCfgDistroRedhat(TestNetCfgDistroBase): DEVICE=eth0 IPADDR=192.10.1.2 NETMASK=255.255.255.0 - NM_CONTROLLED=no ONBOOT=yes TYPE=Ethernet USERCTL=no @@ -881,7 +874,6 @@ class TestNetCfgDistroRedhat(TestNetCfgDistroBase): DEVICE=eth0.1001 IPADDR=10.0.1.2 NETMASK=255.255.0.0 - NM_CONTROLLED=no ONBOOT=yes PHYSDEV=eth0 USERCTL=no diff --git a/tests/unittests/test_net.py b/tests/unittests/test_net.py index c5509536..052b0674 100644 --- a/tests/unittests/test_net.py +++ b/tests/unittests/test_net.py @@ -585,7 +585,6 @@ GATEWAY=172.19.3.254 HWADDR=fa:16:3e:ed:9a:59 IPADDR=172.19.1.34 NETMASK=255.255.252.0 -NM_CONTROLLED=no ONBOOT=yes TYPE=Ethernet USERCTL=no @@ -750,7 +749,6 @@ IPADDR=172.19.1.34 IPADDR1=10.0.0.10 NETMASK=255.255.252.0 NETMASK1=255.255.255.0 -NM_CONTROLLED=no ONBOOT=yes TYPE=Ethernet USERCTL=no @@ -912,7 +910,6 @@ IPV6_AUTOCONF=no IPV6_DEFAULTGW=2001:DB8::1 IPV6_FORCE_ACCEPT_RA=no NETMASK=255.255.252.0 -NM_CONTROLLED=no ONBOOT=yes TYPE=Ethernet USERCTL=no @@ -1143,7 +1140,6 @@ NETWORK_CONFIGS = { BOOTPROTO=none DEVICE=eth1 HWADDR=cf:d6:af:48:e8:80 - NM_CONTROLLED=no ONBOOT=yes TYPE=Ethernet USERCTL=no""" @@ -1162,7 +1158,6 @@ NETWORK_CONFIGS = { IPADDR=192.168.21.3 NETMASK=255.255.255.0 METRIC=10000 - NM_CONTROLLED=no ONBOOT=yes TYPE=Ethernet USERCTL=no""" @@ -1319,7 +1314,6 @@ NETWORK_CONFIGS = { BOOTPROTO=none DEVICE=eth1 HWADDR=cf:d6:af:48:e8:80 - NM_CONTROLLED=no ONBOOT=yes TYPE=Ethernet USERCTL=no""" @@ -1338,7 +1332,6 @@ NETWORK_CONFIGS = { IPADDR=192.168.21.3 NETMASK=255.255.255.0 METRIC=10000 - NM_CONTROLLED=no ONBOOT=yes TYPE=Ethernet USERCTL=no""" @@ -1581,7 +1574,6 @@ NETWORK_CONFIGS = { IPV6_AUTOCONF=no IPV6_FORCE_ACCEPT_RA=no NETMASK=255.255.255.0 - NM_CONTROLLED=no ONBOOT=yes TYPE=Ethernet USERCTL=no @@ -1725,7 +1717,6 @@ NETWORK_CONFIGS = { DHCPV6C=yes IPV6INIT=yes DEVICE=iface0 - NM_CONTROLLED=no ONBOOT=yes TYPE=Ethernet USERCTL=no @@ -1816,7 +1807,6 @@ NETWORK_CONFIGS = { IPV6INIT=yes IPV6_FORCE_ACCEPT_RA=yes DEVICE=iface0 - NM_CONTROLLED=no ONBOOT=yes TYPE=Ethernet USERCTL=no @@ -1892,7 +1882,6 @@ NETWORK_CONFIGS = { IPV6INIT=yes IPV6_FORCE_ACCEPT_RA=no DEVICE=iface0 - NM_CONTROLLED=no ONBOOT=yes TYPE=Ethernet USERCTL=no @@ -1956,7 +1945,6 @@ NETWORK_CONFIGS = { IPV6_AUTOCONF=yes IPV6INIT=yes DEVICE=iface0 - NM_CONTROLLED=no ONBOOT=yes TYPE=Ethernet USERCTL=no @@ -2014,7 +2002,6 @@ NETWORK_CONFIGS = { IPV6_AUTOCONF=no IPV6_FORCE_ACCEPT_RA=no DEVICE=iface0 - NM_CONTROLLED=no ONBOOT=yes TYPE=Ethernet USERCTL=no @@ -2071,7 +2058,6 @@ NETWORK_CONFIGS = { IPV6_AUTOCONF=yes IPV6INIT=yes DEVICE=iface0 - NM_CONTROLLED=no ONBOOT=yes TYPE=Ethernet USERCTL=no @@ -2157,7 +2143,6 @@ NETWORK_CONFIGS = { IPV6_FAILURE_FATAL=yes IPV6_FORCE_ACCEPT_RA=yes DEVICE=iface0 - NM_CONTROLLED=no ONBOOT=yes TYPE=Ethernet USERCTL=no @@ -2198,7 +2183,6 @@ NETWORK_CONFIGS = { """\ BOOTPROTO=dhcp DEVICE=iface0 - NM_CONTROLLED=no ONBOOT=yes TYPE=Ethernet USERCTL=no @@ -2275,7 +2259,6 @@ NETWORK_CONFIGS = { BOOTPROTO=dhcp DEVICE=iface0 ETHTOOL_OPTS="wol g" - NM_CONTROLLED=no ONBOOT=yes TYPE=Ethernet USERCTL=no @@ -2619,7 +2602,6 @@ pre-down route del -net 10.0.0.0/8 gw 11.0.0.1 metric 3 || true DHCPV6C=yes IPV6INIT=yes MACADDR=aa:bb:cc:dd:ee:ff - NM_CONTROLLED=no ONBOOT=yes TYPE=Bond USERCTL=no""" @@ -2629,7 +2611,6 @@ pre-down route del -net 10.0.0.0/8 gw 11.0.0.1 metric 3 || true BOOTPROTO=dhcp DEVICE=bond0.200 DHCLIENT_SET_DEFAULT_ROUTE=no - NM_CONTROLLED=no ONBOOT=yes PHYSDEV=bond0 USERCTL=no @@ -2649,7 +2630,6 @@ pre-down route del -net 10.0.0.0/8 gw 11.0.0.1 metric 3 || true IPV6_DEFAULTGW=2001:4800:78ff:1b::1 MACADDR=bb:bb:bb:bb:bb:aa NETMASK=255.255.255.0 - NM_CONTROLLED=no ONBOOT=yes PRIO=22 STP=no @@ -2661,7 +2641,6 @@ pre-down route del -net 10.0.0.0/8 gw 11.0.0.1 metric 3 || true BOOTPROTO=none DEVICE=eth0 HWADDR=c0:d6:9f:2c:e8:80 - NM_CONTROLLED=no ONBOOT=yes TYPE=Ethernet USERCTL=no""" @@ -2680,7 +2659,6 @@ pre-down route del -net 10.0.0.0/8 gw 11.0.0.1 metric 3 || true MTU=1500 NETMASK=255.255.255.0 NETMASK1=255.255.255.0 - NM_CONTROLLED=no ONBOOT=yes PHYSDEV=eth0 USERCTL=no @@ -2692,7 +2670,6 @@ pre-down route del -net 10.0.0.0/8 gw 11.0.0.1 metric 3 || true DEVICE=eth1 HWADDR=aa:d6:9f:2c:e8:80 MASTER=bond0 - NM_CONTROLLED=no ONBOOT=yes SLAVE=yes TYPE=Ethernet @@ -2704,7 +2681,6 @@ pre-down route del -net 10.0.0.0/8 gw 11.0.0.1 metric 3 || true DEVICE=eth2 HWADDR=c0:bb:9f:2c:e8:80 MASTER=bond0 - NM_CONTROLLED=no ONBOOT=yes SLAVE=yes TYPE=Ethernet @@ -2716,7 +2692,6 @@ pre-down route del -net 10.0.0.0/8 gw 11.0.0.1 metric 3 || true BRIDGE=br0 DEVICE=eth3 HWADDR=66:bb:9f:2c:e8:80 - NM_CONTROLLED=no ONBOOT=yes TYPE=Ethernet USERCTL=no""" @@ -2727,7 +2702,6 @@ pre-down route del -net 10.0.0.0/8 gw 11.0.0.1 metric 3 || true BRIDGE=br0 DEVICE=eth4 HWADDR=98:bb:9f:2c:e8:80 - NM_CONTROLLED=no ONBOOT=yes TYPE=Ethernet USERCTL=no""" @@ -2738,7 +2712,6 @@ pre-down route del -net 10.0.0.0/8 gw 11.0.0.1 metric 3 || true DEVICE=eth5 DHCLIENT_SET_DEFAULT_ROUTE=no HWADDR=98:bb:9f:2c:e8:8a - NM_CONTROLLED=no ONBOOT=no TYPE=Ethernet USERCTL=no""" @@ -2751,7 +2724,6 @@ pre-down route del -net 10.0.0.0/8 gw 11.0.0.1 metric 3 || true IPADDR=192.168.200.7 MTU=9000 NETMASK=255.255.255.0 - NM_CONTROLLED=no ONBOOT=yes TYPE=InfiniBand USERCTL=no""" @@ -3473,7 +3445,6 @@ iface bond0 inet6 static MTU=9000 NETMASK=255.255.255.0 NETMASK1=255.255.255.0 - NM_CONTROLLED=no ONBOOT=yes TYPE=Bond USERCTL=no @@ -3485,7 +3456,6 @@ iface bond0 inet6 static DEVICE=bond0s0 HWADDR=aa:bb:cc:dd:e8:00 MASTER=bond0 - NM_CONTROLLED=no ONBOOT=yes SLAVE=yes TYPE=Ethernet @@ -3513,7 +3483,6 @@ iface bond0 inet6 static DEVICE=bond0s1 HWADDR=aa:bb:cc:dd:e8:01 MASTER=bond0 - NM_CONTROLLED=no ONBOOT=yes SLAVE=yes TYPE=Ethernet @@ -3662,7 +3631,6 @@ iface bond0 inet6 static BOOTPROTO=none DEVICE=en0 HWADDR=aa:bb:cc:dd:e8:00 - NM_CONTROLLED=no ONBOOT=yes TYPE=Ethernet USERCTL=no""" @@ -3683,7 +3651,6 @@ iface bond0 inet6 static MTU=2222 NETMASK=255.255.255.0 NETMASK1=255.255.255.0 - NM_CONTROLLED=no ONBOOT=yes PHYSDEV=en0 USERCTL=no @@ -3811,7 +3778,6 @@ iface bond0 inet6 static DEVICE=br0 IPADDR=192.168.2.2 NETMASK=255.255.255.0 - NM_CONTROLLED=no ONBOOT=yes PRIO=22 STP=no @@ -3829,7 +3795,6 @@ iface bond0 inet6 static IPV6INIT=yes IPV6_AUTOCONF=no IPV6_FORCE_ACCEPT_RA=no - NM_CONTROLLED=no ONBOOT=yes TYPE=Ethernet USERCTL=no @@ -3845,7 +3810,6 @@ iface bond0 inet6 static IPV6INIT=yes IPV6_AUTOCONF=no IPV6_FORCE_ACCEPT_RA=no - NM_CONTROLLED=no ONBOOT=yes TYPE=Ethernet USERCTL=no @@ -4030,7 +3994,6 @@ iface bond0 inet6 static HWADDR=52:54:00:12:34:00 IPADDR=192.168.1.2 NETMASK=255.255.255.0 - NM_CONTROLLED=no ONBOOT=no TYPE=Ethernet USERCTL=no @@ -4042,7 +4005,6 @@ iface bond0 inet6 static DEVICE=eth1 HWADDR=52:54:00:12:34:aa MTU=1480 - NM_CONTROLLED=no ONBOOT=yes TYPE=Ethernet USERCTL=no @@ -4053,7 +4015,6 @@ iface bond0 inet6 static BOOTPROTO=none DEVICE=eth2 HWADDR=52:54:00:12:34:ff - NM_CONTROLLED=no ONBOOT=no TYPE=Ethernet USERCTL=no @@ -4138,7 +4099,6 @@ iface bond0 inet6 static BOOTPROTO=none DEVICE=eth0 HWADDR=cf:d6:af:48:e8:80 - NM_CONTROLLED=no ONBOOT=yes TYPE=Ethernet USERCTL=no""" @@ -4736,7 +4696,6 @@ class TestRhelSysConfigRendering(CiTestCase): BOOTPROTO=dhcp DEVICE=eth1000 HWADDR=07-1c-c6-75-a4-be -NM_CONTROLLED=no ONBOOT=yes TYPE=Ethernet USERCTL=no @@ -4948,7 +4907,6 @@ GATEWAY=10.0.2.2 HWADDR=52:54:00:12:34:00 IPADDR=10.0.2.15 NETMASK=255.255.255.0 -NM_CONTROLLED=no ONBOOT=yes TYPE=Ethernet USERCTL=no @@ -4979,7 +4937,6 @@ HWADDR=fa:16:3e:25:b4:59 IPADDR=51.68.89.122 MTU=1500 NETMASK=255.255.240.0 -NM_CONTROLLED=no ONBOOT=yes TYPE=Ethernet USERCTL=no @@ -4993,7 +4950,6 @@ DEVICE=eth1 DHCLIENT_SET_DEFAULT_ROUTE=no HWADDR=fa:16:3e:b1:ca:29 MTU=9000 -NM_CONTROLLED=no ONBOOT=yes TYPE=Ethernet USERCTL=no @@ -5018,7 +4974,6 @@ USERCTL=no # BOOTPROTO=dhcp DEVICE=eth0 -NM_CONTROLLED=no ONBOOT=yes TYPE=Ethernet USERCTL=no @@ -5251,7 +5206,6 @@ USERCTL=no IPV6_FORCE_ACCEPT_RA=no IPV6_DEFAULTGW=2001:db8::1 NETMASK=255.255.255.0 - NM_CONTROLLED=no ONBOOT=yes TYPE=Ethernet USERCTL=no @@ -5283,7 +5237,6 @@ USERCTL=no """\ BOOTPROTO=none DEVICE=eno1 - NM_CONTROLLED=no ONBOOT=yes TYPE=Ethernet USERCTL=no @@ -5296,7 +5249,6 @@ USERCTL=no IPADDR=192.6.1.9 MTU=1495 NETMASK=255.255.255.0 - NM_CONTROLLED=no ONBOOT=yes PHYSDEV=eno1 USERCTL=no @@ -5332,7 +5284,6 @@ USERCTL=no IPADDR=10.101.8.65 MTU=1334 NETMASK=255.255.255.192 - NM_CONTROLLED=no ONBOOT=yes TYPE=Bond USERCTL=no @@ -5344,7 +5295,6 @@ USERCTL=no BOOTPROTO=none DEVICE=enp0s0 MASTER=bond0 - NM_CONTROLLED=no ONBOOT=yes SLAVE=yes TYPE=Bond @@ -5357,7 +5307,6 @@ USERCTL=no BOOTPROTO=none DEVICE=enp0s1 MASTER=bond0 - NM_CONTROLLED=no ONBOOT=yes SLAVE=yes TYPE=Bond @@ -5388,7 +5337,6 @@ USERCTL=no DEVICE=eno1 HWADDR=07-1c-c6-75-a4-be METRIC=100 - NM_CONTROLLED=no ONBOOT=yes TYPE=Ethernet USERCTL=no @@ -5479,7 +5427,6 @@ USERCTL=no IPV6_FORCE_ACCEPT_RA=no MTU=1400 NETMASK=255.255.248.0 - NM_CONTROLLED=no ONBOOT=yes TYPE=Ethernet USERCTL=no