コード例 #1
0
def test_user_script_error_raised(run_entry_point, training_env):
    output = 'Not \'gloo::EnforceNotMet\' exception.'
    run_entry_point.side_effect = errors.ExecuteUserScriptError(
        cmd='Command "/usr/bin/python -m userscript"',
        output=output.encode('latin1') if six.PY3 else output)
    with pytest.raises(errors.ExecuteUserScriptError):
        train(training_env)
コード例 #2
0
def test_execute_user_script_error():
    error = errors.ExecuteUserScriptError(["python", "-m", "42"],
                                          return_code=42)

    assert (str(error) ==
            'ExecuteUserScriptError:\nExitCode 42\nErrorMessage ""\nCommand'
            " \"['python', '-m', '42']\"")
コード例 #3
0
def test_gloo_exception_intercepted(run_entry_point, training_env):
    output = 'terminate called after throwing an instance of \'gloo::EnforceNotMet\''
    run_entry_point.side_effect = errors.ExecuteUserScriptError(
        cmd='Command "/usr/bin/python -m userscript"',
        output=output.encode('latin1') if six.PY3 else output)
    train(training_env)
    run_entry_point.assert_called()
コード例 #4
0
def test_execute_user_script_error_with_output():
    error = errors.ExecuteUserScriptError(["python", "-m", "42"],
                                          return_code=137,
                                          output=b"42")

    assert (str(error) ==
            'ExecuteUserScriptError:\nExitCode 137\nErrorMessage "42"\nCommand'
            " \"['python', '-m', '42']\"")
コード例 #5
0
def test_execute_user_script_error_with_output():
    error = errors.ExecuteUserScriptError(["python", "-m", "42"],
                                          return_code=42,
                                          output=b"42")

    assert (str(error) == """ExecuteUserScriptError:
Command "['python', '-m', '42']"
42""")
コード例 #6
0
def test_execute_user_script_error_with_output_and_info():
    error = errors.ExecuteUserScriptError(["python", "-m", "42"],
                                          return_code=137,
                                          output="42",
                                          info="SIGKILL")

    assert (
        str(error) == "ExecuteUserScriptError:\nExitCode 137\nErrorMessage"
        " \"42\"\nExtraInfo \"SIGKILL\"\nCommand \"['python', '-m', '42']\"")
コード例 #7
0
def create(
    cmd,
    error_classes,
    processes_per_host,
    cwd=None,
    env=None,
    capture_error=False,
    **kwargs,
):
    """Spawn a process with asyncio for the given command.

    Args:
        cmd (list): The command to be run.
        error_classes (list): List of exception classes to watch and raise.
        cwd (str): The location from which to run the command (default: None).
            If None, this defaults to the ``code_dir`` of the environment.
        env: os.environ
        capture_error (bool): Whether or not to direct stderr to a stream
            that can later be read (default: False).
        **kwargs: Extra arguments that are passed to the asyncio create subprocess constructor.

    Returns:
        asyncio.subprocess.Process: The asyncio process for the given command.

    Raises:
        ExecuteUserScriptError: If there is an exception raised when creating the process.
    """
    try:
        stderr = PIPE if capture_error else None
        rc, output, proc = asyncio.run(
            run_async(
                cmd,
                processes_per_host,
                env=env or os.environ,
                cwd=cwd or environment.code_dir,
                stderr=stderr,
                error_classes=error_classes,
                **kwargs,
            ))
        return rc, output, proc
    except Exception as e:  # pylint: disable=broad-except
        six.reraise(
            errors.ExecuteUserScriptError,
            errors.ExecuteUserScriptError(e),
            sys.exc_info()[2],
        )
コード例 #8
0
def test_execute_user_script_error():
    error = errors.ExecuteUserScriptError(["python", "-m", "42"],
                                          return_code=42)

    assert str(
        error) == "ExecuteUserScriptError:\nCommand \"['python', '-m', '42']\""