blob: 25ce3330d54072a6430d69daf55b2b6a3298b8f1 [file] [log] [blame]
Renato Botelho do Coutoead1e532019-10-31 13:31:07 -05001#!/usr/bin/env python3
Ole Troan72d87582019-05-10 12:01:10 +02002"""CLI functional tests"""
3
4import unittest
Paul Vinciguerrabfd7d292019-10-26 22:25:49 -04005
Ole Troan4376ab22021-03-03 10:40:05 +01006from vpp_papi import VPPIOError
Paul Vinciguerrabfd7d292019-10-26 22:25:49 -04007
Dave Wallace8800f732023-08-31 00:47:44 -04008from asfframework import VppAsfTestCase, VppTestRunner
Ole Troan72d87582019-05-10 12:01:10 +02009
10
Dave Wallace8800f732023-08-31 00:47:44 -040011class TestCLI(VppAsfTestCase):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020012 """CLI Test Case"""
13
Ole Troan72d87582019-05-10 12:01:10 +020014 maxDiff = None
15
16 @classmethod
17 def setUpClass(cls):
Paul Vinciguerrabfd7d292019-10-26 22:25:49 -040018 # using the framework default
Paul Vinciguerrae2ccdf02019-12-02 13:40:33 -050019 cls.vapi_response_timeout = 5
Ole Troan72d87582019-05-10 12:01:10 +020020 super(TestCLI, cls).setUpClass()
21
22 @classmethod
23 def tearDownClass(cls):
24 super(TestCLI, cls).tearDownClass()
25
26 def setUp(self):
27 super(TestCLI, self).setUp()
28
29 def tearDown(self):
30 super(TestCLI, self).tearDown()
31
32 def test_cli_retval(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020033 """CLI inband retval"""
34 rv = self.vapi.papi.cli_inband(cmd="this command does not exist")
Ole Troan72d87582019-05-10 12:01:10 +020035 self.assertNotEqual(rv.retval, 0)
36
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020037 rv = self.vapi.papi.cli_inband(cmd="show version")
Ole Troan72d87582019-05-10 12:01:10 +020038 self.assertEqual(rv.retval, 0)
39
Paul Vinciguerrabfd7d292019-10-26 22:25:49 -040040 def test_long_cli_delay(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020041 """Test that VppApiClient raises VppIOError if timeout.""" # noqa
Ole Troan4376ab22021-03-03 10:40:05 +010042 with self.assertRaises(VPPIOError) as ctx:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020043 rv = self.vapi.papi.cli_inband(cmd="wait 10")
Paul Vinciguerrabfd7d292019-10-26 22:25:49 -040044
Paul Vinciguerrae2ccdf02019-12-02 13:40:33 -050045 def test_long_cli_delay_override(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020046 """Test per-command _timeout option.""" # noqa
47 rv = self.vapi.papi.cli_inband(cmd="wait 10", _timeout=15)
Paul Vinciguerrae2ccdf02019-12-02 13:40:33 -050048 self.assertEqual(rv.retval, 0)
49
Paul Vinciguerrabfd7d292019-10-26 22:25:49 -040050
Dave Wallace8800f732023-08-31 00:47:44 -040051class TestCLIExtendedVapiTimeout(VppAsfTestCase):
Paul Vinciguerrabfd7d292019-10-26 22:25:49 -040052 maxDiff = None
53
54 @classmethod
55 def setUpClass(cls):
56 cls.vapi_response_timeout = 15
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020057 cls.__doc__ = (
58 " CLI Test Case w/ Extended (%ssec) Vapi Timeout "
59 % cls.vapi_response_timeout
60 )
Paul Vinciguerrabfd7d292019-10-26 22:25:49 -040061 super(TestCLIExtendedVapiTimeout, cls).setUpClass()
62
63 @classmethod
64 def tearDownClass(cls):
65 super(TestCLIExtendedVapiTimeout, cls).tearDownClass()
66
67 def setUp(self):
68 super(TestCLIExtendedVapiTimeout, self).setUp()
69
70 def tearDown(self):
71 super(TestCLIExtendedVapiTimeout, self).tearDown()
72
73 def test_long_cli_delay(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020074 """Test that delayed result returns with extended timeout."""
Paul Vinciguerrabfd7d292019-10-26 22:25:49 -040075 wait_secs = self.vapi_response_timeout - 1
76
77 # get vpp time as float
78 start = self.vapi.papi.show_vpe_system_time(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020079 _no_type_conversion=True
80 ).vpe_system_time
81 rv = self.vapi.papi.cli_inband(cmd="wait %s" % wait_secs)
Paul Vinciguerrabfd7d292019-10-26 22:25:49 -040082 now = self.vapi.papi.show_vpe_system_time(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020083 _no_type_conversion=True
84 ).vpe_system_time
Paul Vinciguerrabfd7d292019-10-26 22:25:49 -040085
86 # assume that the overhead of the measurement is not more that .5 sec.
87 self.assertEqual(round(now - start), wait_secs)
88
Ole Troan72d87582019-05-10 12:01:10 +020089
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020090if __name__ == "__main__":
Ole Troan72d87582019-05-10 12:01:10 +020091 unittest.main(testRunner=VppTestRunner)