]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Check if interface exists in bridge prior to adding.
authorGary Kotton <gkotton@redhat.com>
Sun, 1 Jul 2012 07:06:07 +0000 (03:06 -0400)
committerGary Kotton <gkotton@redhat.com>
Mon, 2 Jul 2012 15:27:47 +0000 (11:27 -0400)
This fixes bug 1019730. The fix for bug 1000406 ensures that return
values of shell commands are checked. The command
    utils.execute(['brctl', 'addif', bridge_name, interface],
                   root_helper=self.root_helper)
would cause an exception if there was more than one attachment
on the network. The reason for this was the interface already existed
on the bridge.

Change-Id: I8a1f6cc7be930c04ce302d7f87814b9bd5bed129

quantum/plugins/linuxbridge/agent/linuxbridge_quantum_agent.py

index 4eb2620286b37a5c4b60050dc8c182475a8339bd..91a1e3218fbb1a76f2e2214af96e964369315197 100755 (executable)
@@ -73,6 +73,13 @@ class LinuxBridge:
             return False
         return True
 
+    def interface_exists_on_bridge(self, bridge, interface):
+        directory = '/sys/class/net/%s/brif' % bridge
+        for filename in os.listdir(directory):
+            if filename == interface:
+                return True
+        return False
+
     def get_bridge_name(self, network_id):
         if not network_id:
             LOG.warning("Invalid Network ID, will lead to incorrect bridge"
@@ -205,8 +212,10 @@ class LinuxBridge:
             LOG.debug("Done starting bridge %s for subinterface %s" %
                       (bridge_name, interface))
 
-        utils.execute(['brctl', 'addif', bridge_name, interface],
-                      root_helper=self.root_helper)
+        # Check if the interface is part of the bridge
+        if not self.interface_exists_on_bridge(bridge_name, interface):
+            utils.execute(['brctl', 'addif', bridge_name, interface],
+                          root_helper=self.root_helper)
 
     def add_tap_interface(self, network_id, vlan_id, tap_device_name):
         """