2 """CLI functional tests"""
8 from vpp_papi import VPPIOError
10 from framework import VppTestCase, VppTestRunner
13 class TestCLI(VppTestCase):
19 # using the framework default
20 cls.vapi_response_timeout = 5
21 super(TestCLI, cls).setUpClass()
24 def tearDownClass(cls):
25 super(TestCLI, cls).tearDownClass()
28 super(TestCLI, self).setUp()
31 super(TestCLI, self).tearDown()
33 def test_cli_retval(self):
34 """ CLI inband retval """
35 rv = self.vapi.papi.cli_inband(cmd='this command does not exist')
36 self.assertNotEqual(rv.retval, 0)
38 rv = self.vapi.papi.cli_inband(cmd='show version')
39 self.assertEqual(rv.retval, 0)
41 def test_long_cli_delay(self):
42 """ Test that VppApiClient raises VppIOError if timeout.""" # noqa
43 with self.assertRaises(VPPIOError) as ctx:
44 rv = self.vapi.papi.cli_inband(cmd='wait 10')
46 def test_long_cli_delay_override(self):
47 """ Test per-command _timeout option.""" # noqa
48 rv = self.vapi.papi.cli_inband(cmd='wait 10', _timeout=15)
49 self.assertEqual(rv.retval, 0)
52 class TestCLIExtendedVapiTimeout(VppTestCase):
57 cls.vapi_response_timeout = 15
58 cls.__doc__ = " CLI Test Case w/ Extended (%ssec) Vapi Timeout " \
59 % cls.vapi_response_timeout
60 super(TestCLIExtendedVapiTimeout, cls).setUpClass()
63 def tearDownClass(cls):
64 super(TestCLIExtendedVapiTimeout, cls).tearDownClass()
67 super(TestCLIExtendedVapiTimeout, self).setUp()
70 super(TestCLIExtendedVapiTimeout, self).tearDown()
72 def test_long_cli_delay(self):
73 """ Test that delayed result returns with extended timeout."""
74 wait_secs = self.vapi_response_timeout - 1
76 # get vpp time as float
77 start = self.vapi.papi.show_vpe_system_time(
78 _no_type_conversion=True).vpe_system_time
79 rv = self.vapi.papi.cli_inband(cmd='wait %s' % wait_secs)
80 now = self.vapi.papi.show_vpe_system_time(
81 _no_type_conversion=True).vpe_system_time
83 # assume that the overhead of the measurement is not more that .5 sec.
84 self.assertEqual(round(now - start), wait_secs)
87 if __name__ == '__main__':
88 unittest.main(testRunner=VppTestRunner)