aboutsummaryrefslogtreecommitdiffstats
path: root/resources/libraries/python/VppCounters.py
diff options
context:
space:
mode:
authorMatej Klotton <mklotton@cisco.com>2016-03-02 16:51:30 +0100
committerStefan Kobza <skobza@cisco.com>2016-03-07 16:17:01 +0100
commit799c246c1783b534df0ce7731c9078463be33bdd (patch)
tree95056726292c3334cd3f71c4e154c01993800efa /resources/libraries/python/VppCounters.py
parentcdf3213528f5f560d8d8b92c642f655cef706745 (diff)
Add with-statment support to VatTerminal.
Change-Id: I7b4b32ce07b9247ccf80bf6b5d3339d00bc0999f Signed-off-by: Matej Klotton <mklotton@cisco.com>
Diffstat (limited to 'resources/libraries/python/VppCounters.py')
-rw-r--r--resources/libraries/python/VppCounters.py23
1 files changed, 10 insertions, 13 deletions
diff --git a/resources/libraries/python/VppCounters.py b/resources/libraries/python/VppCounters.py
index b99d65274b..caae06c495 100644
--- a/resources/libraries/python/VppCounters.py
+++ b/resources/libraries/python/VppCounters.py
@@ -83,19 +83,16 @@ class VppCounters(object):
:type node: dict
:return: Stats table.
"""
- vat = VatTerminal(node)
- vat.vat_terminal_exec_cmd('want_stats enable')
- for _ in range(0, 12):
- stats_table = vat.vat_terminal_exec_cmd('dump_stats_table')
- if_counters = stats_table['interface_counters']
- if len(if_counters) > 0:
- self._stats_table = stats_table
- vat.vat_terminal_close()
- return stats_table
- time.sleep(1)
-
- vat.vat_terminal_close()
- return None
+ with VatTerminal(node) as vat:
+ vat.vat_terminal_exec_cmd('want_stats enable')
+ for _ in range(0, 12):
+ stats_table = vat.vat_terminal_exec_cmd('dump_stats_table')
+ if_counters = stats_table['interface_counters']
+ if len(if_counters) > 0:
+ self._stats_table = stats_table
+ return stats_table
+ time.sleep(1)
+ return None
def vpp_get_ipv4_interface_counter(self, node, interface):
return self.vpp_get_ipv46_interface_counter(node, interface, False)