1abfba
From c85c5aa1c09bc4b78a015a2eb338a7fcb48ad4a3 Mon Sep 17 00:00:00 2001
1abfba
From: Emanuele Giuseppe Esposito <eesposit@redhat.com>
1abfba
Date: Mon, 13 Dec 2021 12:08:18 +0100
1abfba
Subject: [PATCH] cloudinit/net: handle two different routes for the same ip
1abfba
 (#1124)
1abfba
1abfba
RH-Author: Emanuele Giuseppe Esposito <eesposit@redhat.com>
1abfba
RH-MergeRequest: 40: cloudinit/net: handle two different routes for the same ip (#1124)
1abfba
RH-Commit: [1/1] 5f1b03b15e7828a2bac80850ca70a72f981cdaa7
1abfba
RH-Bugzilla: 2003231
1abfba
RH-Acked-by: Eduardo Otubo <otubo@redhat.com>
1abfba
RH-Acked-by: Vitaly Kuznetsov <vkuznets@redhat.com>
1abfba
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
1abfba
RH-Acked-by: Mohamed Gamal Morsy <mmorsy@redhat.com>
1abfba
1abfba
commit 0e25076b34fa995161b83996e866c0974cee431f
1abfba
Author: Emanuele Giuseppe Esposito <eesposit@redhat.com>
1abfba
Date:   Mon Dec 6 18:34:26 2021 +0100
1abfba
1abfba
    cloudinit/net: handle two different routes for the same ip (#1124)
1abfba
1abfba
    If we set a dhcp server side like this:
1abfba
    $ cat /var/tmp/cloud-init/cloud-init-dhcp-f0rie5tm/dhcp.leases
1abfba
    lease {
1abfba
    ...
1abfba
    option classless-static-routes 31.169.254.169.254 0.0.0.0,31.169.254.169.254
1abfba
        10.112.143.127,22.10.112.140 0.0.0.0,0 10.112.140.1;
1abfba
    ...
1abfba
    }
1abfba
    cloud-init fails to configure the routes via 'ip route add' because to there are
1abfba
    two different routes for 169.254.169.254:
1abfba
1abfba
    $ ip -4 route add 192.168.1.1/32 via 0.0.0.0 dev eth0
1abfba
    $ ip -4 route add 192.168.1.1/32 via 10.112.140.248 dev eth0
1abfba
1abfba
    But NetworkManager can handle such scenario successfully as it uses "ip route append".
1abfba
    So change cloud-init to also use "ip route append" to fix the issue:
1abfba
1abfba
    $ ip -4 route append 192.168.1.1/32 via 0.0.0.0 dev eth0
1abfba
    $ ip -4 route append 192.168.1.1/32 via 10.112.140.248 dev eth0
1abfba
1abfba
    Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
1abfba
1abfba
    RHBZ: #2003231
1abfba
1abfba
Conflicts:
1abfba
    cloudinit/net/tests/test_init.py: a mock call in
1abfba
    test_ephemeral_ipv4_network_with_rfc3442_static_routes is not
1abfba
    present downstream.
1abfba
1abfba
    cloudinit/net/__init__.py: subp() method is implemented in util,
1abfba
    while in newer version it is implemented in subp file.
1abfba
1abfba
Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
1abfba
---
1abfba
 cloudinit/net/__init__.py        | 2 +-
1abfba
 cloudinit/net/tests/test_init.py | 4 ++--
1abfba
 2 files changed, 3 insertions(+), 3 deletions(-)
1abfba
1abfba
diff --git a/cloudinit/net/__init__.py b/cloudinit/net/__init__.py
1abfba
index bd806378..3d3f7108 100644
1abfba
--- a/cloudinit/net/__init__.py
1abfba
+++ b/cloudinit/net/__init__.py
1abfba
@@ -970,7 +970,7 @@ class EphemeralIPv4Network(object):
1abfba
             if gateway != "0.0.0.0/0":
1abfba
                 via_arg = ['via', gateway]
1abfba
             util.subp(
1abfba
-                ['ip', '-4', 'route', 'add', net_address] + via_arg +
1abfba
+                ['ip', '-4', 'route', 'append', net_address] + via_arg +
1abfba
                 ['dev', self.interface], capture=True)
1abfba
             self.cleanup_cmds.insert(
1abfba
                 0, ['ip', '-4', 'route', 'del', net_address] + via_arg +
1abfba
diff --git a/cloudinit/net/tests/test_init.py b/cloudinit/net/tests/test_init.py
1abfba
index 6db93e26..a0db549b 100644
1abfba
--- a/cloudinit/net/tests/test_init.py
1abfba
+++ b/cloudinit/net/tests/test_init.py
1abfba
@@ -711,10 +711,10 @@ class TestEphemeralIPV4Network(CiTestCase):
1abfba
                 ['ip', '-family', 'inet', 'link', 'set', 'dev', 'eth0', 'up'],
1abfba
                 capture=True),
1abfba
             mock.call(
1abfba
-                ['ip', '-4', 'route', 'add', '169.254.169.254/32',
1abfba
+                ['ip', '-4', 'route', 'append', '169.254.169.254/32',
1abfba
                  'via', '192.168.2.1', 'dev', 'eth0'], capture=True),
1abfba
             mock.call(
1abfba
-                ['ip', '-4', 'route', 'add', '0.0.0.0/0',
1abfba
+                ['ip', '-4', 'route', 'append', '0.0.0.0/0',
1abfba
                  'via', '192.168.2.1', 'dev', 'eth0'], capture=True)]
1abfba
         expected_teardown_calls = [
1abfba
             mock.call(
1abfba
-- 
1abfba
2.27.0
1abfba