sailesh1993 / rpms / cloud-init

Forked from rpms/cloud-init a year ago
Clone
1160f5
From c521ec2ce5b1d9a7322ce152011b8792f121bf5c Mon Sep 17 00:00:00 2001
d9e4dd
From: Eduardo Otubo <otubo@redhat.com>
d9e4dd
Date: Fri, 7 May 2021 13:36:06 +0200
d9e4dd
Subject: Do not write NM_CONTROLLED=no in generated interface config  files
d9e4dd
d9e4dd
Conflicts 20.3:
d9e4dd
 - Not appplying patch on cloudinit/net/sysconfig.py since it now has a
d9e4dd
mechanism to identify if cloud-init is running on RHEL, having the
d9e4dd
correct settings for NM_CONTROLLED.
d9e4dd
d9e4dd
Merged patches (21.1):
d9e4dd
- ecbace48 sysconfig: Don't write BOOTPROTO=dhcp for ipv6 dhcp
d9e4dd
- a1a00383 include 'NOZEROCONF=yes' in /etc/sysconfig/network
d9e4dd
X-downstream-only: true
d9e4dd
Signed-off-by: Eduardo Otubo <otubo@redhat.com>
d9e4dd
Signed-off-by: Ryan McCabe <rmccabe@redhat.com>
d9e4dd
---
1160f5
 cloudinit/net/sysconfig.py  | 12 ++++++++++--
d9e4dd
 tests/unittests/test_net.py | 28 ----------------------------
1160f5
 2 files changed, 10 insertions(+), 30 deletions(-)
d9e4dd
d9e4dd
diff --git a/cloudinit/net/sysconfig.py b/cloudinit/net/sysconfig.py
1160f5
index ba85c4f6..d8c53312 100644
d9e4dd
--- a/cloudinit/net/sysconfig.py
d9e4dd
+++ b/cloudinit/net/sysconfig.py
1160f5
@@ -336,7 +336,6 @@ class Renderer(renderer.Renderer):
1160f5
         "rhel": {
1160f5
             "ONBOOT": True,
1160f5
             "USERCTL": False,
1160f5
-            "NM_CONTROLLED": False,
1160f5
             "BOOTPROTO": "none",
1160f5
         },
1160f5
         "suse": {"BOOTPROTO": "static", "STARTMODE": "auto"},
1160f5
@@ -1039,7 +1038,16 @@ class Renderer(renderer.Renderer):
d9e4dd
         # Distros configuring /etc/sysconfig/network as a file e.g. Centos
1160f5
         if sysconfig_path.endswith("network"):
d9e4dd
             util.ensure_dir(os.path.dirname(sysconfig_path))
1160f5
-            netcfg = [_make_header(), "NETWORKING=yes"]
d9e4dd
+            netcfg = []
d9e4dd
+            for line in util.load_file(sysconfig_path, quiet=True).split('\n'):
d9e4dd
+                if 'cloud-init' in line:
d9e4dd
+                    break
d9e4dd
+                if not line.startswith(('NETWORKING=',
d9e4dd
+                                        'IPV6_AUTOCONF=',
d9e4dd
+                                        'NETWORKING_IPV6=')):
d9e4dd
+                    netcfg.append(line)
d9e4dd
+            # Now generate the cloud-init portion of sysconfig/network
d9e4dd
+            netcfg.extend([_make_header(), 'NETWORKING=yes'])
d9e4dd
             if network_state.use_ipv6:
1160f5
                 netcfg.append("NETWORKING_IPV6=yes")
1160f5
                 netcfg.append("IPV6_AUTOCONF=no")
d9e4dd
diff --git a/tests/unittests/test_net.py b/tests/unittests/test_net.py
1160f5
index 47e4ba00..591241b3 100644
d9e4dd
--- a/tests/unittests/test_net.py
d9e4dd
+++ b/tests/unittests/test_net.py
1160f5
@@ -579,7 +579,6 @@ GATEWAY=172.19.3.254
d9e4dd
 HWADDR=fa:16:3e:ed:9a:59
d9e4dd
 IPADDR=172.19.1.34
d9e4dd
 NETMASK=255.255.252.0
d9e4dd
-NM_CONTROLLED=no
d9e4dd
 ONBOOT=yes
d9e4dd
 TYPE=Ethernet
d9e4dd
 USERCTL=no
1160f5
@@ -712,7 +711,6 @@ IPADDR=172.19.1.34
d9e4dd
 IPADDR1=10.0.0.10
d9e4dd
 NETMASK=255.255.252.0
d9e4dd
 NETMASK1=255.255.255.0
d9e4dd
-NM_CONTROLLED=no
d9e4dd
 ONBOOT=yes
d9e4dd
 TYPE=Ethernet
d9e4dd
 USERCTL=no
1160f5
@@ -874,7 +872,6 @@ IPV6_AUTOCONF=no
d9e4dd
 IPV6_DEFAULTGW=2001:DB8::1
d9e4dd
 IPV6_FORCE_ACCEPT_RA=no
d9e4dd
 NETMASK=255.255.252.0
d9e4dd
-NM_CONTROLLED=no
d9e4dd
 ONBOOT=yes
d9e4dd
 TYPE=Ethernet
d9e4dd
 USERCTL=no
1160f5
@@ -1053,7 +1050,6 @@ NETWORK_CONFIGS = {
d9e4dd
                 BOOTPROTO=none
d9e4dd
                 DEVICE=eth1
d9e4dd
                 HWADDR=cf:d6:af:48:e8:80
d9e4dd
-                NM_CONTROLLED=no
d9e4dd
                 ONBOOT=yes
d9e4dd
                 TYPE=Ethernet
1160f5
                 USERCTL=no"""
1160f5
@@ -1072,7 +1068,6 @@ NETWORK_CONFIGS = {
d9e4dd
                 IPADDR=192.168.21.3
d9e4dd
                 NETMASK=255.255.255.0
d9e4dd
                 METRIC=10000
d9e4dd
-                NM_CONTROLLED=no
d9e4dd
                 ONBOOT=yes
d9e4dd
                 TYPE=Ethernet
1160f5
                 USERCTL=no"""
1160f5
@@ -1244,7 +1239,6 @@ NETWORK_CONFIGS = {
d9e4dd
                 IPV6_AUTOCONF=no
d9e4dd
                 IPV6_FORCE_ACCEPT_RA=no
d9e4dd
                 NETMASK=255.255.255.0
d9e4dd
-                NM_CONTROLLED=no
d9e4dd
                 ONBOOT=yes
d9e4dd
                 TYPE=Ethernet
d9e4dd
                 USERCTL=no
1160f5
@@ -2093,7 +2087,6 @@ pre-down route del -net 10.0.0.0/8 gw 11.0.0.1 metric 3 || true
d9e4dd
                 DHCPV6C=yes
d9e4dd
                 IPV6INIT=yes
d9e4dd
                 MACADDR=aa:bb:cc:dd:ee:ff
d9e4dd
-                NM_CONTROLLED=no
d9e4dd
                 ONBOOT=yes
d9e4dd
                 TYPE=Bond
1160f5
                 USERCTL=no"""
1160f5
@@ -2103,7 +2096,6 @@ pre-down route del -net 10.0.0.0/8 gw 11.0.0.1 metric 3 || true
d9e4dd
                 BOOTPROTO=dhcp
d9e4dd
                 DEVICE=bond0.200
d9e4dd
                 DHCLIENT_SET_DEFAULT_ROUTE=no
d9e4dd
-                NM_CONTROLLED=no
d9e4dd
                 ONBOOT=yes
d9e4dd
                 PHYSDEV=bond0
d9e4dd
                 USERCTL=no
1160f5
@@ -2123,7 +2115,6 @@ pre-down route del -net 10.0.0.0/8 gw 11.0.0.1 metric 3 || true
d9e4dd
                 IPV6_DEFAULTGW=2001:4800:78ff:1b::1
d9e4dd
                 MACADDR=bb:bb:bb:bb:bb:aa
d9e4dd
                 NETMASK=255.255.255.0
d9e4dd
-                NM_CONTROLLED=no
d9e4dd
                 ONBOOT=yes
d9e4dd
                 PRIO=22
d9e4dd
                 STP=no
1160f5
@@ -2135,7 +2126,6 @@ pre-down route del -net 10.0.0.0/8 gw 11.0.0.1 metric 3 || true
d9e4dd
                 BOOTPROTO=none
d9e4dd
                 DEVICE=eth0
d9e4dd
                 HWADDR=c0:d6:9f:2c:e8:80
d9e4dd
-                NM_CONTROLLED=no
d9e4dd
                 ONBOOT=yes
d9e4dd
                 TYPE=Ethernet
1160f5
                 USERCTL=no"""
1160f5
@@ -2154,7 +2144,6 @@ pre-down route del -net 10.0.0.0/8 gw 11.0.0.1 metric 3 || true
d9e4dd
                 MTU=1500
d9e4dd
                 NETMASK=255.255.255.0
d9e4dd
                 NETMASK1=255.255.255.0
d9e4dd
-                NM_CONTROLLED=no
d9e4dd
                 ONBOOT=yes
d9e4dd
                 PHYSDEV=eth0
d9e4dd
                 USERCTL=no
1160f5
@@ -2166,7 +2155,6 @@ pre-down route del -net 10.0.0.0/8 gw 11.0.0.1 metric 3 || true
d9e4dd
                 DEVICE=eth1
d9e4dd
                 HWADDR=aa:d6:9f:2c:e8:80
d9e4dd
                 MASTER=bond0
d9e4dd
-                NM_CONTROLLED=no
d9e4dd
                 ONBOOT=yes
d9e4dd
                 SLAVE=yes
d9e4dd
                 TYPE=Ethernet
1160f5
@@ -2178,7 +2166,6 @@ pre-down route del -net 10.0.0.0/8 gw 11.0.0.1 metric 3 || true
d9e4dd
                 DEVICE=eth2
d9e4dd
                 HWADDR=c0:bb:9f:2c:e8:80
d9e4dd
                 MASTER=bond0
d9e4dd
-                NM_CONTROLLED=no
d9e4dd
                 ONBOOT=yes
d9e4dd
                 SLAVE=yes
d9e4dd
                 TYPE=Ethernet
1160f5
@@ -2190,7 +2177,6 @@ pre-down route del -net 10.0.0.0/8 gw 11.0.0.1 metric 3 || true
d9e4dd
                 BRIDGE=br0
d9e4dd
                 DEVICE=eth3
d9e4dd
                 HWADDR=66:bb:9f:2c:e8:80
d9e4dd
-                NM_CONTROLLED=no
d9e4dd
                 ONBOOT=yes
d9e4dd
                 TYPE=Ethernet
1160f5
                 USERCTL=no"""
1160f5
@@ -2201,7 +2187,6 @@ pre-down route del -net 10.0.0.0/8 gw 11.0.0.1 metric 3 || true
d9e4dd
                 BRIDGE=br0
d9e4dd
                 DEVICE=eth4
d9e4dd
                 HWADDR=98:bb:9f:2c:e8:80
d9e4dd
-                NM_CONTROLLED=no
d9e4dd
                 ONBOOT=yes
d9e4dd
                 TYPE=Ethernet
1160f5
                 USERCTL=no"""
1160f5
@@ -2212,7 +2197,6 @@ pre-down route del -net 10.0.0.0/8 gw 11.0.0.1 metric 3 || true
d9e4dd
                 DEVICE=eth5
d9e4dd
                 DHCLIENT_SET_DEFAULT_ROUTE=no
d9e4dd
                 HWADDR=98:bb:9f:2c:e8:8a
d9e4dd
-                NM_CONTROLLED=no
d9e4dd
                 ONBOOT=no
d9e4dd
                 TYPE=Ethernet
1160f5
                 USERCTL=no"""
1160f5
@@ -2689,7 +2673,6 @@ iface bond0 inet6 static
d9e4dd
         MTU=9000
d9e4dd
         NETMASK=255.255.255.0
d9e4dd
         NETMASK1=255.255.255.0
d9e4dd
-        NM_CONTROLLED=no
d9e4dd
         ONBOOT=yes
d9e4dd
         TYPE=Bond
d9e4dd
         USERCTL=no
1160f5
@@ -2701,7 +2684,6 @@ iface bond0 inet6 static
d9e4dd
         DEVICE=bond0s0
d9e4dd
         HWADDR=aa:bb:cc:dd:e8:00
d9e4dd
         MASTER=bond0
d9e4dd
-        NM_CONTROLLED=no
d9e4dd
         ONBOOT=yes
d9e4dd
         SLAVE=yes
d9e4dd
         TYPE=Ethernet
1160f5
@@ -2729,7 +2711,6 @@ iface bond0 inet6 static
d9e4dd
         DEVICE=bond0s1
d9e4dd
         HWADDR=aa:bb:cc:dd:e8:01
d9e4dd
         MASTER=bond0
d9e4dd
-        NM_CONTROLLED=no
d9e4dd
         ONBOOT=yes
d9e4dd
         SLAVE=yes
d9e4dd
         TYPE=Ethernet
1160f5
@@ -2794,7 +2775,6 @@ iface bond0 inet6 static
d9e4dd
                 BOOTPROTO=none
d9e4dd
                 DEVICE=en0
d9e4dd
                 HWADDR=aa:bb:cc:dd:e8:00
d9e4dd
-                NM_CONTROLLED=no
d9e4dd
                 ONBOOT=yes
d9e4dd
                 TYPE=Ethernet
1160f5
                 USERCTL=no"""
1160f5
@@ -2815,7 +2795,6 @@ iface bond0 inet6 static
d9e4dd
                 MTU=2222
d9e4dd
                 NETMASK=255.255.255.0
d9e4dd
                 NETMASK1=255.255.255.0
d9e4dd
-                NM_CONTROLLED=no
d9e4dd
                 ONBOOT=yes
d9e4dd
                 PHYSDEV=en0
d9e4dd
                 USERCTL=no
1160f5
@@ -2890,7 +2869,6 @@ iface bond0 inet6 static
d9e4dd
                 DEVICE=br0
d9e4dd
                 IPADDR=192.168.2.2
d9e4dd
                 NETMASK=255.255.255.0
d9e4dd
-                NM_CONTROLLED=no
d9e4dd
                 ONBOOT=yes
d9e4dd
                 PRIO=22
d9e4dd
                 STP=no
1160f5
@@ -3032,7 +3010,6 @@ iface bond0 inet6 static
d9e4dd
                 HWADDR=52:54:00:12:34:00
d9e4dd
                 IPADDR=192.168.1.2
d9e4dd
                 NETMASK=255.255.255.0
d9e4dd
-                NM_CONTROLLED=no
d9e4dd
                 ONBOOT=no
d9e4dd
                 TYPE=Ethernet
d9e4dd
                 USERCTL=no
1160f5
@@ -3044,7 +3021,6 @@ iface bond0 inet6 static
d9e4dd
                 DEVICE=eth1
d9e4dd
                 HWADDR=52:54:00:12:34:aa
d9e4dd
                 MTU=1480
d9e4dd
-                NM_CONTROLLED=no
d9e4dd
                 ONBOOT=yes
d9e4dd
                 TYPE=Ethernet
d9e4dd
                 USERCTL=no
1160f5
@@ -3055,7 +3031,6 @@ iface bond0 inet6 static
d9e4dd
                 BOOTPROTO=none
d9e4dd
                 DEVICE=eth2
d9e4dd
                 HWADDR=52:54:00:12:34:ff
d9e4dd
-                NM_CONTROLLED=no
d9e4dd
                 ONBOOT=no
d9e4dd
                 TYPE=Ethernet
d9e4dd
                 USERCTL=no
1160f5
@@ -3628,7 +3603,6 @@ class TestRhelSysConfigRendering(CiTestCase):
d9e4dd
 BOOTPROTO=dhcp
d9e4dd
 DEVICE=eth1000
d9e4dd
 HWADDR=07-1c-c6-75-a4-be
d9e4dd
-NM_CONTROLLED=no
d9e4dd
 ONBOOT=yes
d9e4dd
 TYPE=Ethernet
d9e4dd
 USERCTL=no
1160f5
@@ -3840,7 +3814,6 @@ GATEWAY=10.0.2.2
d9e4dd
 HWADDR=52:54:00:12:34:00
d9e4dd
 IPADDR=10.0.2.15
d9e4dd
 NETMASK=255.255.255.0
d9e4dd
-NM_CONTROLLED=no
d9e4dd
 ONBOOT=yes
d9e4dd
 TYPE=Ethernet
d9e4dd
 USERCTL=no
1160f5
@@ -3910,7 +3883,6 @@ USERCTL=no
d9e4dd
 #
d9e4dd
 BOOTPROTO=dhcp
d9e4dd
 DEVICE=eth0
d9e4dd
-NM_CONTROLLED=no
d9e4dd
 ONBOOT=yes
d9e4dd
 TYPE=Ethernet
d9e4dd
 USERCTL=no
d9e4dd
-- 
1160f5
2.31.1
d9e4dd