From 7535dc21abcdc90c9ff54fe6b9280a659ad4604f Mon Sep 17 00:00:00 2001 From: xudan Date: Thu, 31 Aug 2017 02:20:25 -0400 Subject: Bugfix: the config files in useeconfig will cover user's config 1. Now there are 2 sample files tempest_conf.yaml and hosts.yaml in userconfig, and thet will cover user's tempest_conf.yaml and hosts.yaml in $DOVETAIL_HOME/pre_config. 2. Rename the files in userconfig to be tempest_conf.yaml.sample and hosts.yaml.sample. 3. Add the hosts info in file /etc/hosts in Dovetail Container. JIRA: DOVETAIL-492 Change-Id: I2b5694a8058b864b510925eec595d6f2bd1062ff Signed-off-by: xudan --- dovetail/container.py | 33 ++++++++++++++-------------- dovetail/userconfig/hosts.yaml | 2 -- dovetail/userconfig/hosts.yaml.sample | 2 ++ dovetail/userconfig/tempest_conf.yaml | 16 -------------- dovetail/userconfig/tempest_conf.yaml.sample | 16 ++++++++++++++ dovetail/utils/dovetail_utils.py | 6 +++++ 6 files changed, 41 insertions(+), 34 deletions(-) delete mode 100644 dovetail/userconfig/hosts.yaml create mode 100644 dovetail/userconfig/hosts.yaml.sample delete mode 100644 dovetail/userconfig/tempest_conf.yaml create mode 100644 dovetail/userconfig/tempest_conf.yaml.sample diff --git a/dovetail/container.py b/dovetail/container.py index f3d08373..cf8e14e5 100644 --- a/dovetail/container.py +++ b/dovetail/container.py @@ -153,6 +153,23 @@ class Container(object): envs = envs + ' -e BUILD_TAG=%s-%s' % (dovetail_config['build_tag'], testcase_name) + hosts_config = "" + hosts_config_file = os.path.join(dovetail_config['config_dir'], + 'hosts.yaml') + try: + with open(hosts_config_file) as f: + hosts_info = yaml.safe_load(f) + if hosts_info['hosts_info']: + for host in hosts_info['hosts_info']: + dt_utils.add_hosts_info(host) + hosts_config += " --add-host " + hosts_config += str(host) + cls.logger.info('Get hosts info {}.'.format(hosts_config)) + except Exception: + cls.logger.warn('Failed to get hosts info in {}, ' + 'maybe some issues with domain name resolution.' + .format(hosts_config_file)) + config = "" if type.lower() == "functest": config = cls.set_functest_config(testcase_name) @@ -168,22 +185,6 @@ class Container(object): ' -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__), '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 {}.'.format(hosts_config)) - except Exception: - cls.logger.warn('Failed to get hosts info in {}/hosts.yaml, ' - 'maybe some issues with domain name resolution.' - .format(hosts_config_path)) - cacert_volume = "" https_enabled = dt_utils.check_https_enabled(cls.logger) cacert = os.getenv('OS_CACERT',) diff --git a/dovetail/userconfig/hosts.yaml b/dovetail/userconfig/hosts.yaml deleted file mode 100644 index e4687dfb..00000000 --- a/dovetail/userconfig/hosts.yaml +++ /dev/null @@ -1,2 +0,0 @@ ---- -hosts_info: diff --git a/dovetail/userconfig/hosts.yaml.sample b/dovetail/userconfig/hosts.yaml.sample new file mode 100644 index 00000000..e4687dfb --- /dev/null +++ b/dovetail/userconfig/hosts.yaml.sample @@ -0,0 +1,2 @@ +--- +hosts_info: diff --git a/dovetail/userconfig/tempest_conf.yaml b/dovetail/userconfig/tempest_conf.yaml deleted file mode 100644 index 944e3a9f..00000000 --- a/dovetail/userconfig/tempest_conf.yaml +++ /dev/null @@ -1,16 +0,0 @@ -# This is an empty configuration file to be filled up with the desired options -# to generate a custom tempest.conf -# Examples: -# network-feature-enabled: -# port_security: True - -# volume-feature-enabled: -# api_v1: False - -# validation: -# image_ssh_user: root -# ssh_timeout: 300 - -# compute: -# min_compute_nodes: 2 -# volume_device_name: vdb diff --git a/dovetail/userconfig/tempest_conf.yaml.sample b/dovetail/userconfig/tempest_conf.yaml.sample new file mode 100644 index 00000000..944e3a9f --- /dev/null +++ b/dovetail/userconfig/tempest_conf.yaml.sample @@ -0,0 +1,16 @@ +# This is an empty configuration file to be filled up with the desired options +# to generate a custom tempest.conf +# Examples: +# network-feature-enabled: +# port_security: True + +# volume-feature-enabled: +# api_v1: False + +# validation: +# image_ssh_user: root +# ssh_timeout: 300 + +# compute: +# min_compute_nodes: 2 +# volume_device_name: vdb diff --git a/dovetail/utils/dovetail_utils.py b/dovetail/utils/dovetail_utils.py index 2c7ac317..23285e3c 100644 --- a/dovetail/utils/dovetail_utils.py +++ b/dovetail/utils/dovetail_utils.py @@ -208,3 +208,9 @@ def check_docker_version(logger=None): if client_ret != 0 or (LooseVersion(client_ver) < LooseVersion('1.12.3')): logger.error("Don't support this Docker client version. " "Docker client should be updated to at least 1.12.3.") + + +def add_hosts_info(hosts_info): + hosts_file = '/etc/hosts' + with open(hosts_file, 'a') as f: + f.write("{}\n".format(hosts_info)) -- cgit 1.2.3-korg