コード例 #1
0
def test_input():
    message = "test_input_string"
    sess = ssh.Session()
    sess.open(SSH_HOST, auth=(SSH_USER, SSH_PASS))
    sess.send("bash")
    response = sess.send(
        "read -p \"test_input:\" TEST_INPUT && echo $TEST_INPUT",
        prompt=r'test_input:',
        input=message)

    assert response.splitlines()[-1] == message
コード例 #2
0
    def _reload(dut, save: bool = False, waitfor: int = 900):
        session = ssh.Session()
        session.open(dut.host, auth=dut.auth)
        if save:
            session.send('write')

        try:
            session.send('reload now')
            while session.alive:
                pass
        except ssh.SshSessionClosedException:
            pass
        except pexpect.EOF:
            pass

        time.sleep(30)

        session.close()

        if waitfor > 0:
            t0 = time.time()
            while True:
                try:
                    session.open(dut.host, auth=dut.auth)
                    while True:

                        line = "show logging last 5 minutes"
                        output = session.send(line)
                        if "SYSTEM_RESTARTED" in output:
                            sys.stdout.write("!\n")
                            sys.stdout.flush()
                            return

                        sys.stdout.write("?")
                        sys.stdout.flush()

                        if int(time.time() - t0) >= waitfor:
                            raise ValueError("Timeout exceeded")

                        time.sleep(5)

                except pexpect.EOF:
                    pass
                except pexpect.TIMEOUT:
                    pass
                except ssh.SshSessionClosedException:
                    pass

                sys.stdout.write(".")
                sys.stdout.flush()

                if int(time.time() - t0) >= waitfor:
                    raise ValueError("Timeout exceeded")
コード例 #3
0
ファイル: session.py プロジェクト: arista-northwest/shakedown
    def install(self, hostaddr, auth=None, secret="root"):
        """Installs the root user"""

        if not auth:
            auth = DEFAULT_SSH_AUTH

        sess = ssh.Session()
        sess.open(hostaddr, auth=auth)
        sess.send("configure")
        sess.send("aaa root secret %s" % secret)
        sess.send("end")
        sess.close()
コード例 #4
0
def test_reopen():
    sess = ssh.Session()
    sess.open(SSH_HOST, auth=("root", SSH_ROOT_PASS))
    sess.send("uname -a")
    sess.reopen()
    sess.send("uname -a")
コード例 #5
0
def test_ssh():
    sess = ssh.Session()
    sess.open(SSH_HOST, auth=(SSH_USER, SSH_PASS))

    sess.send("show version")
コード例 #6
0
 def _get_version_ssh(dut):
     session = ssh.Session()
     session.open(dut.host, auth=dut.auth)
     return session.send("show version")
コード例 #7
0
ファイル: session.py プロジェクト: arista-northwest/shakedown
 def __init__(self):
     self._session = ssh.Session()
     self._opener = None