コード例 #1
0
ファイル: workspace.py プロジェクト: wjt/buildstream
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
コード例 #2
0
def test_update_artifact(tmpdir, files):
    sharedir = os.path.join(str(tmpdir), "share")
    with create_artifact_share(sharedir, casd=True) as share:
        # put files object
        if files == "present":
            directory = re_pb2.Directory()
            digest = share.cas.add_object(buffer=directory.SerializeToString())
        elif files == "invalid":
            digest = share.cas.add_object(
                buffer="abcdefghijklmnop".encode("utf-8"))
        elif files == "absent":
            digest = utils._message_digest("abcdefghijklmnop".encode("utf-8"))

        url = urlparse(share.repo)

        with grpc.insecure_channel("{}:{}".format(url.hostname,
                                                  url.port)) as channel:
            artifact_stub = ArtifactServiceStub(channel)

            # initialise an artifact
            artifact = Artifact()
            artifact.version = 0
            artifact.build_success = True
            artifact.strong_key = "abcdefghijklmnop"
            artifact.files.hash = "hashymchashash"
            artifact.files.size_bytes = 10

            artifact.files.CopyFrom(digest)

            # Put it in the artifact share with an UpdateArtifactRequest
            request = UpdateArtifactRequest()
            request.artifact.CopyFrom(artifact)
            request.cache_key = "a-cache-key"

            # should return the same artifact back
            if files == "present":
                response = artifact_stub.UpdateArtifact(request)
                assert response == artifact
            else:
                try:
                    artifact_stub.UpdateArtifact(request)
                except grpc.RpcError as e:
                    assert e.code() == grpc.StatusCode.FAILED_PRECONDITION
                    if files == "absent":
                        assert e.details(
                        ) == "Artifact files specified but no files found"
                    elif files == "invalid":
                        assert e.details(
                        ) == "Artifact files specified but directory not found"
                    return

            # If we uploaded the artifact check GetArtifact
            request = GetArtifactRequest()
            request.cache_key = "a-cache-key"

            response = artifact_stub.GetArtifact(request)
            assert response == artifact
コード例 #3
0
def test_artifact_get_not_found(tmpdir):
    sharedir = os.path.join(str(tmpdir), "share")
    with create_artifact_share(sharedir) as share:
        # set up artifact service stub
        url = urlparse(share.repo)
        with grpc.insecure_channel("{}:{}".format(url.hostname,
                                                  url.port)) as channel:
            artifact_stub = ArtifactServiceStub(channel)

            # Run GetArtifact and check it throws a not found error
            request = GetArtifactRequest()
            request.cache_key = "@artifact/something/not_there"
            try:
                artifact_stub.GetArtifact(request)
            except grpc.RpcError as e:
                assert e.code() == grpc.StatusCode.NOT_FOUND
                assert e.details() == "Artifact proto not found"
            else:
                assert False
コード例 #4
0
def test_build_partial_push(cli, tmpdir, datafiles):
    project = str(datafiles)
    share_dir = os.path.join(str(tmpdir), "artifactshare")
    element_name = "no-runtime-deps.bst"
    builddep_element_name = "autotools/amhello.bst"

    with create_artifact_share(share_dir) as share:

        services = cli.ensure_services()
        assert set(services) == set(["action-cache", "execution", "storage"])

        cli.config["artifacts"] = {
            "url": share.repo,
            "push": True,
        }

        res = cli.run(project=project, args=["build", element_name])
        res.assert_success()

        assert builddep_element_name in res.get_pushed_elements()