test.cmd_expect(): Add support for echo_cmd command line arg

Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
Jan Lindemann 2023-01-17 11:53:39 +01:00
commit 6da9e6af00

View file

@ -45,14 +45,14 @@ async def expect(conn, cmd=None, regex=None, subject=None, act_timeout=0.1, tota
return buf return buf
raise Exception("never reached") raise Exception("never reached")
async def cmd_expect(conn, cmd, subject=None, regex=None, log_act=None, act_timeout=0.1): # export async def cmd_expect(conn, cmd, subject=None, regex=None, log_act=None, act_timeout=0.1, echo_cmd=None): # export
slog(NOTICE, 'sending command "{}"'.format(str(cmd).rstrip("\n"))) slog(NOTICE, 'sending command "{}"'.format(str(cmd).rstrip("\n")))
res = await cmd_exec(conn, cmd) res = await cmd_exec(conn, cmd, echo_cmd=echo_cmd)
if not isinstance(res, list): if not isinstance(res, list):
msg = 'failed to send command over connection {}'.format(conn) msg = 'failed to send command over connection {}'.format(conn)
slog(ERR, 'FAIL: ' + msg) slog(ERR, 'FAIL: ' + msg)
return msg return msg
if expect(conn, regex=regex, subject=subject, act_timeout=act_timeout, log_act=log_act): if await expect(conn, regex=regex, subject=subject, act_timeout=act_timeout, log_act=log_act):
slog(NOTICE, 'PASS: found pattern "{}" in command output'.format(regex)) slog(NOTICE, 'PASS: found pattern "{}" in command output'.format(regex))
return None return None
r = "FAIL: failed to find {} in command output".format(regex) r = "FAIL: failed to find {} in command output".format(regex)