ef3f20
From 9a7480d13ab3be53f0152a19c68d596490d5d290 Mon Sep 17 00:00:00 2001
ef3f20
From: Andreas Karis <akaris@redhat.com>
ef3f20
Date: Tue, 6 Jun 2017 12:55:50 -0400
ef3f20
Subject: [PATCH] RHEL/CentOS: Fix default routes for IPv4/IPv6 configuration.
ef3f20
ef3f20
Since f38fa413176, default routes get added to both ifcfg-* and route-*
ef3f20
and route6-* files. Default routes should only go to ifcfg-* files,
ef3f20
otherwise the information is redundant.
ef3f20
ef3f20
LP: #1696176
ef3f20
Resolves: rhbz#1438082
ef3f20
ef3f20
Signed-off-by: Ryan McCabe <rmccabe@redhat.com>
ef3f20
(cherry picked from commit f99745cf916e707eaa1ded6f12e8b69837b7242d)
ef3f20
---
ef3f20
 cloudinit/net/sysconfig.py  | 12 +++++++-----
ef3f20
 tests/unittests/test_net.py |  8 --------
ef3f20
 2 files changed, 7 insertions(+), 13 deletions(-)
ef3f20
ef3f20
diff --git a/cloudinit/net/sysconfig.py b/cloudinit/net/sysconfig.py
ef3f20
index 6a0dd43..c67e6aa 100644
ef3f20
--- a/cloudinit/net/sysconfig.py
ef3f20
+++ b/cloudinit/net/sysconfig.py
ef3f20
@@ -381,11 +381,13 @@ class Renderer(renderer.Renderer):
ef3f20
                     nm_key = 'NETMASK%s' % route_cfg.last_idx
ef3f20
                     addr_key = 'ADDRESS%s' % route_cfg.last_idx
ef3f20
                     route_cfg.last_idx += 1
ef3f20
-                for (old_key, new_key) in [('gateway', gw_key),
ef3f20
-                                           ('netmask', nm_key),
ef3f20
-                                           ('network', addr_key)]:
ef3f20
-                    if old_key in route:
ef3f20
-                        route_cfg[new_key] = route[old_key]
ef3f20
+                    # add default routes only to ifcfg files, not
ef3f20
+                    # to route-* or route6-*
ef3f20
+                    for (old_key, new_key) in [('gateway', gw_key),
ef3f20
+                                               ('netmask', nm_key),
ef3f20
+                                               ('network', addr_key)]:
ef3f20
+                        if old_key in route:
ef3f20
+                            route_cfg[new_key] = route[old_key]
ef3f20
 
ef3f20
     @classmethod
ef3f20
     def _render_bonding_opts(cls, iface_cfg, iface):
ef3f20
diff --git a/tests/unittests/test_net.py b/tests/unittests/test_net.py
ef3f20
index 172d604..45ab732 100755
ef3f20
--- a/tests/unittests/test_net.py
ef3f20
+++ b/tests/unittests/test_net.py
ef3f20
@@ -148,14 +148,6 @@ ONBOOT=yes
ef3f20
 TYPE=Ethernet
ef3f20
 USERCTL=no
ef3f20
 """.lstrip()),
ef3f20
-            ('etc/sysconfig/network-scripts/route-eth0',
ef3f20
-             """
ef3f20
-# Created by cloud-init on instance boot automatically, do not edit.
ef3f20
-#
ef3f20
-ADDRESS0=0.0.0.0
ef3f20
-GATEWAY0=172.19.3.254
ef3f20
-NETMASK0=0.0.0.0
ef3f20
-""".lstrip()),
ef3f20
             ('etc/resolv.conf',
ef3f20
              """
ef3f20
 ; Created by cloud-init on instance boot automatically, do not edit.