Esempio n. 1
0
File: shell.py Progetto: saimen/tbot
def selftest_tc_shell_copy(
    lab: typing.Optional[linux.LabHost] = None, ) -> None:
    """Test ``shell.copy``."""
    def do_test(a: linux.Path, b: linux.Path, msg: str) -> None:
        if b.exists():
            b.host.exec0("rm", b)
        a.host.exec0("echo", msg, stdout=a)

        shell.copy(a, b)

        out = b.host.exec0("cat", b).strip()
        assert out == msg, repr(out) + " != " + repr(msg)

    with lab or tbot.acquire_lab() as lh:
        tbot.log.message("Test copying a file on the same host ...")
        do_test(
            lh.workdir / ".selftest-copy-local1",
            lh.workdir / ".selftest-copy-local2",
            "Copy locally",
        )

        if minisshd.check_minisshd(lh):
            with minisshd.minisshd(lh) as ssh:
                tbot.log.message(
                    "Test downloading a file from an ssh host ...")
                do_test(
                    ssh.workdir / ".selftest-copy-ssh1",
                    lh.workdir / ".selftest-copy-ssh2",
                    "Download via SCP",
                )

                tbot.log.message("Test uploading a file to an ssh host ...")
                do_test(
                    lh.workdir / ".selftest-copy-ssh1",
                    ssh.workdir / ".selftest-copy-ssh2",
                    "Upload via SCP",
                )

                with minisshd.MiniSSHLabHost(ssh.port) as sl:
                    tbot.log.message(
                        "Test downloading a file from an ssh lab ...")
                    do_test(
                        sl.workdir / ".selftest-copy-ssh4",
                        lh.workdir / ".selftest-copy-ssh3",
                        "Download via SCP Lab",
                    )

                    tbot.log.message("Test uploading a file to an ssh lab ...")
                    do_test(
                        lh.workdir / ".selftest-copy-ssh3",
                        sl.workdir / ".selftest-copy-ssh4",
                        "Upload via SCP Lab",
                    )
        else:
            tbot.log.message(tbot.log.c("Skip").yellow.bold + " ssh tests.")
Esempio n. 2
0
def selftest_machine_ssh_shell(
    lab: typing.Optional[selftest.SelftestHost] = None, ) -> None:
    """Test an SSH shell."""
    from tbot.tc.selftest import minisshd

    with lab or selftest.SelftestHost() as lh:
        if not minisshd.check_minisshd(lh):
            tbot.skip("dropbear is not installed so ssh can't be tested")

        with minisshd.minisshd(lh) as ssh:
            selftest_machine_shell(ssh)
Esempio n. 3
0
def selftest_machine_ssh_shell(lab: typing.Optional[linux.LabHost] = None,) -> None:
    """Test an SSH shell."""
    from tbot.tc.selftest import minisshd

    with lab or tbot.acquire_lab() as lh:
        if minisshd.check_minisshd(lh):
            with minisshd.minisshd(lh) as ssh:
                selftest_machine_shell(ssh)

                selftest_machine_channel(ssh._obtain_channel(), True)
        else:
            tbot.log.message(tbot.log.c("Skip").yellow.bold + " ssh tests.")
Esempio n. 4
0
def selftest_machine_sshlab_shell(lab: typing.Optional[linux.LabHost] = None,) -> None:
    """Test an SSH LabHost shell."""
    from tbot.tc.selftest import minisshd

    with lab or tbot.acquire_lab() as lh:
        if minisshd.check_minisshd(lh):
            with minisshd.minisshd(lh) as ssh:
                ssh.exec0("true")

                with minisshd.MiniSSHLabHost(ssh.port) as sl:
                    selftest_machine_shell(sl)
        else:
            tbot.log.message(tbot.log.c("Skip").yellow.bold + " ssh tests.")
Esempio n. 5
0
def selftest_machine_ssh_shell(
    lab: typing.Optional[linux.Lab] = None, ) -> None:
    """Test an SSH shell."""
    from tbot.tc.selftest import minisshd

    with lab or tbot.acquire_lab() as lh:
        if not minisshd.check_minisshd(lh):
            tbot.skip("dropbear is not installed so ssh can't be tested")

        with minisshd.minisshd(lh) as ssh:
            selftest_machine_shell(ssh)

            selftest_machine_channel(ssh.ch, True)
Esempio n. 6
0
File: machine.py Progetto: zkrx/tbot
def selftest_machine_sshlab_shell(
    lab: typing.Optional[selftest.SelftestHost] = None, ) -> None:
    """Test an SSH LabHost shell."""
    from tbot.tc.selftest import minisshd

    with lab or selftest.SelftestHost() as lh:
        if not minisshd.check_minisshd(lh):
            tbot.skip("dropbear is not installed so ssh can't be tested")

        with minisshd.minisshd(lh) as ssh:
            ssh.exec0("true")

            tbot.log.message(tbot.log.c("Testing with paramiko ...").bold)
            with minisshd.MiniSSHLabHostParamiko(ssh.port) as slp:
                selftest_machine_shell(slp)

            tbot.log.message(tbot.log.c("Testing with plain ssh ...").bold)
            with minisshd.MiniSSHLabHostSSH(ssh.port) as sls:
                selftest_machine_shell(sls)
Esempio n. 7
0
def selftest_tc_shell_copy(
        lab: typing.Optional[selftest.SelftestHost] = None) -> None:
    """Test ``shell.copy``."""
    def do_test(a: linux.Path, b: linux.Path, msg: str) -> None:
        if b.exists():
            b.host.exec0("rm", b)
        a.host.exec0("echo", msg, linux.RedirStdout(a))

        shell.copy(a, b)

        out = b.host.exec0("cat", b).strip()
        assert out == msg, repr(out) + " != " + repr(msg)

    with lab or selftest.SelftestHost() as lh:
        tbot.log.message("Test copying a file on the same host ...")
        do_test(
            lh.workdir / ".selftest-copy-local1",
            lh.workdir / ".selftest-copy-local2",
            "Copy locally",
        )

        if minisshd.check_minisshd(lh):
            with minisshd.minisshd(lh) as ssh:
                tbot.log.message(
                    "Test downloading a file from an ssh host ...")
                do_test(
                    ssh.workdir / ".selftest-copy-ssh1",
                    lh.workdir / ".selftest-copy-ssh2",
                    "Download via SCP",
                )

                tbot.log.message("Test uploading a file to an ssh host ...")
                do_test(
                    lh.workdir / ".selftest-copy-ssh1",
                    ssh.workdir / ".selftest-copy-ssh2",
                    "Upload via SCP",
                )

                if not minisshd.has_paramiko:
                    tbot.log.warning("Skipping paramiko test.")
                else:
                    with minisshd.MiniSSHLabHostParamiko(ssh.port) as slp:
                        tbot.log.message(
                            "Test downloading a file from a paramiko ssh host ..."
                        )
                        do_test(
                            slp.workdir / ".selftest-copy-ssh4",
                            lh.workdir / ".selftest-copy-ssh3",
                            "Download via SCP Lab",
                        )

                        tbot.log.message(
                            "Test uploading a file to a paramiko ssh host ...")
                        do_test(
                            lh.workdir / ".selftest-copy-ssh3",
                            slp.workdir / ".selftest-copy-ssh4",
                            "Upload via SCP Lab",
                        )

                with minisshd.MiniSSHLabHostSSH(ssh.port) as sls:
                    tbot.log.message(
                        "Test downloading a file from a plain ssh host ...")
                    do_test(
                        sls.workdir / ".selftest-copy-ssh6",
                        lh.workdir / ".selftest-copy-ssh5",
                        "Download via SCP Lab",
                    )

                    tbot.log.message(
                        "Test uploading a file to a plain ssh host ...")
                    do_test(
                        lh.workdir / ".selftest-copy-ssh5",
                        sls.workdir / ".selftest-copy-ssh6",
                        "Upload via SCP Lab",
                    )
        else:
            tbot.log.message(tbot.log.c("Skip").yellow.bold + " ssh tests.")