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