예제 #1
0
    def _check_for_name_collisions(self):
        """Ensures all names that map to environment variables are unique, and throws a
        :class:`job.seed.exceptions.InvalidInterfaceDefinition` if they are not unique.

        Per Seed specification for implementors we must validate that all reserved keywords, settings
        and inputs are unique as they are ultimately injected as environment variables.
        """

        # Include reserved keywords
        env_vars = ["OUTPUT_DIR"]

        env_vars += [
            normalize_env_var_name(setting['name'])
            for setting in self.get_settings()
        ]
        env_vars += [
            normalize_env_var_name(input_file['name'])
            for input_file in self.get_input_files()
        ]
        env_vars += [
            normalize_env_var_name(json['name'])
            for json in self.get_input_json()
        ]
        env_vars += [
            normalize_env_var_name('ALLOCATED_' + resource['name'])
            for resource in self.get_scalar_resources()
        ]

        if len(env_vars) != len(set(env_vars)):
            raise InvalidSeedManifestDefinition(
                'NAME_COLLISION_ERROR',
                'Collisions are not allowed between reserved keywords, resources, settings'
                'and input names.')
예제 #2
0
    def __init__(self, definition, do_validate=True):
        """Creates a seed interface from the given definition. If the definition is invalid, a
        :class:`job.seed.exceptions.InvalidInterfaceDefinition` exception will be thrown.

        :param definition: The interface definition
        :type definition: dict
        :param do_validate: Whether to perform validation on the JSON schema
        :type do_validate: bool
        """

        self.definition = definition

        try:
            if do_validate:
                validate(definition, SEED_MANIFEST_SCHEMA)
        except ValidationError as validation_error:
            raise InvalidSeedManifestDefinition(
                'JSON_VALIDATION_ERROR',
                'Error validating against schema: %s' % validation_error)

        self._populate_default_values()

        self._check_for_name_collisions()
        self._check_mount_name_uniqueness()

        self._validate_mount_paths()
예제 #3
0
파일: manifest.py 프로젝트: SteveAIS/scale
    def _validate_mount_paths(self):
        """Ensures that all mount paths are valid

        :raises :class:`job.seed.exceptions.InvalidSeedManifestDefinition`: If a mount path is invalid
        """

        for mount in self.get_mounts():
            name = mount['name']
            path = mount['path']
            if not os.path.isabs(path):
                raise InvalidSeedManifestDefinition('%s mount must have an absolute path' % name)
예제 #4
0
파일: manifest.py 프로젝트: SteveAIS/scale
    def _check_mount_name_uniqueness(self):
        """Ensures all the mount names are unique, and throws a
        :class:`job.seed.exceptions.InvalidInterfaceDefinition` if they are not unique
        """

        mounts = []
        for mount in self.get_mounts():
            mounts.append(mount['name'])

        if len(mounts) != len(set(mounts)):
            raise InvalidSeedManifestDefinition('Mount names must be unique.')
예제 #5
0
    def _check_error_name_uniqueness(self):
        """Ensures all the error names are unique, and throws a
        :class:`job.seed.exceptions.InvalidInterfaceDefinition` if they are not unique
        """

        errors = []
        for error in self.get_errors():
            errors.append(error['name'])

        if len(errors) != len(set(errors)):
            raise InvalidSeedManifestDefinition('DUPLICATE_ERROR_NAMES',
                                                'Error names must be unique.')