예제 #1
0
 def _validate_uid_gids(self, uid, gids, kubernetes_uid=None):
     """Check whether container UID and GIDs are valid."""
     if WORKFLOW_RUNTIME_USER_GID not in gids:
         if kubernetes_uid is None:
             raise EnvironmentValidationError(
                 "Environment image GID must be {}. GIDs {} were found.".
                 format(WORKFLOW_RUNTIME_USER_GID, gids))
         else:
             self.messages.append({
                 "type":
                 "warning",
                 "message":
                 "Environment image GID is recommended to be {}. GIDs {} were found."
                 .format(WORKFLOW_RUNTIME_USER_GID, gids),
             })
     if kubernetes_uid is not None:
         if kubernetes_uid != uid:
             self.messages.append({
                 "type":
                 "warning",
                 "message":
                 "`kubernetes_uid` set to {}. UID {} was found.".format(
                     kubernetes_uid, uid),
             })
     elif uid != WORKFLOW_RUNTIME_USER_UID:
         self.messages.append({
             "type":
             "info",
             "message":
             "Environment image uses UID {} but will run as UID {}.".format(
                 uid, WORKFLOW_RUNTIME_USER_UID),
         })
예제 #2
0
    def _image_exists(self, image, tag):
        """Verify if image exists locally or remotely.

        :returns: A tuple with two boolean values: image exists locally, image exists remotely.
        """

        image_exists_remotely = (self._image_exists_in_gitlab_cern if
                                 image.startswith(GITLAB_CERN_REGISTRY_PREFIX)
                                 else self._image_exists_in_dockerhub)

        exists_locally = self._image_exists_locally(image, tag)
        exists_remotely = image_exists_remotely(image, tag)

        if not any([exists_locally, exists_remotely]):
            raise EnvironmentValidationError(
                "Environment image {} does not exist locally or remotely.".
                format(self._get_full_image_name(image, tag)))
        return exists_locally, exists_remotely
예제 #3
0
    def validate_environment(self):
        """Validate environments in REANA yadage workflow."""
        def _check_environment(environment):
            image = "{}{}".format(
                environment["image"],
                ":{}".format(environment["imagetag"])
                if "imagetag" in environment else "",
            )
            k8s_uid = next(
                (resource["kubernetes_uid"]
                 for resource in environment.get("resources", [])
                 if "kubernetes_uid" in resource),
                None,
            )
            self._validate_environment_image(image, kubernetes_uid=k8s_uid)

        steps_environments = self._extract_steps_environments()
        for environment in steps_environments:
            if environment["environment_type"] != "docker-encapsulated":
                raise EnvironmentValidationError(
                    'The only Yadage environment type supported is "docker-encapsulated". Found "{}".'
                    .format(environment["environment_type"]))
            else:
                _check_environment(environment)
예제 #4
0
    def _validate_image_tag(self, image):
        """Validate if image tag is valid."""
        image_name, image_tag = "", ""
        message = {
            "type":
            "success",
            "message":
            "Environment image {} has the correct format.".format(image),
        }
        if ":" in image:
            environment = image.split(":", 1)
            image_name, image_tag = environment[0], environment[-1]
            if ":" in image_tag:
                raise EnvironmentValidationError(
                    "Environment image {} has invalid tag '{}'".format(
                        image_name, image_tag))
            elif image_tag in ENVIRONMENT_IMAGE_SUSPECTED_TAGS_VALIDATOR:
                message = {
                    "type":
                    "warning",
                    "message":
                    "Using '{}' tag is not recommended in {} environment image."
                    .format(image_tag, image_name),
                }
        else:
            message = {
                "type":
                "warning",
                "message":
                "Environment image {} does not have an explicit tag.".format(
                    image),
            }
            image_name = image

        self.messages.append(message)
        return image_name, image_tag