summaryrefslogtreecommitdiffstats
path: root/dovetail/container.py
diff options
context:
space:
mode:
authorxudan <xudan16@huawei.com>2018-03-23 00:03:58 -0400
committerGeorg Kunz <georg.kunz@ericsson.com>2018-04-10 10:21:02 +0000
commit8b0d80d556dfd7935b6464ec76b49c9c0e6249e0 (patch)
tree4bc938b2043e89f5a88cb81f81196a9da3b75f0f /dovetail/container.py
parentde58a1bd6d908aefc8461c866901e64c12454c8b (diff)
Support to specify docker image for each test case
1. Currently each type of test cases will use one docker image. 2. For example, Functest test cases use opnfv/functest-restapi:euphrates Yardstick uses opnfv/yardstick:opnfv-5.1.0 3. It needs to support to specify the docker image for each test case. 4. For example, vping test cases use opnfv/functest-smoke:euphrates sdnvpn uses opnfv/functest-features:euphrates 5. The benefit of this is that these docker images are well verified by Functest CI and from Functest plan, they may not support functest-restapi docker image in its future release. JIRA: DOVETAIL-638 Change-Id: I8a30eea2233aeff809af2e241b6c939194397832 Signed-off-by: xudan <xudan16@huawei.com>
Diffstat (limited to 'dovetail/container.py')
-rw-r--r--dovetail/container.py45
1 files changed, 20 insertions, 25 deletions
diff --git a/dovetail/container.py b/dovetail/container.py
index 4feed802..b77f4919 100644
--- a/dovetail/container.py
+++ b/dovetail/container.py
@@ -17,8 +17,6 @@ from utils.dovetail_config import DovetailConfig as dt_cfg
class Container(object):
container_list = {}
- has_pull_latest_image = {'yardstick': False, 'functest': False,
- 'bottlenecks': False, 'vnftest': False}
logger = None
@@ -37,14 +35,23 @@ class Container(object):
return cls.container_list[type]
@classmethod
- def get_docker_image(cls, type):
- try:
- return '%s:%s' % (dt_cfg.dovetail_config[type]['image_name'],
- dt_cfg.dovetail_config[type]['docker_tag'])
- except KeyError as e:
- cls.logger.exception(
- 'There is no key {} in {} config file.'.format(e, type))
- return None
+ def _get_config(cls, field, project_cfg, testcase_cfg):
+ value = dt_utils.get_value_from_dict(field, testcase_cfg)
+ if not value:
+ value = dt_utils.get_value_from_dict(field, project_cfg)
+ if not value:
+ cls.logger.error("Couldn't find key {}.".format(field))
+ return None
+ return value
+
+ @classmethod
+ def get_docker_image(cls, testcase):
+ project_cfg = dt_cfg.dovetail_config[testcase.validate_type()]
+ testcase_cfg = testcase.testcase['validate']
+
+ name = cls._get_config('image_name', project_cfg, testcase_cfg)
+ tag = cls._get_config('docker_tag', project_cfg, testcase_cfg)
+ return "{}:{}".format(name, tag) if name and tag else None
# get the openrc_volume for creating the container
@classmethod
@@ -132,9 +139,9 @@ class Container(object):
return "%s %s" % (log_vol, key_vol)
@classmethod
- def create(cls, type, testcase_name):
+ def create(cls, type, testcase_name, docker_image):
dovetail_config = dt_cfg.dovetail_config
- docker_image = cls.get_docker_image(type)
+ opts = dovetail_config[type]['opts']
# credentials file openrc.sh is neccessary
openrc = cls.openrc_volume(type)
@@ -255,18 +262,12 @@ class Container(object):
return True
@classmethod
- def pull_image(cls, validate_type):
- docker_image = cls.get_docker_image(validate_type)
+ def pull_image(cls, docker_image):
if not docker_image:
return None
- if cls.has_pull_latest_image[validate_type] is True:
- cls.logger.debug(
- '{} is already the latest one.'.format(docker_image))
- return docker_image
old_image_id = cls.get_image_id(docker_image)
if not cls.pull_image_only(docker_image):
return None
- cls.has_pull_latest_image[validate_type] = True
new_image_id = cls.get_image_id(docker_image)
if not new_image_id:
cls.logger.error(
@@ -282,12 +283,6 @@ class Container(object):
return docker_image
@classmethod
- def check_image_exist(cls, validate_type):
- docker_image = cls.get_docker_image(validate_type)
- image_id = cls.get_image_id(docker_image)
- return image_id
-
- @classmethod
def check_container_exist(cls, container_name):
cmd = ('sudo docker ps -aq -f name={}'.format(container_name))
ret, msg = dt_utils.exec_cmd(cmd, cls.logger)