[ovs-dev] [PATCH] ovs-xapi-sync: Add retries while getting single bridge ids.
Gurucharan Shetty
shettyg at nicira.com
Fri Jun 14 16:52:59 UTC 2013
When there are multiple xs-network-uuids set for a bridge,
we query xapi to get the record that does not have a VLAN
associated with it. For cases when xapi does not respond,
retry a few times and log the failures.
If after the retries, we still do not get the correct record,
set the external_ids:bridge_id as empty("").
Bug #17877.
Signed-off-by: Gurucharan Shetty <gshetty at nicira.com>
---
.../usr_share_openvswitch_scripts_ovs-xapi-sync | 52 +++++++++++++-------
1 file changed, 33 insertions(+), 19 deletions(-)
diff --git a/xenserver/usr_share_openvswitch_scripts_ovs-xapi-sync b/xenserver/usr_share_openvswitch_scripts_ovs-xapi-sync
index ac56d37..ab21c45 100755
--- a/xenserver/usr_share_openvswitch_scripts_ovs-xapi-sync
+++ b/xenserver/usr_share_openvswitch_scripts_ovs-xapi-sync
@@ -97,25 +97,39 @@ def get_single_bridge_id(bridge_ids, default=None):
"XAPI session could not be initialized" % bridge_ids)
return default
- for bridge_id in bridge_ids:
- 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
+ tries = 5
+ while tries:
+ for bridge_id in bridge_ids:
+ 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
+
+ except Exception:
+ vlog.warn("Unexpected exception.")
+ continue
+
+ vlog.warn("Failed to get a single bridge id from Xapi for %s,"
+ "retrying.." %(" ".join(bridge_ids)))
+ time.sleep(1)
+ tries -= 1
+ vlog.warn("Failed to get a single bridge id from Xapi.")
return default
# By default, the "bridge-id" external id in the Bridge table is the
@@ -317,7 +331,7 @@ def main():
bridge_id = row.external_ids.get("xs-network-uuids")
if bridge_id and len(bridge_id.split(";")) > 1:
bridge_ids = bridge_id.split(";")
- bridge_id = get_single_bridge_id(bridge_ids, bridge_ids[0])
+ bridge_id = get_single_bridge_id(bridge_ids, "")
if bridge_id is not None:
set_external_id(row, "bridge-id", bridge_id.split(";")[0])
--
1.7.9.5
More information about the dev
mailing list