ovs-xapi-sync: Handle exceptions from XAPI for get_single_bridge_id.
authorGurucharan Shetty <gshetty@nicira.com>
Thu, 23 May 2013 23:14:19 +0000 (16:14 -0700)
committerGurucharan Shetty <gshetty@nicira.com>
Fri, 24 May 2013 17:58:26 +0000 (10:58 -0700)
There are possibilities when records disappear underneath ovs-xapi-sync.
In this particular case, when VLAN network was deleted, the corresponding
record in bridge's external_ids:xs_network_ids column was not deleted by
xenserver.  In situations like that handle the exceptions cleanly.

Bug #17390.
Signed-off-by: Gurucharan Shetty <gshetty@nicira.com>
xenserver/usr_share_openvswitch_scripts_ovs-xapi-sync

index e14b319..ac56d37 100755 (executable)
@@ -98,13 +98,23 @@ def get_single_bridge_id(bridge_ids, default=None):
         return default
 
     for bridge_id in bridge_ids:
-       recs = session.xenapi.network.get_all_records_where('field "uuid"="%s"' % bridge_id)
-       if recs:
-           pifs = recs.values()[0]['PIFs']
-           for pif in pifs:
-               rec = session.xenapi.PIF.get_record(pif)
-               if rec['VLAN'] == '-1':
-                   return bridge_id
+        try:
+            recs = session.xenapi.network.get_all_records_where(\
+                                            'field "uuid"="%s"' % bridge_id)
+            if recs:
+                pifs = recs.values()[0]['PIFs']
+                for pif in pifs:
+                    try:
+                        rec = session.xenapi.PIF.get_record(pif)
+                        if rec['VLAN'] == '-1':
+                            return bridge_id
+                    except XenAPI.Failure:
+                        vlog.warn("Could not find XAPI entry for PIF %s" % pif)
+                        continue
+
+        except XenAPI.Failure:
+            vlog.warn("Could not find XAPI entry for bridge_id %s" % bridge_id)
+            continue
 
     return default