Beispiel #1
0
def test_terminal_cmd_whoami_during_ping(terminal_connection):
    terminal = terminal_connection
    cmd_whoami = Whoami(connection=terminal)
    cmd_ping = Ping(connection=terminal, destination="127.0.0.1", options='-c 3')
    cmd_ping.start(timeout=3)
    cmd_whoami.start(timeout=5)
    ret_whoami = cmd_whoami.await_done(timeout=5)
    assert 'USER' in ret_whoami
    assert ret_whoami['USER'] is not None
    assert getpass.getuser() == ret_whoami['USER']
    ret_ping = cmd_ping.result()
    assert 'packets_transmitted' in ret_ping
    assert 3 == int(ret_ping['packets_transmitted'])
    assert 'packet_loss' in ret_ping
    assert 0 == int(ret_ping['packet_loss'])
Beispiel #2
0
def test_timeout_before_command_sent(buffer_connection,
                                     command_output_and_expected_result_ping):
    from moler.cmd.unix.uptime import Uptime
    from moler.cmd.unix.ping import Ping
    command_output, expected_result = command_output_and_expected_result_ping
    ping_cmd = Ping(connection=buffer_connection.moler_connection,
                    prompt="host:.*#",
                    destination="localhost",
                    options="-w 5")
    uptime_cmd = Uptime(connection=buffer_connection.moler_connection,
                        prompt="host:.*#")
    ping_cmd.start(timeout=2)
    time.sleep(0.05)
    buffer_connection.moler_connection.data_received(
        command_output[0].encode("utf-8"), datetime.datetime.now())
    with pytest.raises(CommandTimeout):
        uptime_cmd(timeout=0.2)
    buffer_connection.moler_connection.data_received(
        command_output[1].encode("utf-8"), datetime.datetime.now())
    ping_cmd.await_done(timeout=0.2)
    ping_ret = ping_cmd.result()
    assert ping_ret == expected_result