2 ##############################################################################
3 # Copyright (c) 2017 Huawei Technologies Co.,Ltd and others.
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
9 ##############################################################################
13 from utils.logger import Logger
14 from utils.parser import Parser as config
15 import utils.infra_setup.heat.manager as utils
16 import utils.infra_setup.runner.docker_env as docker_env
18 LOG = Logger(__name__).getLogger()
21 def _prepare_env_daemon(test_yardstick):
23 rc_file = config.bottlenecks_config["rc_dir"]
25 if not os.path.exists(rc_file):
26 installer_ip = os.environ.get('INSTALLER_IP', 'undefined')
27 installer_type = os.environ.get('INSTALLER_TYPE', 'undefined')
28 _get_remote_rc_file(rc_file, installer_ip, installer_type)
32 if not os.environ.get("EXTERNAL_NETWORK"):
33 _append_external_network(rc_file)
35 yardstick_contain = docker_env.yardstick_info["container"]
36 cmd = "cp %s %s" % (rc_file,
37 config.bottlenecks_config["yardstick_rc_dir"])
38 docker_env.docker_exec_cmd(yardstick_contain,
40 file_orig = ("/home/opnfv/repos/yardstick/etc"
41 "/yardstick/yardstick.conf.sample")
42 file_after = "/etc/yardstick/yardstick.conf"
43 cmd = "cp %s %s" % (file_orig,
45 docker_env.docker_exec_cmd(yardstick_contain,
47 cmd = "sed -i '12s/http/file/g' /etc/yardstick/yardstick.conf"
48 docker_env.docker_exec_cmd(yardstick_contain,
51 # update the external_network
55 def file_copy(src_file, dest_file):
56 src = file(src_file, "r+")
57 des = file(dest_file, "w+")
58 des.writelines(src.read())
63 def _get_remote_rc_file(rc_file, installer_ip, installer_type):
65 RELENG_DIR = config.bottlenecks_config["releng_dir"]
66 OS_FETCH_SCRIPT = config.bottlenecks_config["fetch_os"]
67 os_fetch_script = os.path.join(RELENG_DIR, OS_FETCH_SCRIPT)
70 cmd = [os_fetch_script, '-d', rc_file, '-i', installer_type,
72 p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
76 LOG.debug('Failed to fetch credentials from installer')
78 if e.errno != errno.EEXIST:
82 def _source_file(rc_file):
83 p = subprocess.Popen(". %s; env" % rc_file, stdout=subprocess.PIPE,
85 output = p.communicate()[0]
86 env = dict((line.split('=', 1) for line in output.splitlines()))
87 os.environ.update(env)
91 def _append_external_network(rc_file):
92 neutron_client = utils._get_neutron_client()
93 networks = neutron_client.list_networks()['networks']
95 ext_network = next(n['name'] for n in networks if n['router:external'])
97 LOG.warning("Can't find external network")
99 cmd = 'export EXTERNAL_NETWORK=%s' % ext_network
101 with open(rc_file, 'a') as f:
104 if e.errno != errno.EEXIST: