Verified Commit 3c7282dd authored by Karel Koci's avatar Karel Koci 🤘
Browse files

nsfarm: allow and disable input read for serial console

This reason for this is that we use at some point serial console only to
get logs. We do not process it further. There is no reader for serial
console at most of time.
This change allows disable of serial console input and serial console
logs are thus only logged without further propagation.
parent 748f9db2
......@@ -31,6 +31,17 @@ class Board(abc.ABC):
"""
return self._pexpect
def set_serial_flush(self, flush: bool):
"""Enables/Disables serial data flush.
This disables data propagation in logging and flushes pexpect on disable. The effect is that output is only
logged without propagation to pexpect.
This is required as at some point we just use serial console for logs without reading it. In such case it is
just matter of time logger gets stuck as pipe toward pexpect gets filled. This prevents this from happening.
"""
self._fdlogging.set_propagation(not flush)
if flush:
cli.pexpect_flush(self._pexpect)
def power(self, state):
"""Set power state.
"""
......@@ -69,7 +80,7 @@ class Board(abc.ABC):
# Now load image from TFTP
with Container(lxd_connection, "boot", devices=[device_wan, ]) as cont:
ccli = cli.Shell(cont.pexpect())
ccli.run(f"prepare_turris_image {os_branch}")
ccli.run(f"prepare_turris_image '{os_branch}'")
uboot.run('setenv ipaddr 192.168.1.142')
uboot.run('setenv serverip 192.168.1.1')
self._board_bootup(uboot)
......
......@@ -235,6 +235,7 @@ class FDLogging:
self._out_level = out_level
self._fileno = fileno if isinstance(fileno, int) else fileno.fileno()
self._our_sock, self._user_sock = socket.socketpair()
self._propagate = True
self._orig_filestatus = fcntl.fcntl(self._fileno, fcntl.F_GETFL)
fcntl.fcntl(self._fileno, fcntl.F_SETFL, self._orig_filestatus | os.O_NONBLOCK)
......@@ -249,6 +250,12 @@ class FDLogging:
"""
return self._user_sock
def set_propagation(self, propagate: bool):
"""Configures if input should be propagated to socket or not. Output is still propagated to file but input read
from file is simply logged and dropped.
"""
self._propagate = propagate
def close(self):
"""Close socket and stop logging.
"""
......@@ -299,7 +306,8 @@ class FDLogging:
if event == select.POLLNVAL:
return
new_data = os.read(fileno, io.DEFAULT_BUFFER_SIZE)
os.write(output[fileno], new_data)
if fileno != self._fileno or self._propagate:
os.write(output[fileno], new_data)
data[fileno] = self._log(data[fileno], new_data, level[fileno])
......
......@@ -137,7 +137,7 @@ def fixture_board_root_password(request, board_serial):
@pytest.fixture(name="client_board", scope="module")
def fixture_client_board(board_serial, board_root_password, lan1_client):
def fixture_client_board(board, board_serial, board_root_password, lan1_client):
"""Starts client on LAN1 and connect to board using SSH.
Provides instance of nsfarm.cli.Shell() connected to board shell using SSH trough client container.
......@@ -145,6 +145,8 @@ def fixture_client_board(board_serial, board_root_password, lan1_client):
"""
# Let's have syslog on serial console as well as kernel log
board_serial.command('while ! [ -f /var/log/messages ]; do sleep 1; done && tail -f /var/log/messages')
board.set_serial_flush(True)
# Now spawn client container and connect
nsfarm.cli.Shell(lan1_client.pexpect()).run('wait4network')
pexp = lan1_client.pexpect(['ssh', '-q', '192.168.1.1'])
......@@ -152,6 +154,8 @@ def fixture_client_board(board_serial, board_root_password, lan1_client):
pexp.sendline(board_root_password)
pexp.expect_exact("root@turris:")
yield nsfarm.cli.Shell(pexp, flush=False) # TODO drop this flush disable when it works
board.set_serial_flush(False)
# Kill tail -f on serial console
board_serial.send('\x03')
board_serial.prompt()
......
Supports Markdown
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