sailesh1993 / rpms / cloud-init

Forked from rpms/cloud-init 10 months ago
Clone
c3f9da
From 02924179d423c919d0d46e6149da5bb8d26dd0d5 Mon Sep 17 00:00:00 2001
c3f9da
From: Eduardo Otubo <otubo@redhat.com>
c3f9da
Date: Tue, 3 Nov 2020 12:16:37 +0100
c3f9da
Subject: [PATCH 4/5] Explicit set IPV6_AUTOCONF and IPV6_FORCE_ACCEPT_RA on
c3f9da
 static6 (#634)
c3f9da
c3f9da
RH-Author: Eduardo Terrell Ferrari Otubo (eterrell)
c3f9da
RH-MergeRequest: 17: Explicit set IPV6_AUTOCONF and IPV6_FORCE_ACCEPT_RA on static6 (#634)
c3f9da
RH-Commit: [1/2] ba604c675f7c54a3e1768945a9ba77918ca4a57b (eterrell/cloud-init)
c3f9da
RH-Bugzilla: 1894015
c3f9da
c3f9da
commit b46e4a8cff667c8441622089cf7d57aeb88220cd
c3f9da
Author: Eduardo Otubo <otubo@redhat.com>
c3f9da
Date:   Thu Oct 29 15:05:42 2020 +0100
c3f9da
c3f9da
    Explicit set IPV6_AUTOCONF and IPV6_FORCE_ACCEPT_RA on static6 (#634)
c3f9da
c3f9da
    The static and static6 subnet types for network_data.json were
c3f9da
    being ignored by the Openstack handler, this would cause the code to
c3f9da
    break and not function properly.
c3f9da
c3f9da
    As of today, if a static6 configuration is chosen, the interface will
c3f9da
    still eventually be available to receive router advertisements or be set
c3f9da
    from NetworkManager to wait for them and cycle the interface in negative
c3f9da
    case.
c3f9da
c3f9da
    It is safe to assume that if the interface is manually configured to use
c3f9da
    static ipv6 address, there's no need to wait for router advertisements.
c3f9da
    This patch will set automatically IPV6_AUTOCONF and IPV6_FORCE_ACCEPT_RA
c3f9da
    both to "no" in this case.
c3f9da
c3f9da
    This patch fixes the specific behavior only for RHEL flavor and
c3f9da
    sysconfig renderer. It also introduces new unit tests for the specific
c3f9da
    case as well as adjusts some existent tests to be compatible with the
c3f9da
    new options. This patch also addresses this problem by assigning the
c3f9da
    appropriate subnet type for each case on the openstack handler.
c3f9da
c3f9da
    rhbz: #1889635
c3f9da
    rhbz: #1889635
c3f9da
c3f9da
    Signed-off-by: Eduardo Otubo otubo@redhat.com
c3f9da
c3f9da
Conflicts:
c3f9da
* The context of the patches are slightly different from upstream since
c3f9da
the there is more code added around the changes. But nothing interfering
c3f9da
on the patches.
c3f9da
* One minor conflict, removed the "flavor == 'rhel'" check because the
c3f9da
commit that introduced this change is after the 19.4 release. No harm
c3f9da
done since this commit is intended to be shipped to RHEL only anyways.
c3f9da
c3f9da
Signed-off-by: Eduardo Otubo <otubo@redhat.com>
c3f9da
---
c3f9da
 cloudinit/net/network_state.py                 |   3 +-
c3f9da
 cloudinit/net/sysconfig.py                     |   4 +
c3f9da
 cloudinit/sources/helpers/openstack.py         |   8 +-
c3f9da
 tests/unittests/test_distros/test_netconfig.py |   2 +
c3f9da
 tests/unittests/test_net.py                    | 100 +++++++++++++++++++++++++
c3f9da
 5 files changed, 115 insertions(+), 2 deletions(-)
c3f9da
c3f9da
diff --git a/cloudinit/net/network_state.py b/cloudinit/net/network_state.py
c3f9da
index f3e8e25..2525fc9 100644
c3f9da
--- a/cloudinit/net/network_state.py
c3f9da
+++ b/cloudinit/net/network_state.py
c3f9da
@@ -822,7 +822,8 @@ def _normalize_subnet(subnet):
c3f9da
 
c3f9da
     if subnet.get('type') in ('static', 'static6'):
c3f9da
         normal_subnet.update(
c3f9da
-            _normalize_net_keys(normal_subnet, address_keys=('address',)))
c3f9da
+            _normalize_net_keys(normal_subnet, address_keys=(
c3f9da
+                'address', 'ip_address',)))
c3f9da
     normal_subnet['routes'] = [_normalize_route(r)
c3f9da
                                for r in subnet.get('routes', [])]
c3f9da
 
c3f9da
diff --git a/cloudinit/net/sysconfig.py b/cloudinit/net/sysconfig.py
c3f9da
index 4b4ed09..4210544 100644
c3f9da
--- a/cloudinit/net/sysconfig.py
c3f9da
+++ b/cloudinit/net/sysconfig.py
c3f9da
@@ -401,6 +401,10 @@ class Renderer(renderer.Renderer):
c3f9da
                             ' because ipv4 subnet-level mtu:%s provided.',
c3f9da
                             iface_cfg.name, iface_cfg[mtu_key], subnet['mtu'])
c3f9da
                     iface_cfg[mtu_key] = subnet['mtu']
c3f9da
+
c3f9da
+                if subnet_is_ipv6(subnet):
c3f9da
+                    iface_cfg['IPV6_FORCE_ACCEPT_RA'] = False
c3f9da
+                    iface_cfg['IPV6_AUTOCONF'] = False
c3f9da
             elif subnet_type == 'manual':
c3f9da
                 # If the subnet has an MTU setting, then ONBOOT=True
c3f9da
                 # to apply the setting
c3f9da
diff --git a/cloudinit/sources/helpers/openstack.py b/cloudinit/sources/helpers/openstack.py
c3f9da
index 0778f45..6ef4f90 100644
c3f9da
--- a/cloudinit/sources/helpers/openstack.py
c3f9da
+++ b/cloudinit/sources/helpers/openstack.py
c3f9da
@@ -592,11 +592,17 @@ def convert_net_json(network_json=None, known_macs=None):
c3f9da
             elif network['type'] in ['ipv6_slaac', 'ipv6_dhcpv6-stateless',
c3f9da
                                      'ipv6_dhcpv6-stateful']:
c3f9da
                 subnet.update({'type': network['type']})
c3f9da
-            elif network['type'] in ['ipv4', 'ipv6']:
c3f9da
+            elif network['type'] in ['ipv4', 'static']:
c3f9da
                 subnet.update({
c3f9da
                     'type': 'static',
c3f9da
                     'address': network.get('ip_address'),
c3f9da
                 })
c3f9da
+            elif network['type'] in ['ipv6', 'static6']:
c3f9da
+                cfg.update({'accept-ra': False})
c3f9da
+                subnet.update({
c3f9da
+                    'type': 'static6',
c3f9da
+                    'address': network.get('ip_address'),
c3f9da
+                })
c3f9da
 
c3f9da
             # Enable accept_ra for stateful and legacy ipv6_dhcp types
c3f9da
             if network['type'] in ['ipv6_dhcpv6-stateful', 'ipv6_dhcp']:
c3f9da
diff --git a/tests/unittests/test_distros/test_netconfig.py b/tests/unittests/test_distros/test_netconfig.py
c3f9da
index 4ea4203..b85a333 100644
c3f9da
--- a/tests/unittests/test_distros/test_netconfig.py
c3f9da
+++ b/tests/unittests/test_distros/test_netconfig.py
c3f9da
@@ -673,7 +673,9 @@ class TestNetCfgDistroOpensuse(TestNetCfgDistroBase):
c3f9da
                 IPADDR6=2607:f0d0:1002:0011::2/64
c3f9da
                 IPV6ADDR=2607:f0d0:1002:0011::2/64
c3f9da
                 IPV6INIT=yes
c3f9da
+                IPV6_AUTOCONF=no
c3f9da
                 IPV6_DEFAULTGW=2607:f0d0:1002:0011::1
c3f9da
+                IPV6_FORCE_ACCEPT_RA=no
c3f9da
                 NM_CONTROLLED=no
c3f9da
                 ONBOOT=yes
c3f9da
                 STARTMODE=auto
c3f9da
diff --git a/tests/unittests/test_net.py b/tests/unittests/test_net.py
c3f9da
index 2eedb12..b2b7c4b 100644
c3f9da
--- a/tests/unittests/test_net.py
c3f9da
+++ b/tests/unittests/test_net.py
c3f9da
@@ -768,7 +768,9 @@ IPADDR6_2=2001:DB10::10/64
c3f9da
 IPV6ADDR=2001:DB8::10/64
c3f9da
 IPV6ADDR_SECONDARIES="2001:DB9::10/64 2001:DB10::10/64"
c3f9da
 IPV6INIT=yes
c3f9da
+IPV6_AUTOCONF=no
c3f9da
 IPV6_DEFAULTGW=2001:DB8::1
c3f9da
+IPV6_FORCE_ACCEPT_RA=no
c3f9da
 NETMASK=255.255.252.0
c3f9da
 ONBOOT=yes
c3f9da
 STARTMODE=auto
c3f9da
@@ -1016,6 +1018,8 @@ NETWORK_CONFIGS = {
c3f9da
                 IPADDR6=2001:1::1/64
c3f9da
                 IPV6ADDR=2001:1::1/64
c3f9da
                 IPV6INIT=yes
c3f9da
+                IPV6_AUTOCONF=no
c3f9da
+                IPV6_FORCE_ACCEPT_RA=no
c3f9da
                 NETMASK=255.255.255.0
c3f9da
                 ONBOOT=yes
c3f9da
                 STARTMODE=auto
c3f9da
@@ -1201,6 +1205,33 @@ NETWORK_CONFIGS = {
c3f9da
             """),
c3f9da
         },
c3f9da
     },
c3f9da
+    'static6': {
c3f9da
+        'yaml': textwrap.dedent("""\
c3f9da
+        version: 1
c3f9da
+        config:
c3f9da
+          - type: 'physical'
c3f9da
+            name: 'iface0'
c3f9da
+            accept-ra: 'no'
c3f9da
+            subnets:
c3f9da
+            - type: 'static6'
c3f9da
+              address: 2001:1::1/64
c3f9da
+    """).rstrip(' '),
c3f9da
+        'expected_sysconfig_rhel': {
c3f9da
+            'ifcfg-iface0': textwrap.dedent("""\
c3f9da
+            BOOTPROTO=none
c3f9da
+            DEVICE=iface0
c3f9da
+            IPV6ADDR=2001:1::1/64
c3f9da
+            IPV6INIT=yes
c3f9da
+            IPV6_AUTOCONF=no
c3f9da
+            IPV6_FORCE_ACCEPT_RA=no
c3f9da
+            DEVICE=iface0
c3f9da
+            NM_CONTROLLED=no
c3f9da
+            ONBOOT=yes
c3f9da
+            TYPE=Ethernet
c3f9da
+            USERCTL=no
c3f9da
+            """),
c3f9da
+        },
c3f9da
+    },
c3f9da
     'dhcpv6_stateless': {
c3f9da
         'expected_eni': textwrap.dedent("""\
c3f9da
         auto lo
c3f9da
@@ -1507,6 +1538,8 @@ pre-down route del -net 10.0.0.0/8 gw 11.0.0.1 metric 3 || true
c3f9da
                 IPADDR6=2001:1::1/64
c3f9da
                 IPV6ADDR=2001:1::1/64
c3f9da
                 IPV6INIT=yes
c3f9da
+                IPV6_AUTOCONF=no
c3f9da
+                IPV6_FORCE_ACCEPT_RA=no
c3f9da
                 IPV6_DEFAULTGW=2001:4800:78ff:1b::1
c3f9da
                 MACADDR=bb:bb:bb:bb:bb:aa
c3f9da
                 NETMASK=255.255.255.0
c3f9da
@@ -2067,6 +2100,8 @@ iface bond0 inet6 static
c3f9da
         IPADDR6=2001:1::1/92
c3f9da
         IPV6ADDR=2001:1::1/92
c3f9da
         IPV6INIT=yes
c3f9da
+        IPV6_AUTOCONF=no
c3f9da
+        IPV6_FORCE_ACCEPT_RA=no
c3f9da
         MTU=9000
c3f9da
         NETMASK=255.255.255.0
c3f9da
         NETMASK1=255.255.255.0
c3f9da
@@ -2154,6 +2189,8 @@ iface bond0 inet6 static
c3f9da
                 IPADDR6=2001:1::bbbb/96
c3f9da
                 IPV6ADDR=2001:1::bbbb/96
c3f9da
                 IPV6INIT=yes
c3f9da
+                IPV6_AUTOCONF=no
c3f9da
+                IPV6_FORCE_ACCEPT_RA=no
c3f9da
                 IPV6_DEFAULTGW=2001:1::1
c3f9da
                 MTU=2222
c3f9da
                 NETMASK=255.255.255.0
c3f9da
@@ -2213,6 +2250,9 @@ iface bond0 inet6 static
c3f9da
                 IPADDR6=2001:1::100/96
c3f9da
                 IPV6ADDR=2001:1::100/96
c3f9da
                 IPV6INIT=yes
c3f9da
+                IPV6_AUTOCONF=no
c3f9da
+                IPV6_FORCE_ACCEPT_RA=no
c3f9da
+                NM_CONTROLLED=no
c3f9da
                 ONBOOT=yes
c3f9da
                 STARTMODE=auto
c3f9da
                 TYPE=Ethernet
c3f9da
@@ -2226,6 +2266,9 @@ iface bond0 inet6 static
c3f9da
                 IPADDR6=2001:1::101/96
c3f9da
                 IPV6ADDR=2001:1::101/96
c3f9da
                 IPV6INIT=yes
c3f9da
+                IPV6_AUTOCONF=no
c3f9da
+                IPV6_FORCE_ACCEPT_RA=no
c3f9da
+                NM_CONTROLLED=no
c3f9da
                 ONBOOT=yes
c3f9da
                 STARTMODE=auto
c3f9da
                 TYPE=Ethernet
c3f9da
@@ -3015,6 +3058,61 @@ USERCTL=no
c3f9da
         self._compare_files_to_expected(entry[self.expected_name], found)
c3f9da
         self._assert_headers(found)
c3f9da
 
c3f9da
+    def test_stattic6_from_json(self):
c3f9da
+        net_json = {
c3f9da
+            "services": [{"type": "dns", "address": "172.19.0.12"}],
c3f9da
+            "networks": [{
c3f9da
+                "network_id": "dacd568d-5be6-4786-91fe-750c374b78b4",
c3f9da
+                "type": "ipv4", "netmask": "255.255.252.0",
c3f9da
+                "link": "tap1a81968a-79",
c3f9da
+                "routes": [{
c3f9da
+                    "netmask": "0.0.0.0",
c3f9da
+                    "network": "0.0.0.0",
c3f9da
+                    "gateway": "172.19.3.254",
c3f9da
+                }, {
c3f9da
+                    "netmask": "0.0.0.0",  # A second default gateway
c3f9da
+                    "network": "0.0.0.0",
c3f9da
+                    "gateway": "172.20.3.254",
c3f9da
+                }],
c3f9da
+                "ip_address": "172.19.1.34", "id": "network0"
c3f9da
+            }, {
c3f9da
+                "network_id": "mgmt",
c3f9da
+                "netmask": "ffff:ffff:ffff:ffff::",
c3f9da
+                "link": "interface1",
c3f9da
+                "mode": "link-local",
c3f9da
+                "routes": [],
c3f9da
+                "ip_address": "fe80::c096:67ff:fe5c:6e84",
c3f9da
+                "type": "static6",
c3f9da
+                "id": "network1",
c3f9da
+                "services": [],
c3f9da
+                "accept-ra": "false"
c3f9da
+            }],
c3f9da
+            "links": [
c3f9da
+                {
c3f9da
+                    "ethernet_mac_address": "fa:16:3e:ed:9a:59",
c3f9da
+                    "mtu": None, "type": "bridge", "id":
c3f9da
+                    "tap1a81968a-79",
c3f9da
+                    "vif_id": "1a81968a-797a-400f-8a80-567f997eb93f"
c3f9da
+                },
c3f9da
+            ],
c3f9da
+        }
c3f9da
+        macs = {'fa:16:3e:ed:9a:59': 'eth0'}
c3f9da
+        render_dir = self.tmp_dir()
c3f9da
+        network_cfg = openstack.convert_net_json(net_json, known_macs=macs)
c3f9da
+        ns = network_state.parse_net_config_data(network_cfg,
c3f9da
+                                                 skip_broken=False)
c3f9da
+        renderer = self._get_renderer()
c3f9da
+        with self.assertRaises(ValueError):
c3f9da
+            renderer.render_network_state(ns, target=render_dir)
c3f9da
+        self.assertEqual([], os.listdir(render_dir))
c3f9da
+
c3f9da
+    def test_static6_from_yaml(self):
c3f9da
+        entry = NETWORK_CONFIGS['static6']
c3f9da
+        found = self._render_and_read(network_config=yaml.load(
c3f9da
+            entry['yaml']))
c3f9da
+        self._compare_files_to_expected(entry[self.expected_name], found)
c3f9da
+        self._assert_headers(found)
c3f9da
+
c3f9da
     def test_dhcpv6_reject_ra_config_v2(self):
c3f9da
         entry = NETWORK_CONFIGS['dhcpv6_reject_ra']
c3f9da
         found = self._render_and_read(network_config=yaml.load(
c3f9da
@@ -3133,6 +3231,8 @@ USERCTL=no
c3f9da
                    IPADDR6=2001:db8::100/32
c3f9da
                    IPV6ADDR=2001:db8::100/32
c3f9da
                    IPV6INIT=yes
c3f9da
+                   IPV6_AUTOCONF=no
c3f9da
+                   IPV6_FORCE_ACCEPT_RA=no
c3f9da
                    IPV6_DEFAULTGW=2001:db8::1
c3f9da
                    NETMASK=255.255.255.0
c3f9da
                    NM_CONTROLLED=no
c3f9da
-- 
c3f9da
1.8.3.1
c3f9da