blob: 808497f63d08dde68905f6ae11a310c5d31fa703 [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
Paul Vinciguerrabfd7d292019-10-26 22:25:49 -04004import datetime
5import time
Ole Troan72d87582019-05-10 12:01:10 +02006import unittest
Paul Vinciguerrabfd7d292019-10-26 22:25:49 -04007
Ole Troan4376ab22021-03-03 10:40:05 +01008from vpp_papi import VPPIOError
Paul Vinciguerrabfd7d292019-10-26 22:25:49 -04009
Pratikshya Prasai657bdf72022-08-18 11:09:38 -040010from asfframework import VppTestCase, VppTestRunner
Ole Troan72d87582019-05-10 12:01:10 +020011
12
13class TestCLI(VppTestCase):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020014 """CLI Test Case"""
15
Ole Troan72d87582019-05-10 12:01:10 +020016 maxDiff = None
17
18 @classmethod
19 def setUpClass(cls):
Paul Vinciguerrabfd7d292019-10-26 22:25:49 -040020 # using the framework default
Paul Vinciguerrae2ccdf02019-12-02 13:40:33 -050021 cls.vapi_response_timeout = 5
Ole Troan72d87582019-05-10 12:01:10 +020022 super(TestCLI, cls).setUpClass()
23
24 @classmethod
25 def tearDownClass(cls):
26 super(TestCLI, cls).tearDownClass()
27
28 def setUp(self):
29 super(TestCLI, self).setUp()
30
31 def tearDown(self):
32 super(TestCLI, self).tearDown()
33
34 def test_cli_retval(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020035 """CLI inband retval"""
36 rv = self.vapi.papi.cli_inband(cmd="this command does not exist")
Ole Troan72d87582019-05-10 12:01:10 +020037 self.assertNotEqual(rv.retval, 0)
38
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020039 rv = self.vapi.papi.cli_inband(cmd="show version")
Ole Troan72d87582019-05-10 12:01:10 +020040 self.assertEqual(rv.retval, 0)
41
Paul Vinciguerrabfd7d292019-10-26 22:25:49 -040042 def test_long_cli_delay(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020043 """Test that VppApiClient raises VppIOError if timeout.""" # noqa
Ole Troan4376ab22021-03-03 10:40:05 +010044 with self.assertRaises(VPPIOError) as ctx:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020045 rv = self.vapi.papi.cli_inband(cmd="wait 10")
Paul Vinciguerrabfd7d292019-10-26 22:25:49 -040046
Paul Vinciguerrae2ccdf02019-12-02 13:40:33 -050047 def test_long_cli_delay_override(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020048 """Test per-command _timeout option.""" # noqa
49 rv = self.vapi.papi.cli_inband(cmd="wait 10", _timeout=15)
Paul Vinciguerrae2ccdf02019-12-02 13:40:33 -050050 self.assertEqual(rv.retval, 0)
51
Paul Vinciguerrabfd7d292019-10-26 22:25:49 -040052
53class TestCLIExtendedVapiTimeout(VppTestCase):
54 maxDiff = None
55
56 @classmethod
57 def setUpClass(cls):
58 cls.vapi_response_timeout = 15
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020059 cls.__doc__ = (
60 " CLI Test Case w/ Extended (%ssec) Vapi Timeout "
61 % cls.vapi_response_timeout
62 )
Paul Vinciguerrabfd7d292019-10-26 22:25:49 -040063 super(TestCLIExtendedVapiTimeout, cls).setUpClass()
64
65 @classmethod
66 def tearDownClass(cls):
67 super(TestCLIExtendedVapiTimeout, cls).tearDownClass()
68
69 def setUp(self):
70 super(TestCLIExtendedVapiTimeout, self).setUp()
71
72 def tearDown(self):
73 super(TestCLIExtendedVapiTimeout, self).tearDown()
74
75 def test_long_cli_delay(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020076 """Test that delayed result returns with extended timeout."""
Paul Vinciguerrabfd7d292019-10-26 22:25:49 -040077 wait_secs = self.vapi_response_timeout - 1
78
79 # get vpp time as float
80 start = self.vapi.papi.show_vpe_system_time(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020081 _no_type_conversion=True
82 ).vpe_system_time
83 rv = self.vapi.papi.cli_inband(cmd="wait %s" % wait_secs)
Paul Vinciguerrabfd7d292019-10-26 22:25:49 -040084 now = self.vapi.papi.show_vpe_system_time(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020085 _no_type_conversion=True
86 ).vpe_system_time
Paul Vinciguerrabfd7d292019-10-26 22:25:49 -040087
88 # assume that the overhead of the measurement is not more that .5 sec.
89 self.assertEqual(round(now - start), wait_secs)
90
Ole Troan72d87582019-05-10 12:01:10 +020091
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020092if __name__ == "__main__":
Ole Troan72d87582019-05-10 12:01:10 +020093 unittest.main(testRunner=VppTestRunner)