sailesh1993 / rpms / cloud-init

Forked from rpms/cloud-init 10 months ago
Clone
fb0fb1
From a0601a472dc5b05106617b35b81d8a0578ade339 Mon Sep 17 00:00:00 2001
fb0fb1
From: =?UTF-8?q?Lukas=20M=C3=A4rdian?= <luk@slyon.de>
fb0fb1
Date: Thu, 29 Oct 2020 14:38:56 +0100
fb0fb1
Subject: [PATCH 1/2] get_interfaces: don't exclude Open vSwitch bridge/bond
fb0fb1
 members (#608)
fb0fb1
MIME-Version: 1.0
fb0fb1
Content-Type: text/plain; charset=UTF-8
fb0fb1
Content-Transfer-Encoding: 8bit
fb0fb1
fb0fb1
RH-Author: Eduardo Otubo (otubo)
fb0fb1
RH-MergeRequest: 6: Patch series to fix "Bug 1957135 - Intermittent failure to start cloud-init due to failure to detect macs"
fb0fb1
RH-Commit: [1/2] 4362f855d2d1a250a7d18490b35e65a1133a00c2 (otubo/cloud-init)
fb0fb1
RH-Bugzilla: 1957135
fb0fb1
RH-Acked-by: Mohammed Gamal <mmorsy@redhat.com>
fb0fb1
RH-Acked-by: Emanuele Giuseppe Esposito <[eesposit@redhat.com](mailto:eesposit@redhat.com>
fb0fb1
fb0fb1
commit 3c432b32de1bdce2699525201396a8bbc6a41f3e
fb0fb1
Author: Lukas Märdian <luk@slyon.de>
fb0fb1
Date:   Thu Oct 29 14:38:56 2020 +0100
fb0fb1
fb0fb1
    get_interfaces: don't exclude Open vSwitch bridge/bond members (#608)
fb0fb1
fb0fb1
    If an OVS bridge was used as the only/primary interface, the 'init'
fb0fb1
    stage failed with a "Not all expected physical devices present" error,
fb0fb1
    leaving the system with a broken SSH setup.
fb0fb1
fb0fb1
    LP: #1898997
fb0fb1
fb0fb1
Signed-off-by: Eduardo Otubo <otubo@redhat.com>
fb0fb1
---
fb0fb1
 cloudinit/net/__init__.py        | 15 +++++++++++--
fb0fb1
 cloudinit/net/tests/test_init.py | 36 +++++++++++++++++++++++++++++++-
fb0fb1
 tools/.github-cla-signers        |  1 +
fb0fb1
 3 files changed, 49 insertions(+), 3 deletions(-)
fb0fb1
fb0fb1
diff --git a/cloudinit/net/__init__.py b/cloudinit/net/__init__.py
fb0fb1
index e233149a..0aa58b27 100644
fb0fb1
--- a/cloudinit/net/__init__.py
fb0fb1
+++ b/cloudinit/net/__init__.py
fb0fb1
@@ -124,6 +124,15 @@ def master_is_bridge_or_bond(devname):
fb0fb1
     return (os.path.exists(bonding_path) or os.path.exists(bridge_path))
fb0fb1
 
fb0fb1
 
fb0fb1
+def master_is_openvswitch(devname):
fb0fb1
+    """Return a bool indicating if devname's master is openvswitch"""
fb0fb1
+    master_path = get_master(devname)
fb0fb1
+    if master_path is None:
fb0fb1
+        return False
fb0fb1
+    ovs_path = sys_dev_path(devname, path="upper_ovs-system")
fb0fb1
+    return os.path.exists(ovs_path)
fb0fb1
+
fb0fb1
+
fb0fb1
 def is_netfailover(devname, driver=None):
fb0fb1
     """ netfailover driver uses 3 nics, master, primary and standby.
fb0fb1
         this returns True if the device is either the primary or standby
fb0fb1
@@ -855,8 +864,10 @@ def get_interfaces():
fb0fb1
             continue
fb0fb1
         if is_bond(name):
fb0fb1
             continue
fb0fb1
-        if get_master(name) is not None and not master_is_bridge_or_bond(name):
fb0fb1
-            continue
fb0fb1
+        if get_master(name) is not None:
fb0fb1
+            if (not master_is_bridge_or_bond(name) and
fb0fb1
+                    not master_is_openvswitch(name)):
fb0fb1
+                continue
fb0fb1
         if is_netfailover(name):
fb0fb1
             continue
fb0fb1
         mac = get_interface_mac(name)
fb0fb1
diff --git a/cloudinit/net/tests/test_init.py b/cloudinit/net/tests/test_init.py
fb0fb1
index 311ab6f8..0535387a 100644
fb0fb1
--- a/cloudinit/net/tests/test_init.py
fb0fb1
+++ b/cloudinit/net/tests/test_init.py
fb0fb1
@@ -190,6 +190,28 @@ class TestReadSysNet(CiTestCase):
fb0fb1
         self.assertTrue(net.master_is_bridge_or_bond('eth1'))
fb0fb1
         self.assertTrue(net.master_is_bridge_or_bond('eth2'))
fb0fb1
 
fb0fb1
+    def test_master_is_openvswitch(self):
fb0fb1
+        ovs_mac = 'bb:cc:aa:bb:cc:aa'
fb0fb1
+
fb0fb1
+        # No master => False
fb0fb1
+        write_file(os.path.join(self.sysdir, 'eth1', 'address'), ovs_mac)
fb0fb1
+
fb0fb1
+        self.assertFalse(net.master_is_bridge_or_bond('eth1'))
fb0fb1
+
fb0fb1
+        # masters without ovs-system => False
fb0fb1
+        write_file(os.path.join(self.sysdir, 'ovs-system', 'address'), ovs_mac)
fb0fb1
+
fb0fb1
+        os.symlink('../ovs-system', os.path.join(self.sysdir, 'eth1',
fb0fb1
+                   'master'))
fb0fb1
+
fb0fb1
+        self.assertFalse(net.master_is_openvswitch('eth1'))
fb0fb1
+
fb0fb1
+        # masters with ovs-system => True
fb0fb1
+        os.symlink('../ovs-system', os.path.join(self.sysdir, 'eth1',
fb0fb1
+                   'upper_ovs-system'))
fb0fb1
+
fb0fb1
+        self.assertTrue(net.master_is_openvswitch('eth1'))
fb0fb1
+
fb0fb1
     def test_is_vlan(self):
fb0fb1
         """is_vlan is True when /sys/net/devname/uevent has DEVTYPE=vlan."""
fb0fb1
         ensure_file(os.path.join(self.sysdir, 'eth0', 'uevent'))
fb0fb1
@@ -465,20 +487,32 @@ class TestGetInterfaceMAC(CiTestCase):
fb0fb1
     ):
fb0fb1
         bridge_mac = 'aa:bb:cc:aa:bb:cc'
fb0fb1
         bond_mac = 'cc:bb:aa:cc:bb:aa'
fb0fb1
+        ovs_mac = 'bb:cc:aa:bb:cc:aa'
fb0fb1
+
fb0fb1
         write_file(os.path.join(self.sysdir, 'br0', 'address'), bridge_mac)
fb0fb1
         write_file(os.path.join(self.sysdir, 'br0', 'bridge'), '')
fb0fb1
 
fb0fb1
         write_file(os.path.join(self.sysdir, 'bond0', 'address'), bond_mac)
fb0fb1
         write_file(os.path.join(self.sysdir, 'bond0', 'bonding'), '')
fb0fb1
 
fb0fb1
+        write_file(os.path.join(self.sysdir, 'ovs-system', 'address'),
fb0fb1
+                   ovs_mac)
fb0fb1
+
fb0fb1
         write_file(os.path.join(self.sysdir, 'eth1', 'address'), bridge_mac)
fb0fb1
         os.symlink('../br0', os.path.join(self.sysdir, 'eth1', 'master'))
fb0fb1
 
fb0fb1
         write_file(os.path.join(self.sysdir, 'eth2', 'address'), bond_mac)
fb0fb1
         os.symlink('../bond0', os.path.join(self.sysdir, 'eth2', 'master'))
fb0fb1
 
fb0fb1
+        write_file(os.path.join(self.sysdir, 'eth3', 'address'), ovs_mac)
fb0fb1
+        os.symlink('../ovs-system', os.path.join(self.sysdir, 'eth3',
fb0fb1
+                   'master'))
fb0fb1
+        os.symlink('../ovs-system', os.path.join(self.sysdir, 'eth3',
fb0fb1
+                   'upper_ovs-system'))
fb0fb1
+
fb0fb1
         interface_names = [interface[0] for interface in net.get_interfaces()]
fb0fb1
-        self.assertEqual(['eth1', 'eth2'], sorted(interface_names))
fb0fb1
+        self.assertEqual(['eth1', 'eth2', 'eth3', 'ovs-system'],
fb0fb1
+                         sorted(interface_names))
fb0fb1
 
fb0fb1
 
fb0fb1
 class TestInterfaceHasOwnMAC(CiTestCase):
fb0fb1
diff --git a/tools/.github-cla-signers b/tools/.github-cla-signers
fb0fb1
index e5d2b95c..db55361a 100644
fb0fb1
--- a/tools/.github-cla-signers
fb0fb1
+++ b/tools/.github-cla-signers
fb0fb1
@@ -16,6 +16,7 @@ matthewruffell
fb0fb1
 nishigori
fb0fb1
 omBratteng
fb0fb1
 onitake
fb0fb1
+slyon
fb0fb1
 smoser
fb0fb1
 sshedi
fb0fb1
 TheRealFalcon
fb0fb1
-- 
fb0fb1
2.27.0
fb0fb1