]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Treat exceptions when invoking ovs-vsctl
authorGary Kotton <gkotton@redhat.com>
Sun, 19 Aug 2012 08:11:06 +0000 (04:11 -0400)
committerGary Kotton <gkotton@redhat.com>
Mon, 20 Aug 2012 10:07:42 +0000 (06:07 -0400)
Fixes bug 1037902

Change-Id: I3f5bbac2f0c390fd7eaae4eb6338e5ac600c9aba

quantum/agent/linux/ovs_lib.py

index 67f06580e2aaf180c16d03bddd2aade3457a3aed..19aa911ade426872f639655f83508ef97ed06253 100644 (file)
@@ -39,7 +39,7 @@ class VifPort:
     def __str__(self):
         return ("iface-id=" + self.vif_id + ", vif_mac=" +
                 self.vif_mac + ", port_name=" + self.port_name +
-                ", ofport=" + str(self.ofport) + ", bridge_name = " +
+                ", ofport=" + str(self.ofport) + ", bridge_name =" +
                 self.switch.br_name)
 
 
@@ -50,7 +50,10 @@ class OVSBridge:
 
     def run_vsctl(self, args):
         full_args = ["ovs-vsctl", "--timeout=2"] + args
-        return utils.execute(full_args, root_helper=self.root_helper)
+        try:
+            return utils.execute(full_args, root_helper=self.root_helper)
+        except Exception, e:
+            LOG.error("Unable to execute %s. Exception: %s", full_args, e)
 
     def reset_bridge(self):
         self.run_vsctl(["--", "--if-exists", "del-br", self.br_name])
@@ -70,7 +73,10 @@ class OVSBridge:
 
     def run_ofctl(self, cmd, args):
         full_args = ["ovs-ofctl", cmd, self.br_name] + args
-        return utils.execute(full_args, root_helper=self.root_helper)
+        try:
+            return utils.execute(full_args, root_helper=self.root_helper)
+        except Exception, e:
+            LOG.error("Unable to execute %s. Exception: %s", full_args, e)
 
     def count_flows(self):
         flow_list = self.run_ofctl("dump-flows", []).split("\n")[1:]
@@ -155,11 +161,15 @@ class OVSBridge:
         return self.get_port_ofport(local_name)
 
     def db_get_map(self, table, record, column):
-        str = self.run_vsctl(["get", table, record, column]).rstrip("\n\r")
-        return self.db_str_to_map(str)
+        output = self.run_vsctl(["get", table, record, column])
+        if output:
+            str = output.rstrip("\n\r")
+            return self.db_str_to_map(str)
 
     def db_get_val(self, table, record, column):
-        return self.run_vsctl(["get", table, record, column]).rstrip("\n\r")
+        output = self.run_vsctl(["get", table, record, column])
+        if output:
+            return output.rstrip("\n\r")
 
     def db_str_to_map(self, full_str):
         list = full_str.strip("{}").split(", ")
@@ -173,16 +183,20 @@ class OVSBridge:
 
     def get_port_name_list(self):
         res = self.run_vsctl(["list-ports", self.br_name])
-        return res.split("\n")[0:-1]
+        if res:
+            return res.strip().split("\n")
+        return []
 
     def get_port_stats(self, port_name):
         return self.db_get_map("Interface", port_name, "statistics")
 
     def get_xapi_iface_id(self, xs_vif_uuid):
-        return utils.execute(["xe", "vif-param-get", "param-name=other-config",
-                              "param-key=nicira-iface-id",
-                              "uuid=%s" % xs_vif_uuid],
-                             root_helper=self.root_helper).strip()
+        args = ["xe", "vif-param-get", "param-name=other-config",
+                "param-key=nicira-iface-id", "uuid=%s" % xs_vif_uuid]
+        try:
+            return utils.execute(args, root_helper=self.root_helper).strip()
+        except Exception, e:
+            LOG.error("Unable to execute %s. Exception: %s", args, e)
 
     # returns a VIF object for each VIF port
     def get_vif_ports(self):