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,
41 # update the external_network
45 def file_copy(src_file, dest_file):
46 src = file(src_file, "r+")
47 des = file(dest_file, "w+")
48 des.writelines(src.read())
53 def _get_remote_rc_file(rc_file, installer_ip, installer_type):
55 RELENG_DIR = config.bottlenecks_config["releng_dir"]
56 OS_FETCH_SCRIPT = config.bottlenecks_config["fetch_os"]
57 os_fetch_script = os.path.join(RELENG_DIR, OS_FETCH_SCRIPT)
60 cmd = [os_fetch_script, '-d', rc_file, '-i', installer_type,
62 p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
66 LOG.debug('Failed to fetch credentials from installer')
68 if e.errno != errno.EEXIST:
72 def _source_file(rc_file):
73 p = subprocess.Popen(". %s; env" % rc_file, stdout=subprocess.PIPE,
75 output = p.communicate()[0]
76 env = dict((line.split('=', 1) for line in output.splitlines()))
77 os.environ.update(env)
81 def _append_external_network(rc_file):
82 neutron_client = utils._get_neutron_client()
83 networks = neutron_client.list_networks()['networks']
85 ext_network = next(n['name'] for n in networks if n['router:external'])
87 LOG.warning("Can't find external network")
89 cmd = 'export EXTERNAL_NETWORK=%s' % ext_network
91 with open(rc_file, 'a') as f:
94 if e.errno != errno.EEXIST: