3 # Copyright (c) 2015 All rights reserved
4 # This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Execute Multisite Tempest test cases
17 import functest.utils.functest_utils as ft_utils
18 import functest.utils.functest_logger as ft_logger
19 from run_tempest import configure_tempest
20 from run_tempest import TEMPEST_RESULTS_DIR
22 logger = ft_logger.Logger("multisite").getLogger()
25 def configure_tempest_multisite(deployment_dir):
27 Add/update needed parameters into tempest.conf file generated by Rally
29 logger.debug("configure the tempest")
30 configure_tempest(deployment_dir)
32 logger.debug("Finding tempest.conf file...")
33 tempest_conf_file = deployment_dir + "/tempest.conf"
34 if not os.path.isfile(tempest_conf_file):
35 logger.error("Tempest configuration file %s NOT found."
39 # Copy tempest.conf to /home/opnfv/functest/results/tempest/
40 cur_path = os.path.split(os.path.realpath(__file__))[0]
41 shutil.copyfile(tempest_conf_file, cur_path + '/tempest_multisite.conf')
42 tempest_conf_file = cur_path + "/tempest_multisite.conf"
44 logger.debug("Updating selected tempest.conf parameters...")
45 config = ConfigParser.RawConfigParser()
46 config.read(tempest_conf_file)
48 config.set('service_available', 'kingbird', 'true')
49 cmd = "openstack endpoint show kingbird | grep publicurl |\
50 awk '{print $4}' | awk -F '/' '{print $4}'"
51 kingbird_api_version = os.popen(cmd).read()
52 if os.environ.get("INSTALLER_TYPE") == 'fuel':
53 # For MOS based setup, the service is accessible
55 kingbird_conf_path = "/etc/kingbird/kingbird.conf"
56 installer_type = os.getenv('INSTALLER_TYPE', 'Unknown')
57 installer_ip = os.getenv('INSTALLER_IP', 'Unknown')
58 installer_username = ft_utils.get_parameter_from_yaml(
59 "multisite." + installer_type +
60 "_environment.installer_username")
61 installer_password = ft_utils.get_parameter_from_yaml(
62 "multisite." + installer_type +
63 "_environment.installer_password")
65 ssh_options = "-o UserKnownHostsFile=/dev/null -o \
66 StrictHostKeyChecking=no"
68 # Get the controller IP from the fuel node
69 cmd = 'sshpass -p %s ssh 2>/dev/null %s %s@%s \
70 \'fuel node --env 1| grep controller | grep "True\| 1" \
71 | awk -F\| "{print \$5}"\'' % (installer_password,
75 multisite_controller_ip = \
76 "".join(os.popen(cmd).read().split())
78 # Login to controller and get bind host details
79 cmd = 'sshpass -p %s ssh 2>/dev/null %s %s@%s "ssh %s \\" \
80 grep -e "^bind_" %s \\""' % (installer_password,
84 multisite_controller_ip,
86 bind_details = os.popen(cmd).read()
87 bind_details = "".join(bind_details.split())
88 # Extract port number from the bind details
89 bind_port = re.findall(r"\D(\d{4})", bind_details)[0]
90 # Extract ip address from the bind details
91 bind_host = re.findall(r"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}",
93 kingbird_endpoint_url = "http://" + bind_host + ":" + bind_port + \
96 cmd = "openstack endpoint show kingbird | grep publicurl |\
97 awk '{print $4}' | awk -F '/' '{print $3}'"
98 kingbird_endpoint_url = os.popen(cmd).read()
101 config.add_section("kingbird")
103 logger.info('kingbird section exist')
104 config.set('kingbird', 'endpoint_type', 'publicURL')
105 config.set('kingbird', 'TIME_TO_SYNC', '20')
106 config.set('kingbird', 'endpoint_url', kingbird_endpoint_url)
107 config.set('kingbird', 'api_version', kingbird_api_version)
108 with open(tempest_conf_file, 'wb') as config_file:
109 config.write(config_file)
116 if not os.path.exists(TEMPEST_RESULTS_DIR):
117 os.makedirs(TEMPEST_RESULTS_DIR)
119 deployment_dir = ft_utils.get_deployment_dir(logger)
120 configure_tempest_multisite(deployment_dir)
123 if __name__ == '__main__':