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
16 from functest.utils.constants import CONST
17 import functest.utils.functest_logger as ft_logger
18 import functest.utils.functest_utils as ft_utils
19 import functest.utils.openstack_utils as os_utils
24 REPO_PATH = CONST.dir_repo_functest
25 GLANCE_IMAGE_PATH = os.path.join(CONST.dir_functest_data,
26 CONST.openstack_image_file_name)
27 TEMPEST_TEST_LIST_DIR = CONST.dir_tempest_cases
28 TEMPEST_RESULTS_DIR = os.path.join(CONST.dir_results,
30 TEMPEST_CUSTOM = os.path.join(REPO_PATH, TEMPEST_TEST_LIST_DIR,
32 TEMPEST_BLACKLIST = os.path.join(REPO_PATH, TEMPEST_TEST_LIST_DIR,
34 TEMPEST_DEFCORE = os.path.join(REPO_PATH, TEMPEST_TEST_LIST_DIR,
36 TEMPEST_RAW_LIST = os.path.join(TEMPEST_RESULTS_DIR, 'test_raw_list.txt')
37 TEMPEST_LIST = os.path.join(TEMPEST_RESULTS_DIR, 'test_list.txt')
39 CI_INSTALLER_TYPE = CONST.INSTALLER_TYPE
40 CI_INSTALLER_IP = CONST.INSTALLER_IP
42 """ logging configuration """
43 logger = ft_logger.Logger("Tempest").getLogger()
46 def get_verifier_id():
48 Returns verifer id for current Tempest
50 cmd = ("rally verify list-verifiers | awk '/" +
51 CONST.tempest_deployment_name +
53 p = subprocess.Popen(cmd, shell=True,
54 stdout=subprocess.PIPE,
55 stderr=subprocess.STDOUT)
56 deployment_uuid = p.stdout.readline().rstrip()
57 if deployment_uuid == "":
58 logger.error("Tempest verifier not found.")
59 raise Exception('Error with command:%s' % cmd)
60 return deployment_uuid
63 def get_verifier_deployment_id():
65 Returns deployment id for active Rally deployment
67 cmd = ("rally deployment list | awk '/" +
68 CONST.rally_deployment_name +
70 p = subprocess.Popen(cmd, shell=True,
71 stdout=subprocess.PIPE,
72 stderr=subprocess.STDOUT)
73 deployment_uuid = p.stdout.readline().rstrip()
74 if deployment_uuid == "":
75 logger.error("Rally deployment not found.")
76 raise Exception('Error with command:%s' % cmd)
77 return deployment_uuid
80 def get_verifier_repo_dir(verifier_id):
82 Returns installed verfier repo directory for Tempest
85 verifier_id = get_verifier_id()
87 return os.path.join(CONST.dir_rally_inst,
89 'verifier-{}'.format(verifier_id),
93 def get_verifier_deployment_dir(verifier_id, deployment_id):
95 Returns Rally deployment directory for current verifier
98 verifier_id = get_verifier_id()
100 if not deployment_id:
101 deployment_id = get_verifier_deployment_id()
103 return os.path.join(CONST.dir_rally_inst,
105 'verifier-{}'.format(verifier_id),
106 'for-deployment-{}'.format(deployment_id))
109 def backup_tempest_config(conf_file):
111 Copy config file to tempest results directory
113 if not os.path.exists(TEMPEST_RESULTS_DIR):
114 os.makedirs(TEMPEST_RESULTS_DIR)
116 shutil.copyfile(conf_file,
117 os.path.join(TEMPEST_RESULTS_DIR, 'tempest.conf'))
120 def configure_tempest(deployment_dir, IMAGE_ID=None, FLAVOR_ID=None,
123 Calls rally verify and updates the generated tempest.conf with
126 conf_file = configure_verifier(deployment_dir)
127 configure_tempest_update_params(conf_file,
129 if MODE == 'feature_multisite':
130 configure_tempest_multisite_params(conf_file)
133 def configure_tempest_update_params(tempest_conf_file,
134 IMAGE_ID=None, FLAVOR_ID=None):
136 Add/update needed parameters into tempest.conf file
138 logger.debug("Updating selected tempest.conf parameters...")
139 config = ConfigParser.RawConfigParser()
140 config.read(tempest_conf_file)
143 'fixed_network_name',
144 CONST.tempest_private_net_name)
145 if CONST.tempest_use_custom_images:
146 if IMAGE_ID is not None:
147 config.set('compute', 'image_ref', IMAGE_ID)
148 if IMAGE_ID_ALT is not None:
149 config.set('compute', 'image_ref_alt', IMAGE_ID_ALT)
150 if CONST.tempest_use_custom_flavors:
151 if FLAVOR_ID is not None:
152 config.set('compute', 'flavor_ref', FLAVOR_ID)
153 if FLAVOR_ID_ALT is not None:
154 config.set('compute', 'flavor_ref_alt', FLAVOR_ID_ALT)
155 config.set('identity', 'tenant_name', CONST.tempest_identity_tenant_name)
156 config.set('identity', 'username', CONST.tempest_identity_user_name)
157 config.set('identity', 'password', CONST.tempest_identity_user_password)
159 'validation', 'ssh_timeout', CONST.tempest_validation_ssh_timeout)
160 config.set('object-storage', 'operator_role',
161 CONST.tempest_object_storage_operator_role)
163 if CONST.OS_ENDPOINT_TYPE is not None:
164 services_list = ['compute',
171 sections = config.sections()
172 for service in services_list:
173 if service not in sections:
174 config.add_section(service)
175 config.set(service, 'endpoint_type',
176 CONST.OS_ENDPOINT_TYPE)
178 with open(tempest_conf_file, 'wb') as config_file:
179 config.write(config_file)
181 backup_tempest_config(tempest_conf_file)
184 def configure_verifier(deployment_dir):
186 Execute rally verify configure-verifier, which generates tempest.conf
188 tempest_conf_file = os.path.join(deployment_dir, "tempest.conf")
189 if os.path.isfile(tempest_conf_file):
190 logger.debug("Verifier is already configured.")
191 logger.debug("Reconfiguring the current verifier...")
192 cmd = "rally verify configure-verifier --reconfigure"
194 logger.info("Configuring the verifier...")
195 cmd = "rally verify configure-verifier"
196 ft_utils.execute_command(cmd)
198 logger.debug("Looking for tempest.conf file...")
199 if not os.path.isfile(tempest_conf_file):
200 logger.error("Tempest configuration file %s NOT found."
202 raise Exception("Tempest configuration file %s NOT found."
205 return tempest_conf_file
208 def configure_tempest_multisite_params(tempest_conf_file):
210 Add/update multisite parameters into tempest.conf file generated by Rally
212 logger.debug("Updating multisite tempest.conf parameters...")
213 config = ConfigParser.RawConfigParser()
214 config.read(tempest_conf_file)
216 config.set('service_available', 'kingbird', 'true')
217 # cmd = ("openstack endpoint show kingbird | grep publicurl |"
218 # "awk '{print $4}' | awk -F '/' '{print $4}'")
219 # kingbird_api_version = os.popen(cmd).read()
220 kingbird_api_version = os_utils.get_endpoint(service_type='multisite')
222 if CI_INSTALLER_TYPE == 'fuel':
223 # For MOS based setup, the service is accessible
225 kingbird_conf_path = "/etc/kingbird/kingbird.conf"
226 installer_type = CI_INSTALLER_TYPE
227 installer_ip = CI_INSTALLER_IP
228 installer_username = CONST.__getattribute__(
229 'multisite_{}_installer_username'.format(installer_type))
230 installer_password = CONST.__getattribute__(
231 'multisite_{}_installer_password'.format(installer_type))
233 ssh_options = ("-o UserKnownHostsFile=/dev/null -o "
234 "StrictHostKeyChecking=no")
236 # Get the controller IP from the fuel node
237 cmd = 'sshpass -p %s ssh 2>/dev/null %s %s@%s \
238 \'fuel node --env 1| grep controller | grep "True\| 1" \
239 | awk -F\| "{print \$5}"\'' % (installer_password,
243 multisite_controller_ip = "".join(os.popen(cmd).read().split())
245 # Login to controller and get bind host details
246 cmd = 'sshpass -p %s ssh 2>/dev/null %s %s@%s "ssh %s \\" \
247 grep -e "^bind_" %s \\""' % (installer_password,
251 multisite_controller_ip,
253 bind_details = os.popen(cmd).read()
254 bind_details = "".join(bind_details.split())
255 # Extract port number from the bind details
256 bind_port = re.findall(r"\D(\d{4})", bind_details)[0]
257 # Extract ip address from the bind details
258 bind_host = re.findall(r"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}",
260 kingbird_endpoint_url = "http://%s:%s/" % (bind_host, bind_port)
262 # cmd = "openstack endpoint show kingbird | grep publicurl |\
263 # awk '{print $4}' | awk -F '/' '{print $3}'"
264 # kingbird_endpoint_url = os.popen(cmd).read()
265 kingbird_endpoint_url = os_utils.get_endpoint(service_type='kingbird')
268 config.add_section("kingbird")
270 logger.info('kingbird section exist')
271 config.set('kingbird', 'endpoint_type', 'publicURL')
272 config.set('kingbird', 'TIME_TO_SYNC', '20')
273 config.set('kingbird', 'endpoint_url', kingbird_endpoint_url)
274 config.set('kingbird', 'api_version', kingbird_api_version)
275 with open(tempest_conf_file, 'wb') as config_file:
276 config.write(config_file)
278 backup_tempest_config(tempest_conf_file)