summaryrefslogtreecommitdiffstats
path: root/src/vpp-api/python/vpp_papi
diff options
context:
space:
mode:
authorOle Troan <ot@cisco.com>2018-09-18 11:06:33 +0200
committerOle Troan <ot@cisco.com>2018-09-18 11:06:33 +0200
commitb4603a70cbc00daa8cbce159f513af205b634aa9 (patch)
tree41bf9b9a550aba787b36c75a8f478d162a33fa65 /src/vpp-api/python/vpp_papi
parent45d5c87d86d8ac5268e08f743eb032f5a66a82f8 (diff)
STATS: Optimistic concurrency handling in Python library.
Change-Id: I2135f3e77206fd171636a1e0b07c373c0bf093e4 Signed-off-by: Ole Troan <ot@cisco.com>
Diffstat (limited to 'src/vpp-api/python/vpp_papi')
-rw-r--r--src/vpp-api/python/vpp_papi/vpp_stats.py28
1 files changed, 24 insertions, 4 deletions
diff --git a/src/vpp-api/python/vpp_papi/vpp_stats.py b/src/vpp-api/python/vpp_papi/vpp_stats.py
index ecd734bbf7d..456312bdc5b 100644
--- a/src/vpp-api/python/vpp_papi/vpp_stats.py
+++ b/src/vpp-api/python/vpp_papi/vpp_stats.py
@@ -127,6 +127,9 @@ class VPPStats:
def dump(self, counters):
stats = {}
rv = self.api.stat_segment_dump(counters)
+ # Raise exception and retry
+ if rv == ffi.NULL:
+ raise IOError()
rv_len = self.api.stat_segment_vec_len(rv)
for i in range(rv_len):
n = ffi.string(rv[i].name).decode()
@@ -135,16 +138,33 @@ class VPPStats:
return stats
def get_counter(self, name):
- dir = self.ls(name)
- return self.dump(dir).values()[0]
+ retries = 0
+ while True:
+ try:
+ dir = self.ls(name)
+ return self.dump(dir).values()[0]
+ except:
+ if retries > 10:
+ return None
+ retries += 1
+ pass
def disconnect(self):
self.api.stat_segment_disconnect()
def set_errors(self):
'''Return all errors counters > 0'''
- error_names = self.ls(['/err/'])
- error_counters = self.dump(error_names)
+ retries = 0
+ while True:
+ try:
+ error_names = self.ls(['/err/'])
+ error_counters = self.dump(error_names)
+ break
+ except:
+ if retries > 10:
+ return None
+ retries += 1
+ pass
return {k: error_counters[k]
for k in error_counters.keys() if error_counters[k]}