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
19 from functest.utils.constants import CONST
20 import functest.utils.functest_utils as ft_utils
21 import functest.utils.openstack_utils as os_utils
26 GLANCE_IMAGE_PATH = os.path.join(
27 CONST.__getattribute__('dir_functest_images'),
28 CONST.__getattribute__('openstack_image_file_name'))
29 TEMPEST_RESULTS_DIR = os.path.join(CONST.__getattribute__('dir_results'),
31 TEMPEST_CUSTOM = pkg_resources.resource_filename(
32 'functest', 'opnfv_tests/openstack/tempest/custom_tests/test_list.txt')
33 TEMPEST_BLACKLIST = pkg_resources.resource_filename(
34 'functest', 'opnfv_tests/openstack/tempest/custom_tests/blacklist.txt')
35 TEMPEST_DEFCORE = pkg_resources.resource_filename(
37 'opnfv_tests/openstack/tempest/custom_tests/defcore_req.txt')
38 TEMPEST_RAW_LIST = os.path.join(TEMPEST_RESULTS_DIR, 'test_raw_list.txt')
39 TEMPEST_LIST = os.path.join(TEMPEST_RESULTS_DIR, 'test_list.txt')
40 REFSTACK_RESULTS_DIR = os.path.join(CONST.__getattribute__('dir_results'),
42 TEMPEST_CONF_YAML = pkg_resources.resource_filename(
43 'functest', 'opnfv_tests/openstack/tempest/custom_tests/tempest_conf.yaml')
44 TEST_ACCOUNTS_FILE = pkg_resources.resource_filename(
46 'opnfv_tests/openstack/tempest/custom_tests/test_accounts.yaml')
48 CI_INSTALLER_TYPE = CONST.__getattribute__('INSTALLER_TYPE')
49 CI_INSTALLER_IP = CONST.__getattribute__('INSTALLER_IP')
51 """ logging configuration """
52 logger = logging.getLogger(__name__)
55 def get_verifier_id():
57 Returns verifier id for current Tempest
59 cmd = ("rally verify list-verifiers | awk '/" +
60 CONST.__getattribute__('tempest_deployment_name') +
62 p = subprocess.Popen(cmd, shell=True,
63 stdout=subprocess.PIPE,
64 stderr=subprocess.STDOUT)
65 deployment_uuid = p.stdout.readline().rstrip()
66 if deployment_uuid == "":
67 logger.error("Tempest verifier not found.")
68 raise Exception('Error with command:%s' % cmd)
69 return deployment_uuid
72 def get_verifier_deployment_id():
74 Returns deployment id for active Rally deployment
76 cmd = ("rally deployment list | awk '/" +
77 CONST.__getattribute__('rally_deployment_name') +
79 p = subprocess.Popen(cmd, shell=True,
80 stdout=subprocess.PIPE,
81 stderr=subprocess.STDOUT)
82 deployment_uuid = p.stdout.readline().rstrip()
83 if deployment_uuid == "":
84 logger.error("Rally deployment not found.")
85 raise Exception('Error with command:%s' % cmd)
86 return deployment_uuid
89 def get_verifier_repo_dir(verifier_id):
91 Returns installed verifier repo directory for Tempest
94 verifier_id = get_verifier_id()
96 return os.path.join(CONST.__getattribute__('dir_rally_inst'),
98 'verifier-{}'.format(verifier_id),
102 def get_verifier_deployment_dir(verifier_id, deployment_id):
104 Returns Rally deployment directory for current verifier
107 verifier_id = get_verifier_id()
109 if not deployment_id:
110 deployment_id = get_verifier_deployment_id()
112 return os.path.join(CONST.__getattribute__('dir_rally_inst'),
114 'verifier-{}'.format(verifier_id),
115 'for-deployment-{}'.format(deployment_id))
118 def get_repo_tag(repo):
120 Returns last tag of current branch
122 cmd = ("git -C {0} describe --abbrev=0 HEAD".format(repo))
123 p = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True)
124 tag = p.stdout.readline().rstrip()
129 def backup_tempest_config(conf_file):
131 Copy config file to tempest results directory
133 shutil.copyfile(conf_file,
134 os.path.join(TEMPEST_RESULTS_DIR, 'tempest.conf'))
137 def configure_tempest(deployment_dir, image_id=None, flavor_id=None,
140 Calls rally verify and updates the generated tempest.conf with
143 conf_file = configure_verifier(deployment_dir)
144 configure_tempest_update_params(conf_file, image_id, flavor_id,
148 def configure_tempest_defcore(deployment_dir, image_id, flavor_id,
149 image_id_alt, flavor_id_alt, tenant_id):
151 Add/update needed parameters into tempest.conf file
153 conf_file = configure_verifier(deployment_dir)
154 configure_tempest_update_params(conf_file, image_id, flavor_id)
156 logger.debug("Updating selected tempest.conf parameters for defcore...")
157 config = ConfigParser.RawConfigParser()
158 config.read(conf_file)
159 config.set('DEFAULT', 'log_file', '{}/tempest.log'.format(deployment_dir))
160 config.set('oslo_concurrency', 'lock_path',
161 '{}/lock_files'.format(deployment_dir))
162 generate_test_accounts_file(tenant_id=tenant_id)
163 config.set('auth', 'test_accounts_file', TEST_ACCOUNTS_FILE)
164 config.set('scenario', 'img_dir', '{}'.format(deployment_dir))
165 config.set('scenario', 'img_file', 'tempest-image')
166 config.set('compute', 'image_ref', image_id)
167 config.set('compute', 'image_ref_alt', image_id_alt)
168 config.set('compute', 'flavor_ref', flavor_id)
169 config.set('compute', 'flavor_ref_alt', flavor_id_alt)
171 with open(conf_file, 'wb') as config_file:
172 config.write(config_file)
174 confpath = pkg_resources.resource_filename(
176 'opnfv_tests/openstack/refstack_client/refstack_tempest.conf')
177 shutil.copyfile(conf_file, confpath)
180 def generate_test_accounts_file(tenant_id):
182 Add needed tenant and user params into test_accounts.yaml
185 logger.debug("Add needed params into test_accounts.yaml...")
189 CONST.__getattribute__('tempest_identity_tenant_name'),
190 'tenant_id': str(tenant_id),
191 'username': CONST.__getattribute__('tempest_identity_user_name'),
193 CONST.__getattribute__('tempest_identity_user_password')
197 with open(TEST_ACCOUNTS_FILE, "w") as f:
198 yaml.dump(accounts_list, f, default_flow_style=False)
201 def configure_tempest_update_params(tempest_conf_file, image_id=None,
202 flavor_id=None, compute_cnt=1):
204 Add/update needed parameters into tempest.conf file
206 logger.debug("Updating selected tempest.conf parameters...")
207 config = ConfigParser.RawConfigParser()
208 config.read(tempest_conf_file)
211 'fixed_network_name',
212 CONST.__getattribute__('tempest_private_net_name'))
213 config.set('compute', 'volume_device_name',
214 CONST.__getattribute__('tempest_volume_device_name'))
215 if CONST.__getattribute__('tempest_use_custom_images'):
216 if image_id is not None:
217 config.set('compute', 'image_ref', image_id)
218 if IMAGE_ID_ALT is not None:
219 config.set('compute', 'image_ref_alt', IMAGE_ID_ALT)
220 if CONST.__getattribute__('tempest_use_custom_flavors'):
221 if flavor_id is not None:
222 config.set('compute', 'flavor_ref', flavor_id)
223 if FLAVOR_ID_ALT is not None:
224 config.set('compute', 'flavor_ref_alt', FLAVOR_ID_ALT)
226 # enable multinode tests
227 config.set('compute', 'min_compute_nodes', compute_cnt)
229 config.set('identity', 'region', 'RegionOne')
230 if os_utils.is_keystone_v3():
234 config.set('identity', 'auth_version', auth_version)
236 'validation', 'ssh_timeout',
237 CONST.__getattribute__('tempest_validation_ssh_timeout'))
238 config.set('object-storage', 'operator_role',
239 CONST.__getattribute__('tempest_object_storage_operator_role'))
241 if CONST.__getattribute__('OS_ENDPOINT_TYPE') is not None:
242 sections = config.sections()
243 if os_utils.is_keystone_v3():
244 config.set('identity', 'v3_endpoint_type',
245 CONST.__getattribute__('OS_ENDPOINT_TYPE'))
246 if 'identity-feature-enabled' not in sections:
247 config.add_section('identity-feature-enabled')
248 config.set('identity-feature-enabled', 'api_v2', False)
249 config.set('identity-feature-enabled', 'api_v2_admin', False)
250 services_list = ['compute',
257 for service in services_list:
258 if service not in sections:
259 config.add_section(service)
260 config.set(service, 'endpoint_type',
261 CONST.__getattribute__('OS_ENDPOINT_TYPE'))
263 logger.debug('Add/Update required params defined in tempest_conf.yaml '
264 'into tempest.conf file')
265 with open(TEMPEST_CONF_YAML) as f:
266 conf_yaml = yaml.safe_load(f)
268 sections = config.sections()
269 for section in conf_yaml:
270 if section not in sections:
271 config.add_section(section)
272 sub_conf = conf_yaml.get(section)
273 for key, value in sub_conf.items():
274 config.set(section, key, value)
276 with open(tempest_conf_file, 'wb') as config_file:
277 config.write(config_file)
279 backup_tempest_config(tempest_conf_file)
282 def configure_verifier(deployment_dir):
284 Execute rally verify configure-verifier, which generates tempest.conf
286 tempest_conf_file = os.path.join(deployment_dir, "tempest.conf")
287 if os.path.isfile(tempest_conf_file):
288 logger.debug("Verifier is already configured.")
289 logger.debug("Reconfiguring the current verifier...")
290 cmd = "rally verify configure-verifier --reconfigure"
292 logger.info("Configuring the verifier...")
293 cmd = "rally verify configure-verifier"
294 ft_utils.execute_command(cmd)
296 logger.debug("Looking for tempest.conf file...")
297 if not os.path.isfile(tempest_conf_file):
298 logger.error("Tempest configuration file %s NOT found."
300 raise Exception("Tempest configuration file %s NOT found."
303 return tempest_conf_file