Пример #1
0
    def _read_spec_from_yaml(self, hash_key, installs, parent_key=None):
        """Recursively construct a spec from a hash in a YAML database.

        Does not do any locking.
        """
        spec_dict = installs[hash_key]['spec']

        # Install records don't include hash with spec, so we add it in here
        # to ensure it is read properly.
        for name in spec_dict:
            spec_dict[name]['hash'] = hash_key

        # Build spec from dict first.
        spec = Spec.from_node_dict(spec_dict)

        # Add dependencies from other records in the install DB to
        # form a full spec.
        for dep_hash in spec_dict[spec.name]['dependencies'].values():
            child = self._read_spec_from_yaml(dep_hash, installs, hash_key)
            spec._add_dependency(child)

        # Specs from the database need to be marked concrete because
        # they represent actual installations.
        spec._mark_concrete()
        return spec
Пример #2
0
def test_check_prefix_manifest(tmpdir):
    # Test the verification of an entire prefix and its contents
    prefix_path = tmpdir.join('prefix')
    prefix = str(prefix_path)

    spec = spack.spec.Spec('libelf')
    spec._mark_concrete()
    spec.prefix = prefix

    results = spack.verify.check_spec_manifest(spec)
    assert results.has_errors()
    assert prefix in results.errors
    assert results.errors[prefix] == ['manifest missing']

    metadata_dir = str(prefix_path.join('.spack'))
    bin_dir = str(prefix_path.join('bin'))
    other_dir = str(prefix_path.join('other'))

    for d in (metadata_dir, bin_dir, other_dir):
        fs.mkdirp(d)

    file = os.path.join(other_dir, 'file')
    with open(file, 'w') as f:
        f.write("I'm a little file short and stout")

    link = os.path.join(bin_dir, 'run')
    os.symlink(file, link)

    spack.verify.write_manifest(spec)
    results = spack.verify.check_spec_manifest(spec)
    assert not results.has_errors()

    os.remove(link)
    malware = os.path.join(metadata_dir, 'hiddenmalware')
    with open(malware, 'w') as f:
        f.write("Foul evil deeds")

    results = spack.verify.check_spec_manifest(spec)
    assert results.has_errors()
    assert all(x in results.errors for x in (malware, link))
    assert len(results.errors) == 2

    assert results.errors[link] == ['deleted']
    assert results.errors[malware] == ['added']

    manifest_file = os.path.join(spec.prefix,
                                 spack.store.layout.metadata_dir,
                                 spack.store.layout.manifest_file_name)
    with open(manifest_file, 'w') as f:
        f.write("{This) string is not proper json")

    results = spack.verify.check_spec_manifest(spec)
    assert results.has_errors()
    assert results.errors[spec.prefix] == ['manifest corrupted']
Пример #3
0
    def read_spec(self, path):
        """Read the contents of a file and parse them as a spec"""
        try:
            with open(path) as f:
                spec = spack.spec.Spec.from_yaml(f)
        except Exception as e:
            if spack.config.get('config:debug'):
                raise
            raise SpecReadError(
                'Unable to read file: %s' % path, 'Cause: ' + str(e))

        # Specs read from actual installations are always concrete
        spec._mark_concrete()
        return spec
Пример #4
0
    def read_spec(self, path):
        """Read the contents of a file and parse them as a spec"""
        try:
            with open(path) as f:
                spec = spack.spec.Spec.from_yaml(f)
        except Exception as e:
            if spack.config.get('config:debug'):
                raise
            raise SpecReadError('Unable to read file: %s' % path,
                                'Cause: ' + str(e))

        # Specs read from actual installations are always concrete
        spec._mark_concrete()
        return spec
Пример #5
0
    def read_spec(self, path):
        """Read the contents of a file and parse them as a spec"""
        try:
            with open(path) as f:
                extension = os.path.splitext(path)[-1].lower()
                if extension == '.json':
                    spec = spack.spec.Spec.from_json(f)
                elif extension == '.yaml':
                    # Too late for conversion; spec_file_path() already called.
                    spec = spack.spec.Spec.from_yaml(f)
                else:
                    raise SpecReadError('Did not recognize spec file extension:'
                                        ' {0}'.format(extension))
        except Exception as e:
            if spack.config.get('config:debug'):
                raise
            raise SpecReadError(
                'Unable to read file: %s' % path, 'Cause: ' + str(e))

        # Specs read from actual installations are always concrete
        spec._mark_concrete()
        return spec
Пример #6
0
    def _read_spec_from_yaml(self, hash_key, installs, parent_key=None):
        """Recursively construct a spec from a hash in a YAML database.

        Does not do any locking.
        """
        if hash_key not in installs:
            parent = read_spec(installs[parent_key]['path'])

        spec_dict = installs[hash_key]['spec']

        # Build spec from dict first.
        spec = Spec.from_node_dict(spec_dict)

        # Add dependencies from other records in the install DB to
        # form a full spec.
        for dep_hash in spec_dict[spec.name]['dependencies'].values():
            child = self._read_spec_from_yaml(dep_hash, installs, hash_key)
            spec._add_dependency(child)

        # Specs from the database need to be marked concrete because
        # they represent actual installations.
        spec._mark_concrete()
        return spec
Пример #7
0
    def _read_spec_from_yaml(self, hash_key, installs, parent_key=None):
        """Recursively construct a spec from a hash in a YAML database.

        Does not do any locking.
        """
        if hash_key not in installs:
            parent = read_spec(installs[parent_key]['path'])

        spec_dict = installs[hash_key]['spec']

        # Build spec from dict first.
        spec = Spec.from_node_dict(spec_dict)

        # Add dependencies from other records in the install DB to
        # form a full spec.
        for dep_hash in spec_dict[spec.name]['dependencies'].values():
            child = self._read_spec_from_yaml(dep_hash, installs, hash_key)
            spec._add_dependency(child)

        # Specs from the database need to be marked concrete because
        # they represent actual installations.
        spec._mark_concrete()
        return spec