summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthewLi <matthew.lijun@huawei.com>2017-05-19 05:22:34 -0400
committerMatthewLi <matthew.lijun@huawei.com>2017-05-19 05:46:11 -0400
commit84e7b3b030018fd3f464bfa9c47c1df9d07ce675 (patch)
treea222bc84a7c3929c8cdc7ba3e2f2c1bda6917e43
parent90cbc0764d68369a0a6ce0fe09112e73fef2e760 (diff)
hosts info config in container
JIRA: DOVETAIL-435 in some SUT, there's a need to config hosts <domain name>:<ip> 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:<some IP> 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 <matthew.lijun@huawei.com>
-rw-r--r--dovetail/container.py21
-rw-r--r--userconfig/hosts.yaml2
2 files changed, 21 insertions, 2 deletions
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 = \
diff --git a/userconfig/hosts.yaml b/userconfig/hosts.yaml
new file mode 100644
index 00000000..e4687dfb
--- /dev/null
+++ b/userconfig/hosts.yaml
@@ -0,0 +1,2 @@
+---
+hosts_info: