Exemple #1
0
def stop_stress_cpu(user: str):
    """Stops commands stressing the CPU.

        :param user: User with a running stress command.

    """
    with paramiko_connect(user=user) as ssh:
        ssh.exec_command("killall stress")
Exemple #2
0
def clear_home(user: str):
    """Clears the user's home directory.

        Removes the `.ssh` dir.

        :param user: User, whose home directory should be cleared.

    """
    with paramiko_connect(user=user) as ssh:
        ssh.exec_command(command="rm -rf ~/.ssh")
def test_pull_environment_from_location_in_env_var():
    user = USER_31
    with paramiko_connect(user) as ssh:
        ssh.exec_command("echo '{bashrc_contents}' > ~/.bashrc".format(
            bashrc_contents=BASHRC_CONTENTS_WITH_IDACT_CONFIG_PATH_SET))

    remote_environment_upload_path = '~/.idact-custom-config'
    remote_environment_pull_path = None
    check_able_to_pull_environment(
        user=user,
        remote_environment_upload_path=remote_environment_upload_path,
        remote_environment_pull_path=remote_environment_pull_path)
Exemple #4
0
def start_stress_cpu(user: str, timeout: int = 10):
    """Runs a remote command that stresses the CPU, with a timeout.

        :param user: User to run stress as.

        :param timeout: Stress timeout.

    """
    with paramiko_connect(user=user) as ssh:
        ssh.exec_command("nohup stress --cpu 1 --timeout {timeout} &".format(
            timeout=timeout))
        sleep(STARTUP_TIME)
def clear_deployment_sync_data(user: str):
    """Clears the deployment sync data from user directory.

        :param user: User, whose home directory should be cleared.

    """
    try:
        yield
    finally:
        with paramiko_connect(user=user) as ssh:
            ssh.exec_command(command="rm -f {}/{}".format(
                DEPLOYMENT_DEFINITIONS_PATH, DEPLOYMENT_DEFINITIONS_FILENAME))
Exemple #6
0
def remove_remote_file(user: str, path: str):
    """A context manager that removes a remote file on exit.

        :param user: User to connect as.

        :param path: Remote file path to remove.

    """
    try:
        yield
    finally:
        with paramiko_connect(user=user) as ssh:
            ssh.exec_command(command="rm -f {path} || exit 0".format(
                path=path))
Exemple #7
0
def run_dummy_server(user: str,
                     server_port: int,
                     timeout: float):
    """Runs a simple HTTP server on the testing container as the given user.

        :param user: User to run the server as.

        :param server_port: Remote server port.

        :param timeout: Time to run the server for in seconds.

    """
    with paramiko_connect(user=user) as ssh:
        try:
            ssh.exec_command(
                "python -m SimpleHTTPServer {server_port}".format(
                    server_port=server_port))
            sleep(timeout)
        finally:
            ssh.exec_command("kill"
                             " `ps -U $USER"
                             " | grep python"
                             " | awk '{ print $1 }'`")