Пример #1
0
    def wrapper(self, *args, **kwargs):  # pylint: disable=too-many-statements
        valid_paths = {}
        invalid_paths = {}
        validation_errors = []
        # NOTE: we need to access binaries to get paths and resolvers, before validating.
        for binary, binary_checker in self.binaries.items():
            invalid_paths[binary] = []
            try:
                exec_paths = (binary_checker.resolver.exec_paths
                              if not binary_checker.path_provided else
                              binary_checker.binary_path)
            except ValueError as ex:
                raise WorkflowFailedError(workflow_name=self.NAME,
                                          action_name="Resolver",
                                          reason=str(ex))
            for executable_path in exec_paths:
                try:
                    valid_path = binary_checker.validator.validate(
                        executable_path)
                    if valid_path:
                        valid_paths[binary] = valid_path
                except MisMatchRuntimeError as ex:
                    LOG.debug("Invalid executable for %s at %s",
                              binary,
                              executable_path,
                              exc_info=str(ex))
                    invalid_paths[binary].append(executable_path)

                except RuntimeValidatorError as ex:
                    LOG.debug("Runtime validation error for %s",
                              binary,
                              exc_info=str(ex))
                    if str(ex) not in validation_errors:
                        validation_errors.append(str(ex))

                if valid_paths.get(binary, None):
                    binary_checker.binary_path = valid_paths[binary]
                    break
        if validation_errors:
            raise WorkflowFailedError(workflow_name=self.NAME,
                                      action_name="Validation",
                                      reason="\n".join(validation_errors))

        if len(self.binaries) != len(valid_paths):
            validation_failed_binaries = set(self.binaries.keys()).difference(
                valid_paths.keys())
            for validation_failed_binary in validation_failed_binaries:
                message = "Binary validation failed for {0}, searched for {0} in following locations  : {1} which did not satisfy constraints for runtime: {2}. Do you have {0} for runtime: {2} on your PATH?".format(
                    validation_failed_binary,
                    invalid_paths[validation_failed_binary], self.runtime)
                validation_errors.append(message)
            raise WorkflowFailedError(workflow_name=self.NAME,
                                      action_name="Validation",
                                      reason="\n".join(validation_errors))
        func(self, *args, **kwargs)
Пример #2
0
 def wrapper(self, *args, **kwargs):
     valid_paths = []
     # NOTE: we need to access binaries to get paths and resolvers, before validating.
     binaries_copy = self.binaries
     for binary, binary_path in binaries_copy.items():
         validator = binary_path.validator
         exec_paths = binary_path.resolver.exec_paths if not binary_path.path_provided else binary_path.binary_path
         for executable_path in exec_paths:
             valid_path = None
             try:
                 valid_path = validator.validate(executable_path)
             except MisMatchRuntimeError as ex:
                 LOG.debug("Invalid executable for %s at %s",
                           binary,
                           executable_path,
                           exc_info=str(ex))
             if valid_path:
                 binary_path.binary_path = valid_path
                 valid_paths.append(valid_path)
                 break
     self.binaries = binaries_copy
     if len(self.binaries) != len(valid_paths):
         raise WorkflowFailedError(workflow_name=self.NAME,
                                   action_name=None,
                                   reason='Binary validation failed!')
     func(self, *args, **kwargs)
Пример #3
0
    def run(self):
        """
        Actually perform the build by executing registered actions.

        :raises WorkflowFailedError: If the workflow does not contain any actions or if one of the actions ran into
            an error

        :raises WorkflowUnknownError: If one of the actions in the workflow raised an unhandled exception
        """

        LOG.debug("Running workflow '%s'", self.NAME)

        if not self.actions:
            raise WorkflowFailedError(
                workflow_name=self.NAME,
                action_name=None,
                reason="Workflow does not have any actions registered")

        for action in self.actions:
            action_info = "{}:{}".format(self.NAME, action.NAME)

            LOG.info("Running %s", action_info)

            try:
                action.execute()

                LOG.debug("%s succeeded", action_info)

            except ActionFailedError as ex:
                LOG.debug("%s failed", action_info, exc_info=ex)

                raise WorkflowFailedError(workflow_name=self.NAME,
                                          action_name=action.NAME,
                                          reason=str(ex))
            except Exception as ex:

                LOG.debug("%s raised unhandled exception",
                          action_info,
                          exc_info=ex)

                raise WorkflowUnknownError(workflow_name=self.NAME,
                                           action_name=action.NAME,
                                           reason=str(ex))