diff options
| author | Rafael Zalamena <rzalamena@gmail.com> | 2017-06-28 15:30:44 -0300 |
|---|---|---|
| committer | Donald Sharp <sharpd@cumulusnetworks.com> | 2018-11-27 20:22:11 -0500 |
| commit | a40daddc4c7c3e0f30f2a136a9ae9165e351bcdc (patch) | |
| tree | 71f4669a0abfe1a15964558b08834c7624980b06 /tests | |
| parent | 09e21b44879ea05365d56feca6ce35a8c1753a63 (diff) | |
topogen: added JSON output support for vtysh_cmd
Allow vtysh_cmd() to convert JSON output to Python data structures.
This feature will be used to get vtysh JSON outputs for tests
comparsions.
Usage example:
```py
router = get_topogen().gears['r1']
json_output = router.vtysh_cmd('show ip ospf json', isjson=True)
json_cmp(json_output, {'important_key': 'important_value'})
```
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/topotests/lib/topogen.py | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/tests/topotests/lib/topogen.py b/tests/topotests/lib/topogen.py index f437401517..97f006c59c 100644 --- a/tests/topotests/lib/topogen.py +++ b/tests/topotests/lib/topogen.py @@ -40,6 +40,7 @@ Basic usage instructions: import os import sys +import json from mininet.net import Mininet from mininet.log import setLogLevel @@ -388,7 +389,7 @@ class TopoRouter(TopoGear): """ return self.tgen.net[self.name].startRouter() - def vtysh_cmd(self, command): + def vtysh_cmd(self, command, isjson=False): """ Runs the provided command string in the vty shell and returns a string with the response. @@ -401,7 +402,11 @@ class TopoRouter(TopoGear): return self.vtysh_multicmd(command) vtysh_command = 'vtysh -c "{}" 2>/dev/null'.format(command) - return self.run(vtysh_command) + output = self.run(vtysh_command) + if isjson is False: + return output + + return json.loads(output) def vtysh_multicmd(self, commands, pretty_output=True): """ |
