Example #1
0
    def test_diystage_path_valid(self, tmpdir):
        """Ensure DIYStage for a valid path behaves as expected."""
        path = str(tmpdir)
        stage = DIYStage(path)
        assert stage.path == path
        assert stage.source_path == path

        # Order doesn't really matter for DIYStage since they are
        # basically NOOPs; however, call each since they are part
        # of the normal stage usage and to ensure full test coverage.
        stage.create()  # Only sets the flag value
        assert stage.created

        stage.cache_local()  # Only outputs a message
        stage.fetch()  # Only outputs a message
        stage.check()  # Only outputs a message
        stage.expand_archive()  # Only outputs a message

        assert stage.expanded  # The path/source_path does exist

        with pytest.raises(spack.stage.RestageError):
            stage.restage()

        stage.destroy()  # A no-op
        assert stage.path == path  # Ensure can still access attributes
        assert os.path.exists(stage.source_path)  # Ensure path still exists
Example #2
0
 def test_expand_archive(self, mock_archive):
     with Stage(mock_archive.url, name=self.stage_name) as stage:
         stage.fetch()
         check_setup(stage, self.stage_name, mock_archive)
         check_fetch(stage, self.stage_name)
         stage.expand_archive()
         check_expand_archive(stage, self.stage_name, mock_archive)
     check_destroy(stage, self.stage_name)
Example #3
0
File: stage.py Project: LLNL/spack
 def test_expand_archive(self, mock_archive):
     with Stage(mock_archive.url, name=self.stage_name) as stage:
         stage.fetch()
         check_setup(stage, self.stage_name, mock_archive)
         check_fetch(stage, self.stage_name)
         stage.expand_archive()
         check_expand_archive(stage, self.stage_name, mock_archive)
     check_destroy(stage, self.stage_name)
Example #4
0
 def test_expand_archive(self):
     with Stage(self.archive_url, name=self.stage_name) as stage:
         stage.fetch()
         self.check_setup(stage, self.stage_name)
         self.check_fetch(stage, self.stage_name)
         stage.expand_archive()
         self.check_expand_archive(stage, self.stage_name)
     self.check_destroy(stage, self.stage_name)
Example #5
0
 def test_expand_archive(self, expected_file_list, mock_stage_archive):
     archive = mock_stage_archive(expected_file_list)
     with Stage(archive.url, name=self.stage_name) as stage:
         stage.fetch()
         check_setup(stage, self.stage_name, archive)
         check_fetch(stage, self.stage_name)
         stage.expand_archive()
         check_expand_archive(stage, self.stage_name, expected_file_list)
     check_destroy(stage, self.stage_name)
Example #6
0
def _mirror(args):
    mirror_dir = spack.util.path.canonicalize_path(
        os.path.join(args.root_dir, LOCAL_MIRROR_DIR))

    # TODO: Here we are adding gnuconfig manually, but this can be fixed
    # TODO: as soon as we have an option to add to a mirror all the possible
    # TODO: dependencies of a spec
    root_specs = spack.bootstrap.all_root_specs(
        development=args.dev) + ['gnuconfig']
    for spec_str in root_specs:
        msg = 'Adding "{0}" and dependencies to the mirror at {1}'
        llnl.util.tty.msg(msg.format(spec_str, mirror_dir))
        # Suppress tty from the call below for terser messages
        llnl.util.tty.set_msg_enabled(False)
        spec = spack.spec.Spec(spec_str).concretized()
        for node in spec.traverse():
            spack.mirror.create(mirror_dir, [node])
        llnl.util.tty.set_msg_enabled(True)

    if args.binary_packages:
        msg = 'Adding binary packages from "{0}" to the mirror at {1}'
        llnl.util.tty.msg(msg.format(BINARY_TARBALL, mirror_dir))
        llnl.util.tty.set_msg_enabled(False)
        stage = spack.stage.Stage(BINARY_TARBALL, path=tempfile.mkdtemp())
        stage.create()
        stage.fetch()
        stage.expand_archive()
        build_cache_dir = os.path.join(stage.source_path, 'build_cache')
        shutil.move(build_cache_dir, mirror_dir)
        llnl.util.tty.set_msg_enabled(True)

    def write_metadata(subdir, metadata):
        metadata_rel_dir = os.path.join('metadata', subdir)
        metadata_yaml = os.path.join(args.root_dir, metadata_rel_dir,
                                     'metadata.yaml')
        llnl.util.filesystem.mkdirp(os.path.dirname(metadata_yaml))
        with open(metadata_yaml, mode='w') as f:
            spack.util.spack_yaml.dump(metadata, stream=f)
        return os.path.dirname(metadata_yaml), metadata_rel_dir

    instructions = (
        '\nTo register the mirror on the platform where it\'s supposed '
        'to be used, move "{0}" to its final location and run the '
        'following command(s):\n\n').format(args.root_dir)
    cmd = '  % spack bootstrap add --trust {0} <final-path>/{1}\n'
    _, rel_directory = write_metadata(subdir='sources',
                                      metadata=SOURCE_METADATA)
    instructions += cmd.format('local-sources', rel_directory)
    if args.binary_packages:
        abs_directory, rel_directory = write_metadata(subdir='binaries',
                                                      metadata=BINARY_METADATA)
        shutil.copy(spack.util.path.canonicalize_path(CLINGO_JSON),
                    abs_directory)
        shutil.copy(spack.util.path.canonicalize_path(GNUPG_JSON),
                    abs_directory)
        instructions += cmd.format('local-binaries', rel_directory)
    print(instructions)
Example #7
0
 def test_expand_archive_extra_expand(self, mock_stage_archive):
     """Test expand with an extra expand after expand (i.e., no-op)."""
     archive = mock_stage_archive()
     with Stage(archive.url, name=self.stage_name) as stage:
         stage.fetch()
         check_setup(stage, self.stage_name, archive)
         check_fetch(stage, self.stage_name)
         stage.expand_archive()
         stage.fetcher.expand()
         check_expand_archive(stage, self.stage_name, [_include_readme])
     check_destroy(stage, self.stage_name)
Example #8
0
 def test_noexpand_stage_file(
         self, mock_stage_archive, mock_noexpand_resource):
     """When creating a stage with a nonexpanding URL, the 'archive_file'
     property of the stage should refer to the path of that file.
     """
     test_noexpand_fetcher = spack.fetch_strategy.from_kwargs(
         url='file://' + mock_noexpand_resource, expand=False)
     with Stage(test_noexpand_fetcher) as stage:
         stage.fetch()
         stage.expand_archive()
         assert os.path.exists(stage.archive_file)
Example #9
0
    def test_restage(self, mock_archive):
        with Stage(mock_archive.url, name=self.stage_name) as stage:
            stage.fetch()
            stage.expand_archive()

            with working_dir(stage.source_path):
                check_expand_archive(stage, self.stage_name, mock_archive)

                # Try to make a file in the old archive dir
                with open('foobar', 'w') as file:
                    file.write("this file is to be destroyed.")

            assert 'foobar' in os.listdir(stage.source_path)

            # Make sure the file is not there after restage.
            stage.restage()
            check_fetch(stage, self.stage_name)
            assert 'foobar' not in os.listdir(stage.source_path)
        check_destroy(stage, self.stage_name)
Example #10
0
File: stage.py Project: LLNL/spack
    def test_restage(self, mock_archive):
        with Stage(mock_archive.url, name=self.stage_name) as stage:
            stage.fetch()
            stage.expand_archive()

            with working_dir(stage.source_path):
                check_expand_archive(stage, self.stage_name, mock_archive)

                # Try to make a file in the old archive dir
                with open('foobar', 'w') as file:
                    file.write("this file is to be destroyed.")

            assert 'foobar' in os.listdir(stage.source_path)

            # Make sure the file is not there after restage.
            stage.restage()
            check_fetch(stage, self.stage_name)
            assert 'foobar' not in os.listdir(stage.source_path)
        check_destroy(stage, self.stage_name)
Example #11
0
    def test_restage(self):
        with Stage(self.archive_url, name=self.stage_name) as stage:
            stage.fetch()
            stage.expand_archive()
            stage.chdir_to_source()
            self.check_expand_archive(stage, self.stage_name)
            self.check_chdir_to_source(stage, self.stage_name)

            # Try to make a file in the old archive dir
            with open('foobar', 'w') as file:
                file.write("this file is to be destroyed.")

            self.assertTrue('foobar' in os.listdir(stage.source_path))

            # Make sure the file is not there after restage.
            stage.restage()
            self.check_chdir(stage, self.stage_name)
            self.check_fetch(stage, self.stage_name)
            stage.chdir_to_source()
            self.check_chdir_to_source(stage, self.stage_name)
            self.assertFalse('foobar' in os.listdir(stage.source_path))
        self.check_destroy(stage, self.stage_name)