sailesh1993 / rpms / cloud-init

Forked from rpms/cloud-init a year ago
Clone
44fd36
From e0eca40388080dabf6598c0d9653ea50ae10c984 Mon Sep 17 00:00:00 2001
44fd36
From: Emanuele Giuseppe Esposito <eesposit@redhat.com>
44fd36
Date: Tue, 7 Dec 2021 10:04:43 +0100
44fd36
Subject: [PATCH] cloudinit/net: handle two different routes for the same ip
44fd36
 (#1124)
44fd36
44fd36
RH-Author: Emanuele Giuseppe Esposito <eesposit@redhat.com>
44fd36
RH-MergeRequest: 15: cloudinit/net: handle two different routes for the same ip (#1124)
44fd36
RH-Commit: [1/1] b623a76ccd642e22e8d9c4aebc26f0b0cec8118b (eesposit/cloud-init-centos-)
44fd36
RH-Bugzilla: 2028031
44fd36
RH-Acked-by: Mohamed Gamal Morsy <mmorsy@redhat.com>
44fd36
RH-Acked-by: Eduardo Otubo <otubo@redhat.com>
44fd36
44fd36
commit 0e25076b34fa995161b83996e866c0974cee431f
44fd36
Author: Emanuele Giuseppe Esposito <eesposit@redhat.com>
44fd36
Date:   Mon Dec 6 18:34:26 2021 +0100
44fd36
44fd36
    cloudinit/net: handle two different routes for the same ip (#1124)
44fd36
44fd36
    If we set a dhcp server side like this:
44fd36
    $ cat /var/tmp/cloud-init/cloud-init-dhcp-f0rie5tm/dhcp.leases
44fd36
    lease {
44fd36
    ...
44fd36
    option classless-static-routes 31.169.254.169.254 0.0.0.0,31.169.254.169.254
44fd36
        10.112.143.127,22.10.112.140 0.0.0.0,0 10.112.140.1;
44fd36
    ...
44fd36
    }
44fd36
    cloud-init fails to configure the routes via 'ip route add' because to there are
44fd36
    two different routes for 169.254.169.254:
44fd36
44fd36
    $ ip -4 route add 192.168.1.1/32 via 0.0.0.0 dev eth0
44fd36
    $ ip -4 route add 192.168.1.1/32 via 10.112.140.248 dev eth0
44fd36
44fd36
    But NetworkManager can handle such scenario successfully as it uses "ip route append".
44fd36
    So change cloud-init to also use "ip route append" to fix the issue:
44fd36
44fd36
    $ ip -4 route append 192.168.1.1/32 via 0.0.0.0 dev eth0
44fd36
    $ ip -4 route append 192.168.1.1/32 via 10.112.140.248 dev eth0
44fd36
44fd36
    Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
44fd36
44fd36
    RHBZ: #2003231
44fd36
44fd36
Conflicts:
44fd36
    cloudinit/net/tests/test_init.py: a mock call in
44fd36
    test_ephemeral_ipv4_network_with_rfc3442_static_routes is not
44fd36
    present downstream.
44fd36
44fd36
Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
44fd36
---
44fd36
 cloudinit/net/__init__.py        | 2 +-
44fd36
 cloudinit/net/tests/test_init.py | 4 ++--
44fd36
 2 files changed, 3 insertions(+), 3 deletions(-)
44fd36
44fd36
diff --git a/cloudinit/net/__init__.py b/cloudinit/net/__init__.py
44fd36
index de65e7af..4bdc1bda 100644
44fd36
--- a/cloudinit/net/__init__.py
44fd36
+++ b/cloudinit/net/__init__.py
44fd36
@@ -1076,7 +1076,7 @@ class EphemeralIPv4Network(object):
44fd36
             if gateway != "0.0.0.0/0":
44fd36
                 via_arg = ['via', gateway]
44fd36
             subp.subp(
44fd36
-                ['ip', '-4', 'route', 'add', net_address] + via_arg +
44fd36
+                ['ip', '-4', 'route', 'append', net_address] + via_arg +
44fd36
                 ['dev', self.interface], capture=True)
44fd36
             self.cleanup_cmds.insert(
44fd36
                 0, ['ip', '-4', 'route', 'del', net_address] + via_arg +
44fd36
diff --git a/cloudinit/net/tests/test_init.py b/cloudinit/net/tests/test_init.py
44fd36
index 0535387a..6754df8d 100644
44fd36
--- a/cloudinit/net/tests/test_init.py
44fd36
+++ b/cloudinit/net/tests/test_init.py
44fd36
@@ -715,10 +715,10 @@ class TestEphemeralIPV4Network(CiTestCase):
44fd36
                 ['ip', '-family', 'inet', 'link', 'set', 'dev', 'eth0', 'up'],
44fd36
                 capture=True),
44fd36
             mock.call(
44fd36
-                ['ip', '-4', 'route', 'add', '169.254.169.254/32',
44fd36
+                ['ip', '-4', 'route', 'append', '169.254.169.254/32',
44fd36
                  'via', '192.168.2.1', 'dev', 'eth0'], capture=True),
44fd36
             mock.call(
44fd36
-                ['ip', '-4', 'route', 'add', '0.0.0.0/0',
44fd36
+                ['ip', '-4', 'route', 'append', '0.0.0.0/0',
44fd36
                  'via', '192.168.2.1', 'dev', 'eth0'], capture=True)]
44fd36
         expected_teardown_calls = [
44fd36
             mock.call(
44fd36
-- 
44fd36
2.27.0
44fd36