Exemple #1
0
    def wait(self, exec_spec, command, user_stdout, user_stderr, check_exit_code, timeout):
        super(_YtExecutor, self).wait(check_exit_code=True)

        def local_path(name):
            return exec_spec['output_data'][exec_spec[name]]

        if user_stdout is not False:
            with open(local_path('stdout')) as afile:
                self._std_out = afile.read()

        if user_stderr is not False:
            with open(local_path('stderr')) as afile:
                self._std_err = afile.read()

        self._command = command

        with open(local_path('meta')) as afile:
            meta = json.load(afile)

        self._elapsed = meta['elapsed']
        self._metrics = meta['metrics']
        self._exit_code = meta['exit_code']

        self._set_metrics(meta)

        if meta['timeout']:
            raise ytc.ExecutionTimeoutError(self, "{} second(s) wait timeout has expired".format(timeout))

        # if rc != 0 and check_exit_code - _finalise will print stderr and stdout
        if not check_exit_code or self._exit_code == 0:
            logger.debug("Command over YT output:\n%s", ytc.process.truncate(self._std_out, ytc.process.MAX_OUT_LEN))
            logger.debug("Command over YT errors:\n%s", ytc.process.truncate(self._std_err, ytc.process.MAX_OUT_LEN))

        self._finalise(check_exit_code)
Exemple #2
0
def _patch_result(result, exec_spec, command, user_stdout, user_stderr,
                  check_exit_code, timeout):
    def local_path(name):
        return exec_spec['output_data'][exec_spec[name]]

    if user_stdout is not False:
        with open(local_path('stdout')) as afile:
            result._std_out = afile.read()

    if user_stderr is not False:
        with open(local_path('stderr')) as afile:
            result._std_err = afile.read()

    result._command = command

    with open(local_path('meta')) as afile:
        meta = json.load(afile)

    result._elapsed = meta['elapsed']
    result._metrics = meta['metrics']
    result._exit_code = meta['exit_code']

    import pytest
    # set global yt-execute's machinery metrics
    ya_inst = pytest.config.ya
    for k, v in meta.get('yt_metrics', {}).iteritems():
        ya_inst.set_metric_value(k, v + ya_inst.get_metric_value(k, default=0))
    # increase global call counter
    ya_inst.set_metric_value(
        'yt_execute_call_count',
        ya_inst.get_metric_value('yt_execute_call_count', default=0) + 1)

    if meta['timeout']:
        raise ytc.ExecutionTimeoutError(
            result, "{} second(s) wait timeout has expired".format(timeout))

    # if rc != 0 and check_exit_code - _finalise will print stderr and stdout
    if not check_exit_code or result._exit_code == 0:
        logger.debug(
            "Command over YT output:\n%s",
            ytc.process.truncate(result._std_out, ytc.process.MAX_OUT_LEN))
        logger.debug(
            "Command over YT errors:\n%s",
            ytc.process.truncate(result._std_err, ytc.process.MAX_OUT_LEN))

    result._finalise(check_exit_code)