Ejemplo n.º 1
0
def test_staged_source_build(tmpdir, datafiles, cli):
    project_dir = os.path.join(datafiles.dirname, datafiles.basename,
                               "project")
    cachedir = os.path.join(str(tmpdir), "cache")
    element_path = "elements"
    source_protos = os.path.join(str(tmpdir), "cache", "source_protos")
    elementsources = os.path.join(str(tmpdir), "cache", "elementsources")
    source_dir = os.path.join(str(tmpdir), "cache", "sources")

    cli.configure({"cachedir": cachedir})

    create_element_size("target.bst", project_dir, element_path, [], 10000)

    with dummy_context() as context:
        context.cachedir = cachedir
        project = Project(project_dir, context)
        project.ensure_fully_loaded()

        element = project.load_elements(["import-dev.bst"])[0]

        # check consistency of the source
        element._query_source_cache()
        assert not element._cached_sources()

    res = cli.run(project=project_dir, args=["build", "target.bst"])
    res.assert_success()

    # delete artifacts check state is buildable
    cli.remove_artifact_from_cache(project_dir, "target.bst")
    states = cli.get_element_states(project_dir, ["target.bst"])
    assert states["target.bst"] == "buildable"

    # delete source dir and check that state is still buildable
    shutil.rmtree(source_dir)
    states = cli.get_element_states(project_dir, ["target.bst"])
    assert states["target.bst"] == "buildable"

    # build and check that no fetching was done.
    res = cli.run(project=project_dir, args=["build", "target.bst"])
    res.assert_success()
    assert "Fetching from" not in res.stderr

    # assert the source directory is still empty (though there may be
    # directories from staging etc.)
    files = []
    for _, _, filename in os.walk(source_dir):
        files.extend(filename)
    assert files == []

    # Now remove the source refs and check the state
    shutil.rmtree(source_protos)
    shutil.rmtree(elementsources)
    cli.remove_artifact_from_cache(project_dir, "target.bst")
    states = cli.get_element_states(project_dir, ["target.bst"])
    assert states["target.bst"] == "fetch needed"

    # Check that it now fetches from when building the target
    res = cli.run(project=project_dir, args=["build", "target.bst"])
    res.assert_success()
    assert "Fetching from" in res.stderr
Ejemplo n.º 2
0
def test_workspace_open_no_source_push(tmpdir, datafiles, cli):
    project_dir = os.path.join(str(tmpdir), "project")
    element_path = "elements"
    cache_dir = os.path.join(str(tmpdir), "cache")
    share_dir = os.path.join(str(tmpdir), "share")
    workspace = os.path.join(cli.directory, "workspace")

    with create_artifact_share(share_dir) as share:
        cli.configure(
            {
                "cachedir": cache_dir,
                "scheduler": {"pushers": 1},
                "source-caches": {"servers": [{"url": share.repo, "push": True,}]},
            }
        )

        # Fetch as in previous test and check it pushes the source
        create_element_size("target.bst", project_dir, element_path, [], 10000)
        res = cli.run(project=project_dir, args=["build", "target.bst"])
        res.assert_success()
        assert "Fetching from" in res.stderr
        assert "Pushed source" in res.stderr

        # clear the cas and open a workspace
        shutil.rmtree(os.path.join(cache_dir, "cas"))
        res = cli.run(project=project_dir, args=["workspace", "open", "target.bst", "--directory", workspace])
        res.assert_success()

        # Check that this time it does not push the sources
        res = cli.run(project=project_dir, args=["build", "target.bst"])
        res.assert_success()
        assert "Pushed source" not in res.stderr
Ejemplo n.º 3
0
def test_source_checkout(tmpdir, datafiles, cli):
    project_dir = os.path.join(str(tmpdir), "project")
    element_path = "elements"
    cache_dir = os.path.join(str(tmpdir), "cache")
    source_dir = os.path.join(cache_dir, "sources")

    cli.configure(
        {"cachedir": cache_dir,}
    )
    target_dir = os.path.join(str(tmpdir), "target")

    repo = create_element_size("target.bst", project_dir, element_path, [], 100000)

    # check implicit fetching
    res = cli.run(project=project_dir, args=["source", "checkout", "--directory", target_dir, "target.bst"])
    res.assert_success()
    assert "Fetching from" in res.stderr

    # remove the directory and check source checkout works with sources only in
    # the CAS
    shutil.rmtree(repo.repo)
    shutil.rmtree(target_dir)
    shutil.rmtree(source_dir)

    res = cli.run(project=project_dir, args=["source", "checkout", "--directory", target_dir, "target.bst"])
    res.assert_success()
    assert "Fetching from" not in res.stderr

    # remove the CAS and check it doesn't work again
    shutil.rmtree(target_dir)
    shutil.rmtree(os.path.join(cache_dir, "cas"))

    res = cli.run(project=project_dir, args=["source", "checkout", "--directory", target_dir, "target.bst"])
    res.assert_task_error(ErrorDomain.PLUGIN, None)
Ejemplo n.º 4
0
def test_workspace_source_fetch(tmpdir, datafiles, cli):
    project_dir = os.path.join(str(tmpdir), "project")
    element_path = "elements"
    source_dir = os.path.join(str(tmpdir), "cache", "sources")
    workspace = os.path.join(cli.directory, "workspace")

    cli.configure({"cachedir": os.path.join(str(tmpdir), "cache")})

    create_element_size("target.bst", project_dir, element_path, [], 10000)
    res = cli.run(project=project_dir, args=["build", "target.bst"])
    res.assert_success()
    assert "Fetching" in res.stderr

    # remove the original sources
    shutil.rmtree(source_dir)

    # Open a workspace and check that fetches the original sources
    res = cli.run(project=project_dir, args=["workspace", "open", "target.bst", "--directory", workspace])
    res.assert_success()
    assert "Fetching" in res.stderr

    assert os.listdir(workspace) != []