2 """CLI functional tests"""
6 from vpp_papi import VPPIOError
8 from asfframework import VppAsfTestCase, VppTestRunner
11 class TestCLI(VppAsfTestCase):
18 # using the framework default
19 cls.vapi_response_timeout = 5
20 super(TestCLI, cls).setUpClass()
23 def tearDownClass(cls):
24 super(TestCLI, cls).tearDownClass()
27 super(TestCLI, self).setUp()
30 super(TestCLI, self).tearDown()
32 def test_cli_retval(self):
33 """CLI inband retval"""
34 rv = self.vapi.papi.cli_inband(cmd="this command does not exist")
35 self.assertNotEqual(rv.retval, 0)
37 rv = self.vapi.papi.cli_inband(cmd="show version")
38 self.assertEqual(rv.retval, 0)
40 def test_long_cli_delay(self):
41 """Test that VppApiClient raises VppIOError if timeout.""" # noqa
42 with self.assertRaises(VPPIOError) as ctx:
43 rv = self.vapi.papi.cli_inband(cmd="wait 10")
45 def test_long_cli_delay_override(self):
46 """Test per-command _timeout option.""" # noqa
47 rv = self.vapi.papi.cli_inband(cmd="wait 10", _timeout=15)
48 self.assertEqual(rv.retval, 0)
51 class TestCLIExtendedVapiTimeout(VppAsfTestCase):
56 cls.vapi_response_timeout = 15
58 " CLI Test Case w/ Extended (%ssec) Vapi Timeout "
59 % cls.vapi_response_timeout
61 super(TestCLIExtendedVapiTimeout, cls).setUpClass()
64 def tearDownClass(cls):
65 super(TestCLIExtendedVapiTimeout, cls).tearDownClass()
68 super(TestCLIExtendedVapiTimeout, self).setUp()
71 super(TestCLIExtendedVapiTimeout, self).tearDown()
73 def test_long_cli_delay(self):
74 """Test that delayed result returns with extended timeout."""
75 wait_secs = self.vapi_response_timeout - 1
77 # get vpp time as float
78 start = self.vapi.papi.show_vpe_system_time(
79 _no_type_conversion=True
81 rv = self.vapi.papi.cli_inband(cmd="wait %s" % wait_secs)
82 now = self.vapi.papi.show_vpe_system_time(
83 _no_type_conversion=True
86 # assume that the overhead of the measurement is not more that .5 sec.
87 self.assertEqual(round(now - start), wait_secs)
90 if __name__ == "__main__":
91 unittest.main(testRunner=VppTestRunner)