summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJürg Billeter <j@bitron.ch>2018-05-13 20:42:52 +0200
committerJürg Billeter <j@bitron.ch>2018-07-17 07:56:40 +0200
commita161c746b4a0774c1799e4c7c0e0bdad1141c437 (patch)
tree0c0b6e8342a9ced0e93f808aa8131a7dafb1fd4e
parent8de8ef1f4b71c6b0d72d5e171b8abfedb2650d0b (diff)
downloadbuildstream-a161c746b4a0774c1799e4c7c0e0bdad1141c437.tar.gz
tests/testutils/artifactshare.py: Use CAS artifact server
-rw-r--r--tests/testutils/artifactshare.py76
1 files changed, 48 insertions, 28 deletions
diff --git a/tests/testutils/artifactshare.py b/tests/testutils/artifactshare.py
index 720039acf..76b729e33 100644
--- a/tests/testutils/artifactshare.py
+++ b/tests/testutils/artifactshare.py
@@ -3,13 +3,18 @@ import pytest
import subprocess
import os
import shutil
+import signal
from collections import namedtuple
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()
@@ -26,11 +31,6 @@ class ArtifactShare():
def __init__(self, directory, *, total_space=None, free_space=None):
- # 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).
#
@@ -41,27 +41,34 @@ 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.repodir)
+
+ context = Context()
+ context.artifactdir = self.repodir
+
+ self.cas = CASCache(context)
self.total_space = total_space
self.free_space = free_space
- os.makedirs(self.repo)
+ q = Queue()
- self.init()
+ self.process = Process(target=self.run, args=(q,))
+ self.process.start()
- # init():
- #
- # Initializes the artifact share
+ # 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()
# Optionally mock statvfs
if self.total_space:
@@ -69,6 +76,17 @@ class ArtifactShare():
self.free_space = self.total_space
os.statvfs = self._mock_statvfs
+ 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():
#
# Checks whether the artifact is present in the share
@@ -82,8 +100,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
#
@@ -98,23 +116,25 @@ 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)
def _mock_statvfs(self, path):
repo_size = 0
- for root, _, files in os.walk(self.repo):
+ for root, _, files in os.walk(self.repodir):
for filename in files:
repo_size += os.path.getsize(os.path.join(root, filename))