diff options
author | Raoul Hidalgo Charman <raoul.hidalgocharman@codethink.co.uk> | 2019-03-28 12:31:50 +0000 |
---|---|---|
committer | bst-marge-bot <marge-bot@buildstream.build> | 2019-05-15 10:18:26 +0000 |
commit | 30e89a6a3cdcea83e0d83e373e50b88c02df3667 (patch) | |
tree | 2ca584a89133bdc0efe2fa5d876173f48d7f396c /tests/testutils | |
parent | 7c1bb299c891b7fe8b92e1d54a38eca0b55840ef (diff) | |
download | buildstream-30e89a6a3cdcea83e0d83e373e50b88c02df3667.tar.gz |
_artifact.py: Rework to use artifact proto
This will replace the previous use of a directory structure.
Quite a lot is changed here, predominantly _artifact and _artifactcache
modules.
Part of #974
Diffstat (limited to 'tests/testutils')
-rw-r--r-- | tests/testutils/artifactshare.py | 45 |
1 files changed, 38 insertions, 7 deletions
diff --git a/tests/testutils/artifactshare.py b/tests/testutils/artifactshare.py index fca01497a..bc69a87d8 100644 --- a/tests/testutils/artifactshare.py +++ b/tests/testutils/artifactshare.py @@ -10,6 +10,7 @@ from buildstream._cas import CASCache from buildstream._cas.casserver import create_server from buildstream._exceptions import CASError from buildstream._protos.build.bazel.remote.execution.v2 import remote_execution_pb2 +from buildstream._protos.buildstream.v2 import artifact_pb2 # ArtifactShare() @@ -42,6 +43,8 @@ class ArtifactShare(): # self.repodir = os.path.join(self.directory, 'repo') os.makedirs(self.repodir) + self.artifactdir = os.path.join(self.repodir, 'artifacts', 'refs') + os.makedirs(self.artifactdir) self.cas = CASCache(self.repodir) @@ -126,17 +129,45 @@ class ArtifactShare(): # Returns: # (str): artifact digest if the artifact exists in the share, otherwise None. def has_artifact(self, artifact_name): + + artifact_proto = artifact_pb2.Artifact() + artifact_path = os.path.join(self.artifactdir, artifact_name) + + try: + with open(artifact_path, 'rb') as f: + artifact_proto.ParseFromString(f.read()) + except FileNotFoundError: + return None + + reachable = set() + + def reachable_dir(digest): + self.cas._reachable_refs_dir( + reachable, digest, update_mtime=False, check_exists=True) + try: - tree = self.cas.resolve_ref(artifact_name) - reachable = set() - try: - self.cas._reachable_refs_dir(reachable, tree, update_mtime=False, check_exists=True) - except FileNotFoundError: - return None - return tree + if str(artifact_proto.files): + reachable_dir(artifact_proto.files) + + if str(artifact_proto.buildtree): + reachable_dir(artifact_proto.buildtree) + + if str(artifact_proto.public_data): + if not os.path.exists(self.cas.objpath(artifact_proto.public_data)): + return None + + for log_file in artifact_proto.logs: + if not os.path.exists(self.cas.objpath(log_file.digest)): + return None + + return artifact_proto.files + except CASError: return None + except FileNotFoundError: + return None + # close(): # # Remove the artifact share. |