sailesh1993 / rpms / cloud-init

Forked from rpms/cloud-init 10 months ago
Clone
c3f9da
From 3ee8f2f5dde1bb27e682c5985bffe6fb9f9e5e0b Mon Sep 17 00:00:00 2001
c3f9da
From: Eduardo Otubo <otubo@redhat.com>
c3f9da
Date: Thu, 5 Nov 2020 12:42:26 +0100
c3f9da
Subject: [PATCH 5/5] net: fix rendering of 'static6' in network config (#77)
c3f9da
MIME-Version: 1.0
c3f9da
Content-Type: text/plain; charset=UTF-8
c3f9da
Content-Transfer-Encoding: 8bit
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: [2/2] 30eb756aceb37761d50c70eb4f684662a11afa3f (eterrell/cloud-init)
c3f9da
RH-Bugzilla: 1894015
c3f9da
c3f9da
commit dacdd30080bd8183d1f1c1dc9dbcbc8448301529
c3f9da
Author: Ryan Harper <ryan.harper@canonical.com>
c3f9da
Date:   Wed Jan 8 11:30:17 2020 -0600
c3f9da
c3f9da
    net: fix rendering of 'static6' in network config (#77)
c3f9da
c3f9da
    * net: fix rendering of 'static6' in network config
c3f9da
c3f9da
    A V1 static6 network typo was misrendered in eni, it's not valid.
c3f9da
    It was ignored in sysconfig and netplan.  This branch fixes eni,
c3f9da
    updates sysconfig, netplan to render it correctly and adds unittests
c3f9da
    for all cases.
c3f9da
c3f9da
    Reported-by: Raphaƫl Enrici
c3f9da
c3f9da
    LP: #1850988
c3f9da
c3f9da
    * net: add comment about static6 type in subnet_is_ipv6
c3f9da
c3f9da
    Co-authored-by: Chad Smith <blackboxsw@gmail.com>
c3f9da
    Co-authored-by: Daniel Watkins <daniel@daniel-watkins.co.uk>
c3f9da
c3f9da
Signed-off-by: Eduardo Otubo <otubo@redhat.com>
c3f9da
---
c3f9da
 cloudinit/net/eni.py                           |  4 +-
c3f9da
 cloudinit/net/netplan.py                       |  2 +-
c3f9da
 cloudinit/net/network_state.py                 |  2 +-
c3f9da
 cloudinit/net/sysconfig.py                     |  4 +-
c3f9da
 tests/unittests/test_distros/test_netconfig.py | 55 +++++++++++++++++++++++++-
c3f9da
 5 files changed, 61 insertions(+), 6 deletions(-)
c3f9da
c3f9da
diff --git a/cloudinit/net/eni.py b/cloudinit/net/eni.py
c3f9da
index 7077106..2f71456 100644
c3f9da
--- a/cloudinit/net/eni.py
c3f9da
+++ b/cloudinit/net/eni.py
c3f9da
@@ -429,7 +429,9 @@ class Renderer(renderer.Renderer):
c3f9da
                     iface['mode'] = 'auto'
c3f9da
                     # Use stateless DHCPv6 (0=off, 1=on)
c3f9da
                     iface['dhcp'] = '0'
c3f9da
-                elif subnet_is_ipv6(subnet) and subnet['type'] == 'static':
c3f9da
+                elif subnet_is_ipv6(subnet):
c3f9da
+                    # mode might be static6, eni uses 'static'
c3f9da
+                    iface['mode'] = 'static'
c3f9da
                     if accept_ra is not None:
c3f9da
                         # Accept router advertisements (0=off, 1=on)
c3f9da
                         iface['accept_ra'] = '1' if accept_ra else '0'
c3f9da
diff --git a/cloudinit/net/netplan.py b/cloudinit/net/netplan.py
c3f9da
index 14d3999..8985527 100644
c3f9da
--- a/cloudinit/net/netplan.py
c3f9da
+++ b/cloudinit/net/netplan.py
c3f9da
@@ -98,7 +98,7 @@ def _extract_addresses(config, entry, ifname, features=None):
c3f9da
             entry.update({sn_type: True})
c3f9da
         elif sn_type in IPV6_DYNAMIC_TYPES:
c3f9da
             entry.update({'dhcp6': True})
c3f9da
-        elif sn_type in ['static']:
c3f9da
+        elif sn_type in ['static', 'static6']:
c3f9da
             addr = "%s" % subnet.get('address')
c3f9da
             if 'prefix' in subnet:
c3f9da
                 addr += "/%d" % subnet.get('prefix')
c3f9da
diff --git a/cloudinit/net/network_state.py b/cloudinit/net/network_state.py
c3f9da
index 2525fc9..48e5b6e 100644
c3f9da
--- a/cloudinit/net/network_state.py
c3f9da
+++ b/cloudinit/net/network_state.py
c3f9da
@@ -942,7 +942,7 @@ def subnet_is_ipv6(subnet):
c3f9da
     # 'static6', 'dhcp6', 'ipv6_dhcpv6-stateful', 'ipv6_dhcpv6-stateless' or
c3f9da
     # 'ipv6_slaac'
c3f9da
     if subnet['type'].endswith('6') or subnet['type'] in IPV6_DYNAMIC_TYPES:
c3f9da
-        # This is a request for DHCPv6.
c3f9da
+        # This is a request either static6 type or DHCPv6.
c3f9da
         return True
c3f9da
     elif subnet['type'] == 'static' and is_ipv6_addr(subnet.get('address')):
c3f9da
         return True
c3f9da
diff --git a/cloudinit/net/sysconfig.py b/cloudinit/net/sysconfig.py
c3f9da
index 4210544..1989d01 100644
c3f9da
--- a/cloudinit/net/sysconfig.py
c3f9da
+++ b/cloudinit/net/sysconfig.py
c3f9da
@@ -378,7 +378,7 @@ class Renderer(renderer.Renderer):
c3f9da
                 iface_cfg['IPV6_AUTOCONF'] = True
c3f9da
             elif subnet_type in ['dhcp4', 'dhcp']:
c3f9da
                 iface_cfg['BOOTPROTO'] = 'dhcp'
c3f9da
-            elif subnet_type == 'static':
c3f9da
+            elif subnet_type in ['static', 'static6']:
c3f9da
                 # grep BOOTPROTO sysconfig.txt -A2 | head -3
c3f9da
                 # BOOTPROTO=none|bootp|dhcp
c3f9da
                 # 'bootp' or 'dhcp' cause a DHCP client
c3f9da
@@ -434,7 +434,7 @@ class Renderer(renderer.Renderer):
c3f9da
                 continue
c3f9da
             elif subnet_type in IPV6_DYNAMIC_TYPES:
c3f9da
                 continue
c3f9da
-            elif subnet_type == 'static':
c3f9da
+            elif subnet_type in ['static', 'static6']:
c3f9da
                 if subnet_is_ipv6(subnet):
c3f9da
                     ipv6_index = ipv6_index + 1
c3f9da
                     ipv6_cidr = "%s/%s" % (subnet['address'], subnet['prefix'])
c3f9da
diff --git a/tests/unittests/test_distros/test_netconfig.py b/tests/unittests/test_distros/test_netconfig.py
c3f9da
index b85a333..e277bca 100644
c3f9da
--- a/tests/unittests/test_distros/test_netconfig.py
c3f9da
+++ b/tests/unittests/test_distros/test_netconfig.py
c3f9da
@@ -109,13 +109,31 @@ auto eth1
c3f9da
 iface eth1 inet dhcp
c3f9da
 """
c3f9da
 
c3f9da
+V1_NET_CFG_IPV6_OUTPUT = """\
c3f9da
+# This file is generated from information provided by the datasource.  Changes
c3f9da
+# to it will not persist across an instance reboot.  To disable cloud-init's
c3f9da
+# network configuration capabilities, write a file
c3f9da
+# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
c3f9da
+# network: {config: disabled}
c3f9da
+auto lo
c3f9da
+iface lo inet loopback
c3f9da
+
c3f9da
+auto eth0
c3f9da
+iface eth0 inet6 static
c3f9da
+    address 2607:f0d0:1002:0011::2/64
c3f9da
+    gateway 2607:f0d0:1002:0011::1
c3f9da
+
c3f9da
+auto eth1
c3f9da
+iface eth1 inet dhcp
c3f9da
+"""
c3f9da
+
c3f9da
 V1_NET_CFG_IPV6 = {'config': [{'name': 'eth0',
c3f9da
                                'subnets': [{'address':
c3f9da
                                             '2607:f0d0:1002:0011::2',
c3f9da
                                             'gateway':
c3f9da
                                             '2607:f0d0:1002:0011::1',
c3f9da
                                             'netmask': '64',
c3f9da
-                                            'type': 'static'}],
c3f9da
+                                            'type': 'static6'}],
c3f9da
                                'type': 'physical'},
c3f9da
                               {'name': 'eth1',
c3f9da
                                'subnets': [{'control': 'auto',
c3f9da
@@ -141,6 +159,23 @@ network:
c3f9da
             dhcp4: true
c3f9da
 """
c3f9da
 
c3f9da
+V1_TO_V2_NET_CFG_IPV6_OUTPUT = """\
c3f9da
+# This file is generated from information provided by the datasource.  Changes
c3f9da
+# to it will not persist across an instance reboot.  To disable cloud-init's
c3f9da
+# network configuration capabilities, write a file
c3f9da
+# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
c3f9da
+# network: {config: disabled}
c3f9da
+network:
c3f9da
+    version: 2
c3f9da
+    ethernets:
c3f9da
+        eth0:
c3f9da
+            addresses:
c3f9da
+            - 2607:f0d0:1002:0011::2/64
c3f9da
+            gateway6: 2607:f0d0:1002:0011::1
c3f9da
+        eth1:
c3f9da
+            dhcp4: true
c3f9da
+"""
c3f9da
+
c3f9da
 V2_NET_CFG = {
c3f9da
     'ethernets': {
c3f9da
         'eth7': {
c3f9da
@@ -376,6 +411,14 @@ class TestNetCfgDistroUbuntuEni(TestNetCfgDistroBase):
c3f9da
                                    V1_NET_CFG,
c3f9da
                                    expected_cfgs=expected_cfgs.copy())
c3f9da
 
c3f9da
+    def test_apply_network_config_ipv6_ub(self):
c3f9da
+        expected_cfgs = {
c3f9da
+            self.eni_path(): V1_NET_CFG_IPV6_OUTPUT
c3f9da
+        }
c3f9da
+        self._apply_and_verify_eni(self.distro.apply_network_config,
c3f9da
+                                   V1_NET_CFG_IPV6,
c3f9da
+                                   expected_cfgs=expected_cfgs.copy())
c3f9da
+
c3f9da
 
c3f9da
 class TestNetCfgDistroUbuntuNetplan(TestNetCfgDistroBase):
c3f9da
     def setUp(self):
c3f9da
@@ -419,6 +462,16 @@ class TestNetCfgDistroUbuntuNetplan(TestNetCfgDistroBase):
c3f9da
                                        V1_NET_CFG,
c3f9da
                                        expected_cfgs=expected_cfgs.copy())
c3f9da
 
c3f9da
+    def test_apply_network_config_v1_ipv6_to_netplan_ub(self):
c3f9da
+        expected_cfgs = {
c3f9da
+            self.netplan_path(): V1_TO_V2_NET_CFG_IPV6_OUTPUT,
c3f9da
+        }
c3f9da
+
c3f9da
+        # ub_distro.apply_network_config(V1_NET_CFG_IPV6, False)
c3f9da
+        self._apply_and_verify_netplan(self.distro.apply_network_config,
c3f9da
+                                       V1_NET_CFG_IPV6,
c3f9da
+                                       expected_cfgs=expected_cfgs.copy())
c3f9da
+
c3f9da
     def test_apply_network_config_v2_passthrough_ub(self):
c3f9da
         expected_cfgs = {
c3f9da
             self.netplan_path(): V2_TO_V2_NET_CFG_OUTPUT,
c3f9da
-- 
c3f9da
1.8.3.1
c3f9da