Commit 90161f61 authored by André Anjos's avatar André Anjos 💬

[test][docker] Move test-image pull function to a test submodule on request

parent 8be017cf
Pipeline #27216 passed with stage
in 18 minutes and 23 seconds
......@@ -48,45 +48,6 @@ from beat.core import stats
logger = logging.getLogger(__name__)
DOCKER_TEST_IMAGES = {
"docker.idiap.ch/beat/beat.env.system.python": "1.3.0r4",
"docker.idiap.ch/beat/beat.env.db.examples": "1.4.0r4",
"docker.idiap.ch/beat/beat.env.cxx": "2.0.0r1",
"docker.idiap.ch/beat/beat.env.client": "2.0.0r1",
}
"""Images used for docker-enabled tests within this and other BEAT packages
"""
def pull_docker_test_images():
"""To be called when you need to set up tests using ``DOCKER_TEST_IMAGES``
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
"""
import docker
client = docker.from_env()
for image, tag in DOCKER_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
auth_config = dict(username='gitlab-ci-token', password=token)
params += (auth_config,)
client.images.pull(*params)
class Host(object):
"""An object of this class can connect to the docker host and resolve stuff
"""
......
......@@ -34,6 +34,49 @@ import shutil
import nose
import docker
#----------------------------------------------------------
DOCKER_TEST_IMAGES = {
"docker.idiap.ch/beat/beat.env.system.python": "1.3.0r4",
"docker.idiap.ch/beat/beat.env.db.examples": "1.4.0r4",
"docker.idiap.ch/beat/beat.env.cxx": "2.0.0r1",
"docker.idiap.ch/beat/beat.env.client": "2.0.0r1",
}
"""Images used for docker-enabled tests within this and other BEAT packages
"""
def pull_docker_test_images():
"""To be called when you need to set up tests using ``DOCKER_TEST_IMAGES``
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
"""
import docker
client = docker.from_env()
for image, tag in DOCKER_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
auth_config = dict(username='gitlab-ci-token', password=token)
params += (auth_config,)
client.images.pull(*params)
#----------------------------------------------------------
......
......@@ -9,6 +9,6 @@ recipe = bob.buildout:scripts
[docker]
recipe = collective.recipe.cmd
cmds = ./bin/python -c 'from beat.core.dock import pull_docker_test_images as f; f()'
cmds = ./bin/python -c 'from beat.core.test.utils import pull_docker_test_images as f; f()'
on_install = true
on_update = true
......@@ -53,7 +53,7 @@ test:
commands:
# pulls required images once before running the tests
- python -c "from beat.core.dock import pull_docker_test_images as f; f()"
- python -c "from beat.core.test.utils import pull_docker_test_images as f; f()"
- worker --help
- nosetests --with-coverage --cover-package={{ name }} -sv {{ name }}
- sphinx-build -aEW {{ project_dir }}/doc {{ project_dir }}/sphinx
......
......@@ -16,6 +16,6 @@ recipe = bob.buildout:scripts
[docker]
recipe = collective.recipe.cmd
cmds = ./bin/python -c 'from beat.core.dock import pull_docker_test_images as f; f()'
cmds = ./bin/python -c 'from beat.core.test.utils import pull_docker_test_images as f; f()'
on_install = true
on_update = true
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