]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
fall back to `ip link` when `ip tuntap` unavailable
authorGary Kotton <gkotton@redhat.com>
Tue, 15 May 2012 07:33:04 +0000 (03:33 -0400)
committerGary Kotton <gkotton@redhat.com>
Wed, 16 May 2012 19:16:30 +0000 (15:16 -0400)
bug 989868

In the event that the command "ip tuntap" is not found then a exception will
be raised and the command "ip link" will be perfomed.

Changes following comments

More appropriate error message

Same style for log/error messages

Change-Id: Ia912e189b73dd0d112b7ef4eefbb7245ee595b54

quantum/plugins/linuxbridge/agent/linuxbridge_quantum_agent.py

index a65b19dc76bec896697f0647dfe4474733c4464e..354ef66566543652d62671ccba16c439bacd295f 100755 (executable)
@@ -34,6 +34,8 @@ import time
 
 from sqlalchemy.ext.sqlsoup import SqlSoup
 
+from quantum.common import exceptions as exception
+
 logging.basicConfig()
 LOG = logging.getLogger(__name__)
 
@@ -62,7 +64,7 @@ class LinuxBridge:
         self.physical_interface = physical_interface
         self.root_helper = root_helper
 
-    def run_cmd(self, args):
+    def run_cmd(self, args, check_return=False):
         cmd = shlex.split(self.root_helper) + args
         LOG.debug("Running command: " + " ".join(cmd))
         p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
@@ -71,6 +73,10 @@ class LinuxBridge:
             LOG.debug("Timeout running command: " + " ".join(cmd))
         if retval:
             LOG.debug("Command returned: %s" % retval)
+        if (p.returncode != 0 and check_return):
+            msg = "Command failed: " + " ".join(cmd)
+            LOG.debug(msg)
+            raise exception.ProcessExecutionError(msg)
         return retval
 
     def device_exists(self, device):
@@ -116,27 +122,39 @@ class LinuxBridge:
                 BRIDGE_NAME_PLACEHOLDER, bridge_name)
             return os.listdir(bridge_interface_path)
 
-    def get_all_tap_devices(self):
-        tap_devices = []
-        retval = self.run_cmd(['ip', 'tuntap'])
+    def _get_prefixed_ip_link_devices(self, prefix):
+        prefixed_devices = []
+        retval = self.run_cmd(['ip', 'link'])
         rows = retval.split('\n')
         for row in rows:
-            split_row = row.split(':')
-            if split_row[0].startswith(TAP_INTERFACE_PREFIX):
-                tap_devices.append(split_row[0])
-
-        return tap_devices
-
-    def get_all_gateway_devices(self):
-        gw_devices = []
-        retval = self.run_cmd(['ip', 'tuntap'])
+            values = row.split(':')
+            if (len(values) > 2):
+                value = values[1].strip(' ')
+                if (value.startswith(prefix)):
+                    prefixed_devices.append(value)
+        return prefixed_devices
+
+    def _get_prefixed_tap_devices(self, prefix):
+        prefixed_devices = []
+        retval = self.run_cmd(['ip', 'tuntap'], check_return=True)
         rows = retval.split('\n')
         for row in rows:
             split_row = row.split(':')
-            if split_row[0].startswith(GATEWAY_INTERFACE_PREFIX):
-                gw_devices.append(split_row[0])
+            if split_row[0].startswith(prefix):
+                prefixed_devices.append(split_row[0])
+        return prefixed_devices
 
-        return gw_devices
+    def get_all_tap_devices(self):
+        try:
+            return self._get_prefixed_tap_devices(TAP_INTERFACE_PREFIX)
+        except exception.ProcessExecutionError:
+            return self._get_prefixed_ip_link_devices(TAP_INTERFACE_PREFIX)
+
+    def get_all_gateway_devices(self):
+        try:
+            return self._get_prefixed_tap_devices(GATEWAY_INTERFACE_PREFIX)
+        except exception.ProcessExecutionError:
+            return self._get_prefixed_ip_link_devices(GATEWAY_INTERFACE_PREFIX)
 
     def get_bridge_for_tap_device(self, tap_device_name):
         bridges = self.get_all_quantum_bridges()