Exemple #1
0
def test_command_not_found(buffer_connection,
                           command_output_command_not_found):
    command_output = command_output_command_not_found
    buffer_connection.remote_inject_response([command_output])
    cmd_pwd = Pwd(connection=buffer_connection.moler_connection)
    cmd_sudo = Sudo(connection=buffer_connection.moler_connection,
                    password="******",
                    cmd_object=cmd_pwd)
    with pytest.raises(CommandFailure):
        cmd_sudo()
Exemple #2
0
def test_failing_with_timeout(buffer_connection,
                              command_output_and_expected_result_timeout):
    command_output = command_output_and_expected_result_timeout
    buffer_connection.remote_inject_response([command_output])
    cmd_pwd = Pwd(connection=buffer_connection.moler_connection)
    cmd_sudo = Sudo(connection=buffer_connection.moler_connection,
                    password="******",
                    cmd_object=cmd_pwd)
    with pytest.raises(CommandTimeout):
        cmd_sudo(timeout=0.1)
Exemple #3
0
def test_sudo_su_object(buffer_connection, command_output_and_expected_result_ls_l):
    from moler.cmd.unix.sudo import Sudo
    from moler.cmd.unix.ls import Ls
    command_output = command_output_and_expected_result_ls_l[0]
    expected_dict = command_output_and_expected_result_ls_l[1]
    buffer_connection.remote_inject_response([command_output])
    cmd_ls = Ls(connection=buffer_connection.moler_connection, options="-l")
    cmd_su = Su(connection=buffer_connection.moler_connection, cmd_object=cmd_ls)
    cmd_sudo = Sudo(connection=buffer_connection.moler_connection, cmd_object=cmd_su)
    ret = cmd_sudo()
    assert ret == expected_dict
Exemple #4
0
def test_failing_with_wrong_password(buffer_connection,
                                     command_output_password_fails):
    command_output = command_output_password_fails
    buffer_connection.remote_inject_response([command_output])
    cmd = Whoami(connection=buffer_connection.moler_connection)
    cmd_sudo = Sudo(connection=buffer_connection.moler_connection,
                    cmd_object=cmd,
                    password="******")
    with pytest.raises(CommandFailure):
        cmd_sudo(timeout=0.2)
    assert cmd_sudo._command_output_started is False
Exemple #5
0
def test_sudo_with_parameter_i(buffer_connection):
    command_output = """sudo -i
root@host#"""
    buffer_connection.remote_inject_response([command_output])
    cmd_sudo = Sudo(connection=buffer_connection.moler_connection,
                    password="******",
                    sudo_params='-i',
                    prompt="moler_bash#",
                    expected_prompt="root@host.*#")
    assert "sudo -i" == cmd_sudo.command_string
    cmd_sudo()
def test_failing_with_embedded_command_fails(buffer_connection,
                                             command_output_cp_fails):
    command_output = command_output_cp_fails
    buffer_connection.remote_inject_response([command_output])
    cmd_cp = Cp(connection=buffer_connection.moler_connection,
                src="src.txt",
                dst="dst.txt")
    cmd_sudo = Sudo(connection=buffer_connection.moler_connection,
                    password="******",
                    cmd_object=cmd_cp)
    with pytest.raises(CommandFailure):
        cmd_sudo()
def test_calling_by_command_object(buffer_connection,
                                   command_output_and_expected_result):
    command_output, expected_result = command_output_and_expected_result
    buffer_connection.remote_inject_response([command_output])

    cmd_pwd = Pwd(connection=buffer_connection.moler_connection)
    cmd_sudo = Sudo(connection=buffer_connection.moler_connection,
                    password="******",
                    cmd_object=cmd_pwd)
    assert "sudo pwd" == cmd_sudo.command_string
    result = cmd_sudo()
    assert result == expected_result
Exemple #8
0
def test_calling_by_command_class(buffer_connection,
                                  command_output_and_expected_result):
    command_output, expected_result = command_output_and_expected_result
    buffer_connection.remote_inject_response([command_output])

    cmd_sudo = Sudo(connection=buffer_connection.moler_connection,
                    password="******",
                    cmd_class_name="moler.cmd.unix.pwd.Pwd")
    assert "sudo pwd" == cmd_sudo.command_string
    result = cmd_sudo()
    assert "sudo pwd" == cmd_sudo.command_string
    assert result == expected_result
Exemple #9
0
def test_sudo_su(buffer_connection):
    from moler.cmd.unix.sudo import Sudo
    command_output = """sudo su -c 'pwd'
/home/auto/inv
moler_bash#"""
    expected_dict = {'full_path': '/home/auto/inv', 'path_to_current': '/home/auto', 'current_path': 'inv'}
    buffer_connection.remote_inject_response([command_output])
    cmd_su = Su(connection=buffer_connection.moler_connection, prompt=r"moler_bash#",
                cmd_class_name='moler.cmd.unix.pwd.Pwd')
    cmd_sudo = Sudo(connection=buffer_connection.moler_connection, cmd_object=cmd_su)
    ret = cmd_sudo()
    assert ret == expected_dict
Exemple #10
0
def test_calling_by_command_object_su(buffer_connection):
    command_output = """sudo su
root@host#"""
    buffer_connection.remote_inject_response([command_output])

    cmd_su = Su(connection=buffer_connection.moler_connection,
                expected_prompt="root@host.*#")
    cmd_sudo = Sudo(connection=buffer_connection.moler_connection,
                    cmd_object=cmd_su,
                    expected_prompt="root@host.*#")
    assert "sudo su" == cmd_sudo.command_string
    cmd_sudo()
def test_failing_with_both_parameters(buffer_connection,
                                      command_output_cp_fails):
    command_output = command_output_cp_fails
    buffer_connection.remote_inject_response([command_output])
    cmd_cp = Cp(connection=buffer_connection.moler_connection,
                src="src.txt",
                dst="dst.txt")
    cmd_sudo = Sudo(connection=buffer_connection.moler_connection,
                    cmd_class_name="moler.cmd.unix.cp.Cp",
                    cmd_object=cmd_cp,
                    password="******")
    with pytest.raises(CommandFailure):
        cmd_sudo()
Exemple #12
0
def test_failing_with_embedded_command_fails(buffer_connection,
                                             command_output_cp_fails):
    command_output = command_output_cp_fails
    buffer_connection.remote_inject_response([command_output])
    cmd_cp = Cp(connection=buffer_connection.moler_connection,
                src="src.txt",
                dst="dst.txt",
                prompt="ute@debdev:")
    cmd_sudo = Sudo(connection=buffer_connection.moler_connection,
                    password="******",
                    cmd_object=cmd_cp)
    with pytest.raises(CommandFailure):
        abc = cmd_sudo()
        print("abc '{}'".format(abc))
def test_no_parameters(buffer_connection):
    cmd_sudo = Sudo(connection=buffer_connection.moler_connection,
                    password="******")
    with pytest.raises(CommandFailure):
        cmd_sudo()