hosts info config in container 47/35047/3
authorMatthewLi <matthew.lijun@huawei.com>
Fri, 19 May 2017 09:22:34 +0000 (05:22 -0400)
committerMatthewLi <matthew.lijun@huawei.com>
Fri, 19 May 2017 09:46:11 +0000 (05:46 -0400)
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>
dovetail/container.py
userconfig/hosts.yaml [new file with mode: 0644]

index ae7c8e2..11c64f4 100644 (file)
@@ -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 (file)
index 0000000..e4687df
--- /dev/null
@@ -0,0 +1,2 @@
+---
+hosts_info: