[node-patches] Change in ovirt-node[ovirt-3.6]: Sometimes BridgedNIC gets called with a bridge. Be smarter

dougsland at redhat.com dougsland at redhat.com
Tue Jan 12 20:22:02 UTC 2016


Douglas Schilling Landgraf has uploaded a new change for review.

Change subject: Sometimes BridgedNIC gets called with a bridge. Be smarter
......................................................................

Sometimes BridgedNIC gets called with a bridge. Be smarter

Previously, if BridgedNIC was called with an actual bridge as the
argument (ovirtmgmt, for example), it set null values for some
fields, such as the bridge nic, which caused the network to show
unconfigured when it actually was.

Add a method to Bridges() to find slaves.
Add BridgeNIC (essentially BridgedNIC but setting the ifname to
the bridge instead of the slave)

Called BridgedNIC only if it's a slave. If it's a bridge, call
BridgeNIC, and set the ifname appropriately.

Check /sys to find the actual slave nic

Change-Id: I9f7181d8fea099c6dce9f287c56d85b92afad068
Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=1280241
Signed-off-by: Ryan Barry <rbarry at redhat.com>
Signed-off-by: Douglas Schilling Landgraf <dougsland at redhat.com>
(cherry picked from commit 65c1e24e2b70c0ac17b4b3867d10722ed90f4209)
---
M src/ovirt/node/utils/network.py
1 file changed, 26 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-node refs/changes/58/51758/1

diff --git a/src/ovirt/node/utils/network.py b/src/ovirt/node/utils/network.py
index fa742d0..6220d96 100755
--- a/src/ovirt/node/utils/network.py
+++ b/src/ovirt/node/utils/network.py
@@ -398,6 +398,19 @@
         return self.build_str(["ifname"], additional_pairs=pairs)
 
 
+class BridgeNIC(BridgedNIC):
+    def __init__(self, nic):
+        snic = Bridges().slave_for_bridge(nic)
+        super(BridgeNIC, self).__init__(snic)
+        if snic.ifname != nic.ifname:
+            self.ifname = nic.ifname
+        else:
+            # There are no slaves. ;vdsmdummy; ?
+            # Leave it with the old behavior so we don't introduce
+            # any regressions
+            pass
+
+
 class TaggedNIC(NIC):
     """A class to provide easy access to tagged NICs
     """
@@ -584,12 +597,12 @@
                 self.logger.debug(" Has tag")
                 nic = TaggedNIC(nic, vlanid)
 
-            if layout == "bridged":
+            if layout == "bridged" and not nic.typ == "bridge":
                 self.logger.debug(" Is bridged")
                 nic = BridgedNIC(nic)
 
         if nic.typ == "bridge":
-            nic = BridgedNIC(nic)
+            nic = BridgeNIC(nic)
 
         if nic.is_configured() and filter_configured:
             # Don not return configured NICs
@@ -870,6 +883,17 @@
         process.call(["ip", "link", "set", "dev", ifname, "down"])
         process.call(["brctl", "delbr", ifname])
 
+    def slave_for_bridge(self, nic):
+        try:
+            slave = os.listdir("/sys/class/net/%s/brif" % nic.ifname)[0]
+            nic = NIC(slave)
+        except IndexError:
+            # No slaves. ;vdsmdummy; ?
+            # leave snic as it is with the old behavior
+            self.logger.info("Couldn't find a slave for BridgedNIC %s" %
+                             nic.ifname)
+        return nic
+
 
 class Bonds(base.Base):
     """Convenience API to access some bonding related stuff


-- 
To view, visit https://gerrit.ovirt.org/51758
To unsubscribe, visit https://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I9f7181d8fea099c6dce9f287c56d85b92afad068
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-node
Gerrit-Branch: ovirt-3.6
Gerrit-Owner: Douglas Schilling Landgraf <dougsland at redhat.com>



More information about the node-patches mailing list