From c27213a30f4d6b5395ba70f011615ae9c7be93ce Mon Sep 17 00:00:00 2001 From: Ole Troan Date: Wed, 31 Aug 2016 14:50:49 +0200 Subject: Add in-message cli_request/cli_reply API This new CLI API is meant to replace the cli_request/cli_reply that uses shared memory. PS: checkstyle -- *hate* Change-Id: I6318f8f6b9be2c2398b49dac9e2193c1998ea724 Signed-off-by: Ole Troan --- vpp-api/python/tests/test_cli.py | 52 +++++++++++++++++++++++++++++++++++++ vpp-api/python/vpp_papi/vpp_papi.py | 6 +++++ 2 files changed, 58 insertions(+) create mode 100755 vpp-api/python/tests/test_cli.py (limited to 'vpp-api') diff --git a/vpp-api/python/tests/test_cli.py b/vpp-api/python/tests/test_cli.py new file mode 100755 index 00000000000..66fb6943e70 --- /dev/null +++ b/vpp-api/python/tests/test_cli.py @@ -0,0 +1,52 @@ +#!/usr/bin/env python + +from __future__ import print_function +import unittest, sys, time, threading, struct +import test_base +import vpp_papi +from ipaddress import * + +import glob, subprocess +class TestPAPI(unittest.TestCase): + @classmethod + def setUpClass(cls): + # + # Start main VPP process + cls.vpp_bin = glob.glob(test_base.scriptdir+'/../../../build-root/install-vpp*-native/vpp/bin/vpp')[0] + print("VPP BIN:", cls.vpp_bin) + cls.vpp = subprocess.Popen([cls.vpp_bin, "unix", "nodaemon"], stderr=subprocess.PIPE) + print('Started VPP') + # For some reason unless we let VPP start up the API cannot connect. + time.sleep(0.3) + @classmethod + def tearDownClass(cls): + cls.vpp.terminate() + + def setUp(self): + print("Connecting API") + r = vpp_papi.connect("test_papi") + self.assertEqual(r, 0) + + def tearDown(self): + r = vpp_papi.disconnect() + self.assertEqual(r, 0) + + # + # The tests themselves + # + + # + # Basic request / reply + # + def test_cli_request(self): + print(vpp_papi.cli_exec('show version verbose')) + #t = vpp_papi.cli_inband_request(len(cmd), cmd) + #print('T:',t) + #reply = t.reply[0].decode().rstrip('\x00') + #print(reply) + #program = t.program.decode().rstrip('\x00') + #self.assertEqual('vpe', program) + + +if __name__ == '__main__': + unittest.main() diff --git a/vpp-api/python/vpp_papi/vpp_papi.py b/vpp-api/python/vpp_papi/vpp_papi.py index 6a7a358f6cd..144151c4154 100644 --- a/vpp-api/python/vpp_papi/vpp_papi.py +++ b/vpp-api/python/vpp_papi/vpp_papi.py @@ -99,6 +99,12 @@ def disconnect(): logging.info("Disconnected") return rv +# CLI convenience wrapper +def cli_exec(cmd): + cmd += '\n' + r = cli_inband(len(cmd), cmd) + return r.reply[0].decode().rstrip('\x00') + def register_event_callback(callback): event_callback_set(callback) -- cgit 1.2.3-korg