You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@buildstream.apache.org by gi...@apache.org on 2020/12/29 13:11:42 UTC
[buildstream] 33/41: tests/testutils/artifactshare.py: Use CAS
artifact server
This is an automated email from the ASF dual-hosted git repository.
github-bot pushed a commit to branch jmac/googlecas_and_virtual_directories_1
in repository https://gitbox.apache.org/repos/asf/buildstream.git
commit 2d93d03643d02eae48a6b43684a5b85709158d6f
Author: Jürg Billeter <j...@bitron.ch>
AuthorDate: Sun May 13 20:42:52 2018 +0200
tests/testutils/artifactshare.py: Use CAS artifact server
---
tests/testutils/artifactshare.py | 74 +++++++++++++++++++++++++---------------
1 file changed, 47 insertions(+), 27 deletions(-)
diff --git a/tests/testutils/artifactshare.py b/tests/testutils/artifactshare.py
index b7cb5d3..6b9117b 100644
--- a/tests/testutils/artifactshare.py
+++ b/tests/testutils/artifactshare.py
@@ -3,12 +3,17 @@ import pytest
import subprocess
import os
import shutil
+import signal
from contextlib import contextmanager
+from multiprocessing import Process, Queue
+import pytest_cov
from buildstream import _yaml
-
-from .site import HAVE_OSTREE_CLI
+from buildstream._artifactcache.cascache import CASCache
+from buildstream._artifactcache.casserver import create_server
+from buildstream._context import Context
+from buildstream._exceptions import ArtifactError
# ArtifactShare()
@@ -23,11 +28,6 @@ class ArtifactShare():
def __init__(self, directory):
- # We need the ostree CLI for tests which use this
- #
- if not HAVE_OSTREE_CLI:
- pytest.skip("ostree cli is not available")
-
# The working directory for the artifact share (in case it
# needs to do something outside of it's backend's storage folder).
#
@@ -38,24 +38,42 @@ class ArtifactShare():
# Unless this gets more complicated, just use this directly
# in tests as a remote artifact push/pull configuration
#
- self.repo = os.path.join(self.directory, 'repo')
+ self.repodir = os.path.join(self.directory, 'repo')
- os.makedirs(self.repo)
+ os.makedirs(self.repodir)
- self.init()
+ context = Context()
+ context.artifactdir = self.repodir
- # init():
- #
- # Initializes the artifact share
+ self.cas = CASCache(context)
+
+ q = Queue()
+
+ self.process = Process(target=self.run, args=(q,))
+ self.process.start()
+
+ # Retrieve port from server subprocess
+ port = q.get()
+
+ self.repo = 'http://localhost:{}'.format(port)
+
+ # run():
#
- # Returns:
- # (smth): A new ref corresponding to this commit, which can
- # be passed as the ref in the Repo.source_config() API.
+ # Run the artifact server.
#
- def init(self):
- subprocess.call(['ostree', 'init',
- '--repo', self.repo,
- '--mode', 'archive-z2'])
+ def run(self, q):
+ pytest_cov.embed.cleanup_on_sigterm()
+
+ server = create_server(self.repodir, enable_push=True)
+ port = server.add_insecure_port('localhost:0')
+
+ server.start()
+
+ # Send port to parent
+ q.put(port)
+
+ # Sleep until termination by signal
+ signal.pause()
# has_artifact():
#
@@ -70,8 +88,8 @@ class ArtifactShare():
# (bool): True if the artifact exists in the share, otherwise false.
def has_artifact(self, project_name, element_name, cache_key):
- # NOTE: This should be kept in line with our ostree
- # based artifact cache code, the below is the
+ # NOTE: This should be kept in line with our
+ # artifact cache code, the below is the
# same algo for creating an artifact reference
#
@@ -86,18 +104,20 @@ class ArtifactShare():
])
artifact_key = '{0}/{1}/{2}'.format(project_name, element_name, cache_key)
- if not subprocess.call(['ostree', 'rev-parse',
- '--repo', self.repo,
- artifact_key]):
+ try:
+ tree = self.cas.resolve_ref(artifact_key)
return True
-
- return False
+ except ArtifactError:
+ return False
# close():
#
# Remove the artifact share.
#
def close(self):
+ self.process.terminate()
+ self.process.join()
+
shutil.rmtree(self.directory)