Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closing of SSH connection to board over Labhost from the board in interactive session lands you on the Labhost #42

Closed
cmhe opened this issue Dec 9, 2020 · 1 comment
Labels
bad-behavior tbot incorrectly handles a certain situation. bug A bug in tbot has-workaround This issue can temporarily be fixed by a hack/workaround

Comments

@cmhe
Copy link
Contributor

cmhe commented Dec 9, 2020

I have this setup:

Lab:

import contextlib
import tbot
from tbot.machine import connector, linux


class StartBashInitializer(tbot.machine.Initializer):
    @contextlib.contextmanager
    def _init_machine(self):
        linux.util.wait_for_shell(self.ch)
        self.ch.sendline("bash --norc --noprofile")
        yield None


class Fuji(
    connector.ParamikoConnector,
    StartBashInitializer,
    linux.Bash,
    linux.Lab,
):
    hostname = "fuji.lan"
    username = "ch"

    @property
    def workdir(self):
        return linux.Workdir.static(self,
                                    f"/home/{self.username}/work/tbot-workdir")


def register_machines(ctx: tbot.Context) -> None:
    ctx.register(Fuji, tbot.role.LabHost)

Board:

import tbot
import contextlib
import time

from tbot.machine import connector, linux


class BoardLinux(connector.SSHConnector, linux.Bash):
    name = "board"
    hostname = "user"
    username = "root"

    @classmethod
    @contextlib.contextmanager
    def from_context(cls, ctx: tbot.Context):
        with tbot.ctx() as cx:
            lh = cx.request(tbot.role.LabHost)
            lo = cx.request(tbot.role.LocalHost)

            try:
                tbot.log.message("Power board on")
                lo.exec0("curl", "http://tasmota-0061.lan/cm?cmnd=Power%20On")

                tbot.log.message("Waiting for connection...")
                while not lh.test("timeout", "5", "ssh", BoardLinux.hostname, "true"):
                    tbot.log.message("still waiting ...")

                with cls(lh) as m:
                    yield m
            finally:
                tbot.log.message("Power board off")
                lo.exec0("curl", "http://tasmota-0061.lan/cm?cmnd=Power%20Off")


def register_machines(ctx: tbot.Context) -> None:
    ctx.register(BoardLinux, tbot.role.BoardLinux)

Starting a interactive session with the interactive_linux and closing the connection on the board via for instance a reboot command. Will drop me to the LabHost (fuji).

I use the current master commit: 0be8d7e of tbot

@Rahix Rahix added bad-behavior tbot incorrectly handles a certain situation. bug A bug in tbot labels Dec 9, 2020
@Rahix
Copy link
Owner

Rahix commented Jan 19, 2021

I think this should be resolvable by this change:

 class StartBashInitializer(tbot.machine.Initializer):
     @contextlib.contextmanager
     def _init_machine(self):
         linux.util.wait_for_shell(self.ch)
-        self.ch.sendline("bash --norc --noprofile")
+        self.ch.sendline("bash --norc --noprofile; exit")
         yield None

@Rahix Rahix added the has-workaround This issue can temporarily be fixed by a hack/workaround label Feb 23, 2021
@Rahix Rahix closed this as completed May 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bad-behavior tbot incorrectly handles a certain situation. bug A bug in tbot has-workaround This issue can temporarily be fixed by a hack/workaround
Projects
None yet
Development

No branches or pull requests

2 participants