diff options
author | Jürg Billeter <j@bitron.ch> | 2018-05-13 20:42:52 +0200 |
---|---|---|
committer | Jürg Billeter <j@bitron.ch> | 2018-07-08 14:57:17 +0200 |
commit | 3d75abe9d179caa9888030db527a30a493188dfb (patch) | |
tree | dca2a78c8092e4c7e7e4cffd15756c263483e54b | |
parent | e19690f0e63dd39f81c8e832eea699a183bfd48d (diff) | |
download | buildstream-3d75abe9d179caa9888030db527a30a493188dfb.tar.gz |
tests/testutils/artifactshare.py: Use CAS artifact server
-rw-r--r-- | tests/testutils/artifactshare.py | 74 |
1 files changed, 47 insertions, 27 deletions
diff --git a/tests/testutils/artifactshare.py b/tests/testutils/artifactshare.py index b7cb5d33d..6b9117b48 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) |