mirror of
ssh://git.janware.com/srv/git/janware/proj/jw-devtest
synced 2026-01-15 02:22:56 +01:00
test.expect(): Add support for Cmd class array
Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
parent
59b0c60aee
commit
9da6c3f31b
1 changed files with 25 additions and 6 deletions
|
|
@ -8,6 +8,15 @@ from ..misc import *
|
|||
from ..Connection import Connection
|
||||
from ..Connections import Connections
|
||||
|
||||
class Cmd: # export
|
||||
|
||||
def __init__(self, cmdline, expect = None, act_timeout = None, total_timeout = None, flags = 0x0):
|
||||
self.cmdline = cmdline
|
||||
self.expect = expect
|
||||
self.act_timeout = act_timeout
|
||||
self.total_timeout = total_timeout
|
||||
self.flags = flags
|
||||
|
||||
async def expect(conn, cmd=None, regex=None, subject=None, act_timeout=0.1, total_timeout=None, log_act=None): # export
|
||||
# regex is a keyword-argument so that other arguments to support other
|
||||
# checks can be added later
|
||||
|
|
@ -69,25 +78,35 @@ async def cmds_exec(console, cmds, log_act=None, echo_cmd=False): # export
|
|||
return False
|
||||
|
||||
for c in cmds:
|
||||
default_timeout = 2
|
||||
default_flags = 0x0
|
||||
if isinstance(c, Cmd):
|
||||
cmdline = c.cmdline
|
||||
act_timeout = default_timeout if c.act_timeout is None else c.act_timeout
|
||||
total_timeout = act_timeout if c.total_timeout is None else c.total_timeout
|
||||
flags = default_flags if c.flags is None else c.flags
|
||||
else:
|
||||
cmdline = c[0]
|
||||
e = None if len(c) < 2 else c[1]
|
||||
timeout = 200 if len(c) < 3 else c[2]
|
||||
act_timeout = 2 if len(c) < 3 else c[2]
|
||||
total_timeout = act_timeout if len(c) < 4 else c[3]
|
||||
flags = default_flags
|
||||
if cmdline is None:
|
||||
if e is None:
|
||||
continue
|
||||
slog(DEBUG, 'Waiting for: "{}"'.format(e))
|
||||
rr = await expect(console, regex=e, act_timeout=timeout)
|
||||
rr = await expect(console, regex=e, act_timeout=act_timeout, total_timeout=total_timeout)
|
||||
if rr is None:
|
||||
return 'Timed out waiting for: "{}"'.format(e)
|
||||
elif isinstance(cmdline, str):
|
||||
rr = await cmd_exec(console, cmdline, act_timeout=1, log_act=log_act, echo_cmd=echo_cmd)
|
||||
rr = await cmd_exec(console, cmdline, act_timeout=act_timeout, total_timeout=total_timeout, log_act=log_act, echo_cmd=echo_cmd)
|
||||
if rr is None:
|
||||
return 'Failed to run command "{}"'.format(cmdline)
|
||||
if e is not None:
|
||||
if find_match(rr, e):
|
||||
continue
|
||||
slog(DEBUG, 'Waiting for: "{}"'.format(e))
|
||||
rr = await expect(console, regex=e, act_timeout=timeout)
|
||||
rr = await expect(console, regex=e, act_timeout=act_timeout, total_timeout=total_timeout)
|
||||
if rr is None:
|
||||
return 'Timed out waiting for: "{}"'.format(e)
|
||||
else:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue