diff options
Diffstat (limited to 'dovetail/container.py')
-rw-r--r-- | dovetail/container.py | 63 |
1 files changed, 46 insertions, 17 deletions
diff --git a/dovetail/container.py b/dovetail/container.py index 67e26f66..39062c84 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 @@ -48,7 +49,8 @@ class Container(object): @classmethod def openrc_volume(cls, type): dovetail_config = dt_cfg.dovetail_config - dovetail_config['openrc'] = os.path.abspath(dovetail_config['openrc']) + dovetail_config['openrc'] = os.path.join(dovetail_config['config_dir'], + dovetail_config['env_file']) if os.path.isfile(dovetail_config['openrc']): openrc = ' -v %s:%s ' % (dovetail_config['openrc'], dovetail_config[type]['openrc']) @@ -106,9 +108,22 @@ class Container(object): log_vol = '-v %s:%s ' % (dovetail_config['result_dir'], dovetail_config["yardstick"]['result']['log']) - key_path = os.path.join(dovetail_config['userconfig_dir'], 'id_rsa') - key_con_path = dovetail_config["yardstick"]['result']['key_path'] - key_vol = '-v %s:%s ' % (key_path, key_con_path) + + # for yardstick, support pod.yaml configuration + pod_file = os.path.join(dovetail_config['config_dir'], + dovetail_config['pod_file']) + if not os.path.isfile(pod_file): + cls.logger.error("File %s doesn't exist.", pod_file) + return None + key_file = os.path.join(dovetail_config['config_dir'], + dovetail_config['pri_key']) + key_container_path = dovetail_config["yardstick"]['result']['key_path'] + if not os.path.isfile(key_file): + cls.logger.debug("Key file %s is not found, maybe can use passwd " + "method in %s to do HA test.", key_file, pod_file) + key_vol = '' + else: + key_vol = '-v %s:%s ' % (key_file, key_container_path) return "%s %s %s" % (envs, log_vol, key_vol) @classmethod @@ -137,29 +152,43 @@ class Container(object): return None # for refstack, support user self_defined configuration - # for yardstick, support pod.yaml configuration - pod_file = os.path.join(dovetail_config['userconfig_dir'], 'pod.yaml') - if type.lower() == "yardstick" and not os.path.exists(pod_file): - cls.logger.error("File %s doesn't exist.", pod_file) - return None - key_file = os.path.join(dovetail_config['userconfig_dir'], 'id_rsa') - if type.lower() == "yardstick" and not os.path.exists(key_file): - cls.logger.debug("File %s doesn't exist.", key_file) - cls.logger.debug("Can just use password in %s.", pod_file) config_volume = \ - ' -v %s:%s ' % (dovetail_config['userconfig_dir'], - dovetail_config["functest"]['config']['dir']) + ' -v %s:%s ' % (os.getenv("DOVETAIL_HOME"), + dovetail_config[type]['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 = \ dt_utils.exec_cmd("sudo docker ps | grep " + docker_image + " | awk '{print $1}' | head -1", cls.logger) cls.container_list[type] = container_id + + if 'sdnvpn' in str(testcase_name): + prefix_path = dt_cfg.dovetail_config[type]['config']['dir'] + file_name = dt_cfg.dovetail_config['sdnvpn_image'] + src_path = os.path.join(prefix_path, 'pre_config', file_name) + dest_path = '/home/opnfv/functest/images' + Container.pre_copy(container_id, src_path, dest_path) return container_id @classmethod |