Beispiel #1
0
def test_two_commands_uptime_whoami(
        buffer_connection, command_output_and_expected_result_uptime_whoami):
    from moler.cmd.unix.uptime import Uptime
    from moler.cmd.unix.whoami import Whoami
    command_output, expected_result = command_output_and_expected_result_uptime_whoami
    uptime_cmd = Uptime(connection=buffer_connection.moler_connection)
    whoami_cmd = Whoami(connection=buffer_connection.moler_connection)
    uptime_cmd.start(timeout=2)
    time.sleep(0.005)
    whoami_cmd.start(timeout=2)
    time.sleep(0.05)
    assert CommandScheduler.is_waiting_for_execution(
        connection_observer=whoami_cmd) is True
    buffer_connection.moler_connection.data_received(
        command_output[0].encode("utf-8"), datetime.datetime.now())
    time.sleep(0.2)
    buffer_connection.moler_connection.data_received(
        command_output[1].encode("utf-8"), datetime.datetime.now())
    assert EventAwaiter.wait_for_all(timeout=2,
                                     events=[uptime_cmd, whoami_cmd]) is True
    ret_uptime = uptime_cmd.result()
    ret_whoami = whoami_cmd.result()
    assert ret_uptime == expected_result[0]
    assert ret_whoami == expected_result[1]
    assert CommandScheduler.is_waiting_for_execution(
        connection_observer=whoami_cmd) is False
Beispiel #2
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'])