vty: log failed vty command

Add a log label argument to f_vty_wait_for_prompt(), and feed the sent
command from f_vty_transceive*(), so that the failure verdict already
lists the vty command that caused the failure.

A common error is to issue insufficient 'exit' commands, so that I often
think the newly added VTY command failed, even though it is a subsequent
command causing the failure. I want to shorten the "time-to-aha" there.

Change-Id: Icfd739db150d86e9256a224f12dc979dcd77879f
This commit is contained in:
Neels Hofmeyr 2020-11-25 22:56:13 +00:00
parent c897cfb6e6
commit 9ebabc8b0e
1 changed files with 6 additions and 6 deletions

View File

@ -56,7 +56,7 @@ module Osmocom_VTY_Functions {
}
/* wait for any of the permitted prompts; buffer + return all intermediate output */
function f_vty_wait_for_prompt(TELNETasp_PT pt, boolean strict := true) return charstring {
function f_vty_wait_for_prompt(TELNETasp_PT pt, boolean strict := true, charstring log_label := "(?)") return charstring {
var charstring rx, buf := "";
var integer fd;
timer T := 2.0;
@ -68,10 +68,10 @@ module Osmocom_VTY_Functions {
[] pt.receive(pattern "[\w-]+\(*\)\# ") { };
[] pt.receive(t_vty_unknown) -> value rx {
if (strict) {
setverdict(fail, "VTY: Unknown Command");
setverdict(fail, "VTY: Unknown Command: " & log_label);
mtc.stop;
} else {
log("VTY: Unknown Command (ignored)");
log("VTY: Unknown Command (ignored): " & log_label);
buf := buf & rx;
repeat;
}
@ -79,14 +79,14 @@ module Osmocom_VTY_Functions {
[] pt.receive(charstring:?) -> value rx { buf := buf & rx; repeat };
[] pt.receive(integer:?) -> value fd {
if (fd == -1) {
setverdict(fail, "VTY Telnet Connection Failure");
setverdict(fail, "VTY Telnet Connection Failure: " & log_label);
mtc.stop;
} else {
repeat; /* telnet connection succeeded */
}
}
[] T.timeout {
setverdict(fail, "VTY Timeout for prompt");
setverdict(fail, "VTY Timeout for prompt: " & log_label);
mtc.stop;
};
}
@ -97,7 +97,7 @@ module Osmocom_VTY_Functions {
/* send a VTY command and obtain response until prompt is received */
function f_vty_transceive_ret(TELNETasp_PT pt, charstring tx, boolean strict := true) return charstring {
pt.send(tx);
return f_vty_wait_for_prompt(pt, strict);
return f_vty_wait_for_prompt(pt, strict, tx);
}
/* send a VTY command and obtain response until prompt is received */