Skip to content
Snippets Groups Projects
Verified Commit 84e6788e authored by Karel Koci's avatar Karel Koci :metal:
Browse files

nsfarm/cli: fix function pexpect_flush

It turns out that nonblocking doesn't mean nonblocking in all cases. In
this case when there was no input the read was blocking.
The timeout set to zero solves this.
parent b2a9f818
Branches
1 merge request!6nsfarm/cli: fix function pexpect_flush
...@@ -82,7 +82,7 @@ class Board(abc.ABC): ...@@ -82,7 +82,7 @@ class Board(abc.ABC):
# Wait for bootup # Wait for bootup
self._pexpect.expect_exact(["Router Turris successfully started.", ], timeout=120) self._pexpect.expect_exact(["Router Turris successfully started.", ], timeout=120)
# Note Shell sends new line which opens terminal for it # Note Shell sends new line which opens terminal for it
shell = cli.Shell(self._pexpect, flush=False) # TODO why this flush timeouts? shell = cli.Shell(self._pexpect)
shell.run("sysctl -w kernel.printk='0 4 1 7'") # disable kernel print to not confuse console flow shell.run("sysctl -w kernel.printk='0 4 1 7'") # disable kernel print to not confuse console flow
return shell return shell
......
...@@ -18,6 +18,7 @@ import select ...@@ -18,6 +18,7 @@ import select
import socket import socket
import threading import threading
import typing import typing
import pexpect
_FLUSH_BUFFLEN = 2048 _FLUSH_BUFFLEN = 2048
...@@ -25,9 +26,14 @@ _FLUSH_BUFFLEN = 2048 ...@@ -25,9 +26,14 @@ _FLUSH_BUFFLEN = 2048
def pexpect_flush(pexpect_handle): def pexpect_flush(pexpect_handle):
"""Flush all input on pexpect. This effectively reads everything. """Flush all input on pexpect. This effectively reads everything.
""" """
# TODO fix: this timeouts if there is nothing to flush # The read_nonblocking blocks when there is not at least one byte available for read (yeah you are reading it right
while len(pexpect_handle.read_nonblocking(_FLUSH_BUFFLEN)) == _FLUSH_BUFFLEN: # the nonblocking read is blocking). The solution here is to use timeout with zero value. This raises timeout
pass # exception immediately once there is no input available.
while True:
try:
pexpect_handle.read_nonblocking(io.DEFAULT_BUFFER_SIZE, 0)
except pexpect.TIMEOUT:
return
def run_exit_code_zero(exit_code): def run_exit_code_zero(exit_code):
......
  • Karel Koci :metal: @kkoci

    mentioned in commit 510ed9bffaab63f397694cc82cded7bd10abff8b

    ·

    mentioned in commit 510ed9bffaab63f397694cc82cded7bd10abff8b

    Toggle commit list
  • Karel Koci :metal: @kkoci

    mentioned in commit abb4ae8b

    ·

    mentioned in commit abb4ae8b

    Toggle commit list
  • Karel Koci :metal: @kkoci

    mentioned in commit 38077ba8

    ·

    mentioned in commit 38077ba8

    Toggle commit list
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment