aboutsummaryrefslogtreecommitdiffstats
path: root/src/vpp-api/python/vpp_papi/vpp_stats.py
diff options
context:
space:
mode:
authorPaul Vinciguerra <pvinci@vinciconsulting.com>2018-11-27 08:15:22 -0800
committerOle Trøan <otroan@employees.org>2018-11-29 19:18:07 +0000
commit6ccc6e91648312cc210e9b6a18e469e64f4a523f (patch)
treec80d92e7d8c1c28f90cb92d4455c39c52f3b2617 /src/vpp-api/python/vpp_papi/vpp_stats.py
parent039a1c2f1401ebf3b38fa9bd55dffff0713b8b98 (diff)
vpp_papi: Add custom exceptions.
This patchset adds and raises the following custom exception classes: * class VPPApiError(Exception): * class VPPNotImplementedError(NotImplementedError): * class VPPIOError(IOError): * class VPPRuntimeError(RuntimeError): * class VPPValueError(ValueError): * class VPPSerializerValueError(ValueError): * class VPPStatsIOError(IOError): * class VPPStatsClientLoadError(RuntimeError): * class VppTransportShmemIOError(IOError): * class VppTransportSocketIOError(IOError) Change-Id: Ia40900fd2dcef148d01125d6c691329fc666901e Signed-off-by: Paul Vinciguerra <pvinci@vinciconsulting.com>
Diffstat (limited to 'src/vpp-api/python/vpp_papi/vpp_stats.py')
-rw-r--r--src/vpp-api/python/vpp_papi/vpp_stats.py28
1 files changed, 21 insertions, 7 deletions
diff --git a/src/vpp-api/python/vpp_papi/vpp_stats.py b/src/vpp-api/python/vpp_papi/vpp_stats.py
index 8344de0c55b..bb6cdf5ffdc 100644
--- a/src/vpp-api/python/vpp_papi/vpp_stats.py
+++ b/src/vpp-api/python/vpp_papi/vpp_stats.py
@@ -138,12 +138,26 @@ def stat_entry_to_python(api, e):
return None
+class VPPStatsIOError(IOError):
+ pass
+
+
+class VPPStatsClientLoadError(RuntimeError):
+ pass
+
+
class VPPStats(object):
- def __init__(self, socketname='/var/run/stats.sock', timeout=10):
+ VPPStatsIOError = VPPStatsIOError
+
+ default_socketname = '/var/run/stats.sock'
+ sharedlib_name = 'libvppapiclient.so'
+
+ def __init__(self, socketname=default_socketname, timeout=10):
try:
- self.api = ffi.dlopen('libvppapiclient.so')
+ self.api = ffi.dlopen(VPPStats.sharedlib_name)
except Exception:
- raise RuntimeError("Could not open: libvppapiclient.so")
+ raise VPPStatsClientLoadError("Could not open: %s" %
+ VPPStats.sharedlib_name)
self.client = self.api.stat_client_get()
poll_end_time = time.time() + timeout
@@ -154,7 +168,7 @@ class VPPStats(object):
break
if rv != 0:
- raise IOError()
+ raise VPPStatsIOError()
def heartbeat(self):
return self.api.stat_segment_heartbeat_r(self.client)
@@ -169,7 +183,7 @@ class VPPStats(object):
rv = self.api.stat_segment_dump_r(counters, self.client)
# Raise exception and retry
if rv == ffi.NULL:
- raise IOError()
+ raise VPPStatsIOError()
rv_len = self.api.stat_segment_vec_len(rv)
for i in range(rv_len):
n = ffi.string(rv[i].name).decode()
@@ -184,7 +198,7 @@ class VPPStats(object):
try:
dir = self.ls(name)
return self.dump(dir).values()[0]
- except Exception as e:
+ except VPPStatsIOError as e:
if retries > 10:
return None
retries += 1
@@ -201,7 +215,7 @@ class VPPStats(object):
error_names = self.ls(['/err/'])
error_counters = self.dump(error_names)
break
- except Exception as e:
+ except VPPStatsIOError as e:
if retries > 10:
return None
retries += 1