cli: Add return value in cli_inband
Even when a CLI command called through the cli_inband API failed the API would return 0 (SUCCESS). This patch fixes that, but since most CLI handlers return error->code == 0, in most failure cases it will return -1 (UNSPECIFIED ERROR). Type: fix Change-Id: Ic83f3b23e8e8954bb8aa211301baba24e8c20ef6 Signed-off-by: Ole Troan <ot@cisco.com>
This commit is contained in:

committed by
Paul Vinciguerra

parent
f89a6de8f0
commit
72d8758fdc
@ -684,7 +684,7 @@ vlib_unix_error_report (vlib_main_t * vm, clib_error_t * error)
|
||||
}
|
||||
|
||||
/* Process CLI input. */
|
||||
void
|
||||
int
|
||||
vlib_cli_input (vlib_main_t * vm,
|
||||
unformat_input_t * input,
|
||||
vlib_cli_output_function_t * function, uword function_arg)
|
||||
@ -694,6 +694,7 @@ vlib_cli_input (vlib_main_t * vm,
|
||||
clib_error_t *error;
|
||||
vlib_cli_output_function_t *save_function;
|
||||
uword save_function_arg;
|
||||
int rv = 0;
|
||||
|
||||
save_function = cp->output_function;
|
||||
save_function_arg = cp->output_function_arg;
|
||||
@ -713,11 +714,15 @@ vlib_cli_input (vlib_main_t * vm,
|
||||
{
|
||||
vlib_cli_output (vm, "%v", error->what);
|
||||
vlib_unix_error_report (vm, error);
|
||||
/* clib_error_return is unfortunately often called with a '0'
|
||||
return code */
|
||||
rv = error->code != 0 ? error->code : -1;
|
||||
clib_error_free (error);
|
||||
}
|
||||
|
||||
cp->output_function = save_function;
|
||||
cp->output_function_arg = save_function_arg;
|
||||
return rv;
|
||||
}
|
||||
|
||||
/* Output to current CLI connection. */
|
||||
|
@ -186,10 +186,10 @@ static __clib_unused vlib_cli_command_t __clib_unused_##x
|
||||
void vlib_cli_output (struct vlib_main_t *vm, char *fmt, ...);
|
||||
|
||||
/* Process CLI input. */
|
||||
void vlib_cli_input (struct vlib_main_t *vm,
|
||||
unformat_input_t * input,
|
||||
vlib_cli_output_function_t * function,
|
||||
uword function_arg);
|
||||
int vlib_cli_input (struct vlib_main_t *vm,
|
||||
unformat_input_t * input,
|
||||
vlib_cli_output_function_t * function,
|
||||
uword function_arg);
|
||||
|
||||
clib_error_t *vlib_cli_register (struct vlib_main_t *vm,
|
||||
vlib_cli_command_t * c);
|
||||
|
@ -226,7 +226,7 @@ vl_api_cli_inband_t_handler (vl_api_cli_inband_t * mp)
|
||||
|
||||
unformat_init_string (&input, (char *) vl_api_from_api_string (&mp->cmd),
|
||||
vl_api_string_len (&mp->cmd));
|
||||
vlib_cli_input (vm, &input, inband_cli_output, (uword) & out_vec);
|
||||
rv = vlib_cli_input (vm, &input, inband_cli_output, (uword) & out_vec);
|
||||
|
||||
len = vec_len (out_vec);
|
||||
|
||||
|
36
test/test_cli.py
Normal file
36
test/test_cli.py
Normal file
@ -0,0 +1,36 @@
|
||||
#!/usr/bin/env python
|
||||
"""CLI functional tests"""
|
||||
|
||||
import unittest
|
||||
from framework import VppTestCase, VppTestRunner
|
||||
|
||||
|
||||
class TestCLI(VppTestCase):
|
||||
""" CLI Test Case """
|
||||
maxDiff = None
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super(TestCLI, cls).setUpClass()
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
super(TestCLI, cls).tearDownClass()
|
||||
|
||||
def setUp(self):
|
||||
super(TestCLI, self).setUp()
|
||||
|
||||
def tearDown(self):
|
||||
super(TestCLI, self).tearDown()
|
||||
|
||||
def test_cli_retval(self):
|
||||
""" CLI inband retval """
|
||||
rv = self.vapi.papi.cli_inband(cmd='this command does not exist')
|
||||
self.assertNotEqual(rv.retval, 0)
|
||||
|
||||
rv = self.vapi.papi.cli_inband(cmd='show version')
|
||||
self.assertEqual(rv.retval, 0)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main(testRunner=VppTestRunner)
|
Reference in New Issue
Block a user