Ejemplo n.º 1
0
    def _execute(
        self,
        atc: ActionToCheck,
        env: InstructionEnvironmentForPostSdsStep,
    ):
        process_executor = ProcessExecutorForProgramExecutorWoStdinThatRaisesIfResultIsNotExitCode(
            env, self._arrangement.process_execution.os_services, atc,
            self._atc_exe_input(env))
        error_msg_extra_info = ''
        sub_process_result = None
        try:
            sub_process_result = capture_process_executor_result__wo_stdin(
                process_executor, env.sds.result.root_dir)
            step_result = new_eh_exit_code(sub_process_result.exitcode)
        except HardErrorResultError as ex:
            step_result = ex.result
            error_msg_extra_info = os.linesep + str(
                ex.failure_details) + os.linesep

        self._expectation.execute.apply(
            self._put, step_result,
            MessageBuilder('Result of execute' + error_msg_extra_info))
        if sub_process_result:
            msg_builder = MessageBuilder('Sub process output from execute ' +
                                         error_msg_extra_info)
            self._expectation_post_sds.sub_process_result_from_execute.apply(
                self._put, sub_process_result, msg_builder)

        self._expectation_post_sds.side_effects_on_files_after_execute.apply(
            self._put, env.sds)
        self._check_symbols_after(atc, phase_step.STEP__ACT__EXECUTE)
        self._expectation.after_execution.apply_with_message(
            self._put, env.tcds, 'after execution')
Ejemplo n.º 2
0
 def execute(self,
             environment: InstructionEnvironmentForPostSdsStep,
             os_process_executor: AtcOsProcessExecutor,
             script_output_dir_path: pathlib.Path,
             std_files: StdFiles) -> ExitCodeOrHardError:
     self.cwd_registerer.register_cwd_for(phase_step.ACT__EXECUTE)
     return new_eh_exit_code(0)
 def execute(self,
             command: Command,
             std_files: StdFiles,
             process_execution_settings: ProcessExecutionSettings) -> ExitCodeOrHardError:
     self.command = command
     self.process_execution_settings = process_execution_settings
     return new_eh_exit_code(0)
Ejemplo n.º 4
0
 def execute(
     self,
     environment: InstructionEnvironmentForPostSdsStep,
     os_services: OsServices,
     atc_input: AtcExecutionInput,
     output: StdOutputFiles,
 ) -> ExitCodeOrHardError:
     return new_eh_exit_code(self.exit_code)
Ejemplo n.º 5
0
 def execute(
     self,
     environment: InstructionEnvironmentForPostSdsStep,
     os_services: OsServices,
     atc_input: AtcExecutionInput,
     output_files: StdOutputFiles,
 ) -> ExitCodeOrHardError:
     self.cwd_registerer.register_cwd_for(phase_step.ACT__EXECUTE)
     return new_eh_exit_code(0)
Ejemplo n.º 6
0
 def execute(self,
             environment: InstructionEnvironmentForPostSdsStep,
             os_process_executor: AtcOsProcessExecutor,
             script_output_dir_path: pathlib.Path,
             std_files: StdFiles) -> ExitCodeOrHardError:
     exit_code = subprocess.call([sys.executable, str(self.python_program_file)],
                                 timeout=60,
                                 stdin=std_files.stdin,
                                 stdout=std_files.output.out,
                                 stderr=std_files.output.err)
     return new_eh_exit_code(exit_code)
Ejemplo n.º 7
0
 def execute(
     self,
     environment: InstructionEnvironmentForPostSdsStep,
     os_services: OsServices,
     atc_input: AtcExecutionInput,
     output: StdOutputFiles,
 ) -> ExitCodeOrHardError:
     settings = atc_proc_exe_settings.for_atc(environment, atc_input)
     try:
         exit_code = self._executor.execute(environment, settings,
                                            atc_input.stdin, output)
         return eh.new_eh_exit_code(exit_code)
     except HardErrorException as ex:
         return eh.new_eh_hard_error(FailureDetails.new_message(ex.error))
Ejemplo n.º 8
0
 def execute(
     self,
     environment: InstructionEnvironmentForPostSdsStep,
     os_services: OsServices,
     atc_input: AtcExecutionInput,
     output: StdOutputFiles,
 ) -> ExitCodeOrHardError:
     with as_stdin.of_optional(atc_input.stdin) as stdin_f:
         exit_code = subprocess.call(
             [sys.executable, str(self.python_program_file)],
             timeout=60,
             stdin=stdin_f,
             stdout=output.out,
             stderr=output.err)
         return new_eh_exit_code(exit_code)
Ejemplo n.º 9
0
    def execute(self,
                environment: InstructionEnvironmentForPostSdsStep,
                os_process_executor: AtcOsProcessExecutor,
                script_output_dir_path: pathlib.Path,
                std_files: StdFiles) -> ExitCodeOrHardError:
        python_file = pathlib.Path() / self.PYTHON_FILE_NAME
        with python_file.open(mode='w') as f:
            f.write(self.python_program_source)

        exit_code = subprocess.call([sys.executable, str(python_file)],
                                    timeout=60,
                                    stdin=std_files.stdin,
                                    stdout=std_files.output.out,
                                    stderr=std_files.output.err)
        return new_eh_exit_code(exit_code)
Ejemplo n.º 10
0
 def execute(self,
             environment: InstructionEnvironmentForPostSdsStep,
             os_services: OsServices,
             atc_input: AtcExecutionInput,
             output: StdOutputFiles,
             ) -> ExitCodeOrHardError:
     python_file = pathlib.Path() / self.PYTHON_FILE_NAME
     with python_file.open(mode='w') as f:
         f.write(self.python_program_source)
     with as_stdin.of_optional(atc_input.stdin) as stdin_f:
         exit_code = subprocess.call([sys.executable, str(python_file)],
                                     timeout=60,
                                     stdin=stdin_f,
                                     stdout=output.out,
                                     stderr=output.err)
     return new_eh_exit_code(exit_code)
Ejemplo n.º 11
0
 def execute(
     self,
     environment: InstructionEnvironmentForPostSdsStep,
     os_services: OsServices,
     atc_input: AtcExecutionInput,
     output: StdOutputFiles,
 ) -> ExitCodeOrHardError:
     resolving_environment = full_resolving_env_for_instruction_env(
         os_services, environment)
     try:
         command = self._make_command(resolving_environment)
         settings = atc_proc_exe_settings.for_atc(environment, atc_input)
         with std_files.of_optional_stdin(atc_input.stdin,
                                          output) as std_files_:
             exit_code = os_services.command_executor.execute(
                 command, settings, std_files_)
         return eh.new_eh_exit_code(exit_code)
     except HardErrorException as ex:
         return eh.new_eh_hard_error(FailureDetails.new_message(ex.error))
 def __init__(self, constant_return_value: ExitCodeOrHardError = new_eh_exit_code(0)):
     self.constant_return_value = constant_return_value
Ejemplo n.º 13
0
 def execute(self,
             environment: InstructionEnvironmentForPostSdsStep,
             os_process_executor: AtcOsProcessExecutor,
             script_output_dir_path: pathlib.Path,
             std_files: StdFiles) -> ExitCodeOrHardError:
     return new_eh_exit_code(self.exit_code)
Ejemplo n.º 14
0
def check_execution(put: unittest.TestCase,
                    actor: Actor,
                    act_phase_instructions: list,
                    arrangement: Arrangement,
                    expectation: Expectation) -> ExitCodeOrHardError:
    assert_is_list_of_act_phase_instructions(put, act_phase_instructions)
    with home_directory_structure(contents=arrangement.hds_contents) as hds:
        instruction_environment = InstructionEnvironmentForPreSdsStep(hds,
                                                                      arrangement.environ,
                                                                      arrangement.timeout_in_seconds,
                                                                      symbols=arrangement.symbol_table)
        sut = actor.parse(act_phase_instructions)
        expectation.symbol_usages.apply_with_message(put,
                                                     sut.symbol_usages(),
                                                     'symbol-usages after ' +
                                                     phase_step.STEP__ACT__PARSE)
        step_result = sut.validate_pre_sds(instruction_environment)
        expectation.result_of_validate_pre_sds.apply_with_message(put, step_result,
                                                                  'validate_pre_sds')
        if step_result.status is not svh.SuccessOrValidationErrorOrHardErrorEnum.SUCCESS:
            return None
        put.assertEqual(svh.SuccessOrValidationErrorOrHardErrorEnum.SUCCESS,
                        step_result.status,
                        'Result of ' + phase_step.STEP__VALIDATE_PRE_SDS)
        expectation.symbol_usages.apply_with_message(put,
                                                     sut.symbol_usages(),
                                                     'symbol-usages after ' +
                                                     phase_step.STEP__VALIDATE_PRE_SDS)
        with sds_with_act_as_curr_dir(symbols=instruction_environment.symbols
                                      ) as path_resolving_env:
            instruction_environment = InstructionEnvironmentForPostSdsStep(instruction_environment.hds,
                                                                           instruction_environment.environ,
                                                                           path_resolving_env.sds,
                                                                           phase_identifier.ACT.identifier,
                                                                           instruction_environment.timeout_in_seconds,
                                                                           symbols=arrangement.symbol_table)
            step_result = sut.validate_post_setup(instruction_environment)
            put.assertEqual(svh.SuccessOrValidationErrorOrHardErrorEnum.SUCCESS,
                            step_result.status,
                            'Result of validation/post-setup')
            expectation.symbol_usages.apply_with_message(put,
                                                         sut.symbol_usages(),
                                                         'symbol-usages after ' +
                                                         phase_step.STEP__VALIDATE_POST_SETUP)
            script_output_dir_path = path_resolving_env.sds.test_case_dir
            step_result = sut.prepare(instruction_environment,
                                      arrangement.atc_process_executor,
                                      script_output_dir_path)
            expectation.side_effects_on_files_after_prepare.apply(put, path_resolving_env.sds)
            expectation.result_of_prepare.apply(put,
                                                step_result,
                                                MessageBuilder('Result of prepare'))
            expectation.symbol_usages.apply_with_message(put,
                                                         sut.symbol_usages(),
                                                         'symbol-usages after ' +
                                                         phase_step.STEP__ACT__PREPARE)
            if not step_result.is_success:
                return

            process_executor = ProcessExecutorForProgramExecutorThatRaisesIfResultIsNotExitCode(
                instruction_environment,
                arrangement.atc_process_executor,
                script_output_dir_path,
                sut)
            error_msg_extra_info = ''
            sub_process_result = None
            try:
                sub_process_result = capture_process_executor_result(process_executor,
                                                                     path_resolving_env.sds.result.root_dir)
                step_result = new_eh_exit_code(sub_process_result.exitcode)
            except HardErrorResultError as ex:
                step_result = ex.result
                error_msg_extra_info = os.linesep + str(ex.failure_details) + os.linesep

            expectation.result_of_execute.apply(put,
                                                step_result,
                                                MessageBuilder('Result of execute' + error_msg_extra_info))
            if sub_process_result:
                msg_builder = MessageBuilder('Sub process output from execute' + error_msg_extra_info)
                expectation.sub_process_result_from_execute.apply(put, sub_process_result, msg_builder)
            expectation.side_effects_on_files_after_execute.apply(put, path_resolving_env.sds)
            expectation.symbol_usages.apply_with_message(put,
                                                         sut.symbol_usages(),
                                                         'symbol-usages after ' +
                                                         phase_step.STEP__ACT__EXECUTE)
            return step_result
Ejemplo n.º 15
0
 def f(*args, **kwargs) -> ExitCodeOrHardError:
     return new_eh_exit_code(exit_code)
Ejemplo n.º 16
0
 def execute(self,
             environment: InstructionEnvironmentForPostSdsStep,
             script_output_dir_path: pathlib.Path,
             std_files: StdFiles) -> eh.ExitCodeOrHardError:
     return eh.new_eh_exit_code(0)
Ejemplo n.º 17
0
 def _actor(self) -> Actor:
     return ActorThatRunsConstantActions(
         validate_post_setup_action=_RecordCurrDirAndReturn(self.recorder, phase_step.ACT__VALIDATE_POST_SETUP,
                                                            svh.new_svh_success()),
         execute_action=_RecordCurrDirAndReturn(self.recorder, phase_step.ACT__EXECUTE,
                                                new_eh_exit_code(0)))
Ejemplo n.º 18
0
 def _actor(self) -> Actor:
     return ActorThatRunsConstantActions(
         validate_post_setup_action=_RecordCurrDirAndReturn(self.recorder, phase_step.ACT__VALIDATE_POST_SETUP,
                                                            svh.new_svh_success()),
         execute_action=_RecordCurrDirAndReturn(self.recorder, phase_step.ACT__EXECUTE,
                                                new_eh_exit_code(0)))