summaryrefslogtreecommitdiff
path: root/tests/testutils/artifactshare.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/testutils/artifactshare.py')
-rw-r--r--tests/testutils/artifactshare.py45
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.