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
15 import opnfv.utils.constants as releng_constants
17 from functest.utils.constants import CONST
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
43 def configure_tempest(logger, deployment_dir, IMAGE_ID=None, FLAVOR_ID=None):
45 Add/update needed parameters into tempest.conf file generated by Rally
47 tempest_conf_file = os.path.join(deployment_dir, "tempest.conf")
48 if os.path.isfile(tempest_conf_file):
49 logger.debug("Verifier is already configured.")
50 logger.debug("Reconfiguring the current verifier...")
51 cmd = "rally verify configure-verifier --reconfigure"
53 logger.info("Configuring the verifier...")
54 cmd = "rally verify configure-verifier"
55 ft_utils.execute_command(cmd)
57 logger.debug("Looking for tempest.conf file...")
58 if not os.path.isfile(tempest_conf_file):
59 logger.error("Tempest configuration file %s NOT found."
61 return releng_constants.EXIT_RUN_ERROR
63 logger.debug("Updating selected tempest.conf parameters...")
64 config = ConfigParser.RawConfigParser()
65 config.read(tempest_conf_file)
69 CONST.tempest_private_net_name)
70 if CONST.tempest_use_custom_images:
71 if IMAGE_ID is not None:
72 config.set('compute', 'image_ref', IMAGE_ID)
73 if IMAGE_ID_ALT is not None:
74 config.set('compute', 'image_ref_alt', IMAGE_ID_ALT)
75 if CONST.tempest_use_custom_flavors:
76 if FLAVOR_ID is not None:
77 config.set('compute', 'flavor_ref', FLAVOR_ID)
78 if FLAVOR_ID_ALT is not None:
79 config.set('compute', 'flavor_ref_alt', FLAVOR_ID_ALT)
80 config.set('identity', 'tenant_name', CONST.tempest_identity_tenant_name)
81 config.set('identity', 'username', CONST.tempest_identity_user_name)
82 config.set('identity', 'password', CONST.tempest_identity_user_password)
84 'validation', 'ssh_timeout', CONST.tempest_validation_ssh_timeout)
86 if CONST.OS_ENDPOINT_TYPE is not None:
87 services_list = ['compute',
94 sections = config.sections()
95 for service in services_list:
96 if service not in sections:
97 config.add_section(service)
98 config.set(service, 'endpoint_type',
99 CONST.OS_ENDPOINT_TYPE)
101 with open(tempest_conf_file, 'wb') as config_file:
102 config.write(config_file)
104 # Copy tempest.conf to /home/opnfv/functest/results/tempest/
105 shutil.copyfile(tempest_conf_file,
106 os.path.join(TEMPEST_RESULTS_DIR, 'tempest.conf'))
108 return releng_constants.EXIT_OK
111 def configure_tempest_multisite(logger, deployment_dir):
113 Add/update needed parameters into tempest.conf file generated by Rally
115 logger.debug("configure the tempest")
116 configure_tempest(logger, deployment_dir)
118 logger.debug("Finding tempest.conf file...")
119 tempest_conf_old = os.path.join(deployment_dir, 'tempest.conf')
120 if not os.path.isfile(tempest_conf_old):
121 logger.error("Tempest configuration file %s NOT found."
123 return releng_constants.EXIT_RUN_ERROR
125 # Copy tempest.conf to /home/opnfv/functest/results/tempest/
126 cur_path = os.path.split(os.path.realpath(__file__))[0]
127 tempest_conf_file = os.path.join(cur_path, 'tempest_multisite.conf')
128 shutil.copyfile(tempest_conf_old, tempest_conf_file)
130 logger.debug("Updating selected tempest.conf parameters...")
131 config = ConfigParser.RawConfigParser()
132 config.read(tempest_conf_file)
134 config.set('service_available', 'kingbird', 'true')
135 # cmd = ("openstack endpoint show kingbird | grep publicurl |"
136 # "awk '{print $4}' | awk -F '/' '{print $4}'")
137 # kingbird_api_version = os.popen(cmd).read()
138 kingbird_api_version = os_utils.get_endpoint(service_type='kingbird')
140 if CI_INSTALLER_TYPE == 'fuel':
141 # For MOS based setup, the service is accessible
143 kingbird_conf_path = "/etc/kingbird/kingbird.conf"
144 installer_type = CI_INSTALLER_TYPE
145 installer_ip = CI_INSTALLER_IP
146 installer_username = CONST.__getattribute__(
147 'multisite_{}_installer_username'.format(installer_type))
148 installer_password = CONST.__getattribute__(
149 'multisite_{}_installer_password'.format(installer_type))
151 ssh_options = ("-o UserKnownHostsFile=/dev/null -o "
152 "StrictHostKeyChecking=no")
154 # Get the controller IP from the fuel node
155 cmd = 'sshpass -p %s ssh 2>/dev/null %s %s@%s \
156 \'fuel node --env 1| grep controller | grep "True\| 1" \
157 | awk -F\| "{print \$5}"\'' % (installer_password,
161 multisite_controller_ip = "".join(os.popen(cmd).read().split())
163 # Login to controller and get bind host details
164 cmd = 'sshpass -p %s ssh 2>/dev/null %s %s@%s "ssh %s \\" \
165 grep -e "^bind_" %s \\""' % (installer_password,
169 multisite_controller_ip,
171 bind_details = os.popen(cmd).read()
172 bind_details = "".join(bind_details.split())
173 # Extract port number from the bind details
174 bind_port = re.findall(r"\D(\d{4})", bind_details)[0]
175 # Extract ip address from the bind details
176 bind_host = re.findall(r"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}",
178 kingbird_endpoint_url = "http://%s:%s/" % (bind_host, bind_port)
180 # cmd = "openstack endpoint show kingbird | grep publicurl |\
181 # awk '{print $4}' | awk -F '/' '{print $3}'"
182 # kingbird_endpoint_url = os.popen(cmd).read()
183 kingbird_endpoint_url = os_utils.get_endpoint(service_type='kingbird')
186 config.add_section("kingbird")
188 logger.info('kingbird section exist')
189 config.set('kingbird', 'endpoint_type', 'publicURL')
190 config.set('kingbird', 'TIME_TO_SYNC', '20')
191 config.set('kingbird', 'endpoint_url', kingbird_endpoint_url)
192 config.set('kingbird', 'api_version', kingbird_api_version)
193 with open(tempest_conf_file, 'wb') as config_file:
194 config.write(config_file)
196 return releng_constants.EXIT_OK