Commit 71a722c4 authored by André Anjos's avatar André Anjos 💬

[test][docker] Make auto-image pulling a function; Call it to setup various docker modules

parent 5358a362
Pipeline #27142 passed with stage
in 19 minutes and 23 seconds
......@@ -83,27 +83,27 @@ TEST_IMAGES = {
"""
def setup_package():
prefixes = [
pkg_resources.resource_filename('beat.backend.python.test', 'prefix'),
pkg_resources.resource_filename('beat.core.test', 'prefix')
]
def setup_docker_test_images():
"""To be called when you need to set those up. Check ``TEST_IMAGES``
for path in prefixes:
subprocess.check_call(['rsync', '-arz', path, prefix_folder])
This function will pull images that are not locally available yet
This technique prevents errors if docker.idiap.ch is not available,
e.g. when running outside the Idiap network
"""
# Docker setup - pull images that are not locally available yet
# This technique prevents errors if docker.idiap.ch is not available
# e.g. when running outside the Idiap network
import docker
client = docker.from_env()
for image, tag in TEST_IMAGES.items():
has_image = False
for installed_image in client.images.list():
for installed_tag in installed_image.tags:
if installed_tag == ('%s:%s' % (image, tag)):
has_image = True
if not has_image: #must pull (network connection required)
token = os.environ.get('CI_BUILD_TOKEN')
params = (image, tag)
if token is not None: #running on CI, setup
......@@ -111,7 +111,19 @@ def setup_package():
params += (auth_config,)
client.images.pull(*params)
def setup_package():
prefixes = [
pkg_resources.resource_filename('beat.backend.python.test', 'prefix'),
pkg_resources.resource_filename('beat.core.test', 'prefix')
]
for path in prefixes:
subprocess.check_call(['rsync', '-arz', path, prefix_folder])
if DOCKER_NETWORK_TEST_ENABLED:
import docker
client = docker.from_env()
try:
network = client.networks.get(network_name)
except docker.errors.NotFound:
......
......@@ -50,6 +50,10 @@ from .utils import skipif
from . import network_name
from . import DOCKER_NETWORK_TEST_ENABLED
# this will ensure we pull the required images for the tests
from . import setup_docker_test_images as setup_module
class NoDiscoveryTests(unittest.TestCase):
"""Test cases that don't require the discovery of database and runtime
environments.
......
......@@ -54,6 +54,9 @@ from ..utils import find_free_port
from . import prefix
from . import tmp_prefix
# this will ensure we pull the required images for the tests
from . import setup_docker_test_images as setup_module
#----------------------------------------------------------
......
......@@ -33,6 +33,9 @@ from .. import environments
from .utils import slow
# this will ensure we pull the required images for the tests
from . import setup_docker_test_images as setup_module
class EnvironmentTest(unittest.TestCase):
......
......@@ -44,6 +44,9 @@ from . import network_name
from . import prefix_folder
from . import DOCKER_NETWORK_TEST_ENABLED
# this will ensure we pull the required images for the tests
from . import setup_docker_test_images as setup_module
BUILDER_IMAGE = "docker.idiap.ch/beat/beat.env.client:2.0.0r0"
#----------------------------------------------------------
......
......@@ -32,6 +32,10 @@ from ..dock import Host
from .test_worker import TestOneWorker, TestTwoWorkers
# this will ensure we pull the required images for the tests
from . import setup_docker_test_images as setup_module
#----------------------------------------------------------
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment