From d5b340cc43b01b837474b95ff7d8555c5333cb46 Mon Sep 17 00:00:00 2001 From: Sviatoslav Sydorenko Date: Tue, 3 Apr 2018 20:07:51 +0200 Subject: [PATCH] Improve foreman image src selection --- test/runner/lib/cloud/foreman.py | 45 +++++++++++++++++++++++++++----- 1 file changed, 38 insertions(+), 7 deletions(-) diff --git a/test/runner/lib/cloud/foreman.py b/test/runner/lib/cloud/foreman.py index 1dd93e72a5..9bce0370ce 100644 --- a/test/runner/lib/cloud/foreman.py +++ b/test/runner/lib/cloud/foreman.py @@ -4,6 +4,7 @@ from __future__ import absolute_import, print_function import os +import random from . import ( CloudProvider, @@ -31,7 +32,26 @@ class ForemanProvider(CloudProvider): """ DOCKER_SIMULATOR_NAME = 'foreman-stub' - DOCKER_SIMULATOR_IMAGE_NAME = 'foreman-simulator' + DOCKER_SIMULATOR_IMAGE_NAME = 'ansible/foreman-test-container' + DOCKER_SIMULATOR_IMAGE_TAG = '1.0.0' + + DOCKER_IMAGES = { + 'hub': { + 'registry_url': 'registry.hub.docker.com', + 'img_name': DOCKER_SIMULATOR_IMAGE_NAME, + 'img_tag': DOCKER_SIMULATOR_IMAGE_TAG, + }, + 'quay': { + 'registry_url': 'quay.io', + 'img_name': DOCKER_SIMULATOR_IMAGE_NAME, + 'img_tag': DOCKER_SIMULATOR_IMAGE_TAG, + }, + } + """Image registry to pull Foreman stub from. + + It's source source itself resides at: + https://github.com/ansible/foreman-test-container + """ def __init__(self, args): """Set up container references for provider. @@ -41,12 +61,23 @@ class ForemanProvider(CloudProvider): super(ForemanProvider, self).__init__(args) self.__container_from_env = os.getenv('ANSIBLE_FRMNSIM_CONTAINER') - self.image = self.__container_from_env or ( - 'ansible/ansible:%s' - # The simulator must be pinned to a specific version - # to guarantee CI passes with the version used: - '@sha256:soooomeinvaaalidddshaaa' - ) % self.DOCKER_SIMULATOR_IMAGE_NAME + """Overrides target container, might be used for development. + + Use ANSIBLE_FRMNSIM_CONTAINER={hub|quay|whatever_you_want} if you want + to be explicit. Omit/empty otherwise. + """ + + image_src = self.DOCKER_IMAGES.get(self.__container_from_env, {}) + if not image_src and self.__container_from_env: + self.image = self.__container_from_env + else: + self.image = ( + # The simulator must be pinned to a specific version + # to guarantee CI passes with the version used: + '{registry_url}/{img_name}:{img_tag}' + ).format( + **(image_src or random.choice(self.DOCKER_IMAGES)) + ) self.container_name = '' def filter(self, targets, exclude):