Renato Botelho do Couto | ead1e53 | 2019-10-31 13:31:07 -0500 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Ole Troan | 72d8758 | 2019-05-10 12:01:10 +0200 | [diff] [blame] | 2 | """CLI functional tests""" |
| 3 | |
Paul Vinciguerra | bfd7d29 | 2019-10-26 22:25:49 -0400 | [diff] [blame] | 4 | import datetime |
| 5 | import time |
Ole Troan | 72d8758 | 2019-05-10 12:01:10 +0200 | [diff] [blame] | 6 | import unittest |
Paul Vinciguerra | bfd7d29 | 2019-10-26 22:25:49 -0400 | [diff] [blame] | 7 | |
Ole Troan | 4376ab2 | 2021-03-03 10:40:05 +0100 | [diff] [blame] | 8 | from vpp_papi import VPPIOError |
Paul Vinciguerra | bfd7d29 | 2019-10-26 22:25:49 -0400 | [diff] [blame] | 9 | |
Ole Troan | 72d8758 | 2019-05-10 12:01:10 +0200 | [diff] [blame] | 10 | from framework import VppTestCase, VppTestRunner |
| 11 | |
| 12 | |
| 13 | class TestCLI(VppTestCase): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 14 | """CLI Test Case""" |
| 15 | |
Ole Troan | 72d8758 | 2019-05-10 12:01:10 +0200 | [diff] [blame] | 16 | maxDiff = None |
| 17 | |
| 18 | @classmethod |
| 19 | def setUpClass(cls): |
Paul Vinciguerra | bfd7d29 | 2019-10-26 22:25:49 -0400 | [diff] [blame] | 20 | # using the framework default |
Paul Vinciguerra | e2ccdf0 | 2019-12-02 13:40:33 -0500 | [diff] [blame] | 21 | cls.vapi_response_timeout = 5 |
Ole Troan | 72d8758 | 2019-05-10 12:01:10 +0200 | [diff] [blame] | 22 | 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 Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 35 | """CLI inband retval""" |
| 36 | rv = self.vapi.papi.cli_inband(cmd="this command does not exist") |
Ole Troan | 72d8758 | 2019-05-10 12:01:10 +0200 | [diff] [blame] | 37 | self.assertNotEqual(rv.retval, 0) |
| 38 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 39 | rv = self.vapi.papi.cli_inband(cmd="show version") |
Ole Troan | 72d8758 | 2019-05-10 12:01:10 +0200 | [diff] [blame] | 40 | self.assertEqual(rv.retval, 0) |
| 41 | |
Paul Vinciguerra | bfd7d29 | 2019-10-26 22:25:49 -0400 | [diff] [blame] | 42 | def test_long_cli_delay(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 43 | """Test that VppApiClient raises VppIOError if timeout.""" # noqa |
Ole Troan | 4376ab2 | 2021-03-03 10:40:05 +0100 | [diff] [blame] | 44 | with self.assertRaises(VPPIOError) as ctx: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 45 | rv = self.vapi.papi.cli_inband(cmd="wait 10") |
Paul Vinciguerra | bfd7d29 | 2019-10-26 22:25:49 -0400 | [diff] [blame] | 46 | |
Paul Vinciguerra | e2ccdf0 | 2019-12-02 13:40:33 -0500 | [diff] [blame] | 47 | def test_long_cli_delay_override(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 48 | """Test per-command _timeout option.""" # noqa |
| 49 | rv = self.vapi.papi.cli_inband(cmd="wait 10", _timeout=15) |
Paul Vinciguerra | e2ccdf0 | 2019-12-02 13:40:33 -0500 | [diff] [blame] | 50 | self.assertEqual(rv.retval, 0) |
| 51 | |
Paul Vinciguerra | bfd7d29 | 2019-10-26 22:25:49 -0400 | [diff] [blame] | 52 | |
| 53 | class TestCLIExtendedVapiTimeout(VppTestCase): |
| 54 | maxDiff = None |
| 55 | |
| 56 | @classmethod |
| 57 | def setUpClass(cls): |
| 58 | cls.vapi_response_timeout = 15 |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 59 | cls.__doc__ = ( |
| 60 | " CLI Test Case w/ Extended (%ssec) Vapi Timeout " |
| 61 | % cls.vapi_response_timeout |
| 62 | ) |
Paul Vinciguerra | bfd7d29 | 2019-10-26 22:25:49 -0400 | [diff] [blame] | 63 | 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 Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 76 | """Test that delayed result returns with extended timeout.""" |
Paul Vinciguerra | bfd7d29 | 2019-10-26 22:25:49 -0400 | [diff] [blame] | 77 | wait_secs = self.vapi_response_timeout - 1 |
| 78 | |
| 79 | # get vpp time as float |
| 80 | start = self.vapi.papi.show_vpe_system_time( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 81 | _no_type_conversion=True |
| 82 | ).vpe_system_time |
| 83 | rv = self.vapi.papi.cli_inband(cmd="wait %s" % wait_secs) |
Paul Vinciguerra | bfd7d29 | 2019-10-26 22:25:49 -0400 | [diff] [blame] | 84 | now = self.vapi.papi.show_vpe_system_time( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 85 | _no_type_conversion=True |
| 86 | ).vpe_system_time |
Paul Vinciguerra | bfd7d29 | 2019-10-26 22:25:49 -0400 | [diff] [blame] | 87 | |
| 88 | # assume that the overhead of the measurement is not more that .5 sec. |
| 89 | self.assertEqual(round(now - start), wait_secs) |
| 90 | |
Ole Troan | 72d8758 | 2019-05-10 12:01:10 +0200 | [diff] [blame] | 91 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 92 | if __name__ == "__main__": |
Ole Troan | 72d8758 | 2019-05-10 12:01:10 +0200 | [diff] [blame] | 93 | unittest.main(testRunner=VppTestRunner) |