From 84e7b3b030018fd3f464bfa9c47c1df9d07ce675 Mon Sep 17 00:00:00 2001 From: MatthewLi Date: Fri, 19 May 2017 05:22:34 -0400 Subject: hosts info config in container JIRA: DOVETAIL-435 in some SUT, there's a need to config hosts : info in container /etc/hosts, ortherwise, SUT service will not be used. usage: 1,for dovetail directly running, cd ${DOVETAIL_HOME}/userconfig vim hosts.yaml sth like hosts_info: - domain_nameA:192.168.33.101 - domain_nameB: 2,for dovetail container running, first get inside the container, cd /home/opnfv/dovetail/userconfig vim hosts.yaml same as 1. Change-Id: Ic5d87df3d78c0fa1d08c4e972c0fc97e61b906e9 Signed-off-by: MatthewLi --- dovetail/container.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'dovetail/container.py') diff --git a/dovetail/container.py b/dovetail/container.py index ae7c8e2e..11c64f49 100644 --- a/dovetail/container.py +++ b/dovetail/container.py @@ -8,6 +8,7 @@ # import os +import yaml import utils.dovetail_logger as dt_logger import utils.dovetail_utils as dt_utils @@ -149,10 +150,26 @@ class Container(object): ' -v %s:%s ' % (dovetail_config['userconfig_dir'], dovetail_config["functest"]['config']['dir']) + hosts_config = "" + hosts_config_path = os.path.abspath( + os.path.join(os.path.dirname(__file__), os.pardir, 'userconfig')) + try: + with open(os.path.join(hosts_config_path, 'hosts.yaml')) as f: + hosts_info = yaml.safe_load(f) + if hosts_info['hosts_info']: + for host in hosts_info['hosts_info']: + hosts_config += " --add-host " + hosts_config += str(host) + cls.logger.info('get hosts info %s', hosts_config) + except Exception: + cls.logger.warn('fail to get hosts info in %s/hosts.yaml, \ + maybe some issue with domain name resolution', + hosts_config_path) + result_volume = ' -v %s:%s ' % (dovetail_config['result_dir'], dovetail_config[type]['result']['dir']) - cmd = 'sudo docker run %s %s %s %s %s %s %s /bin/bash' % \ - (opts, envs, config, openrc, config_volume, + cmd = 'sudo docker run %s %s %s %s %s %s %s %s /bin/bash' % \ + (opts, envs, config, hosts_config, openrc, config_volume, result_volume, docker_image) dt_utils.exec_cmd(cmd, cls.logger) ret, container_id = \ -- cgit 1.2.3-korg