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
11 """Tempest testcases implementation."""
13 from __future__ import division
24 from six.moves import configparser
25 from xtesting.core import testcase
28 from functest.core import singlevm
29 from functest.opnfv_tests.openstack.rally import rally
30 from functest.utils import config
31 from functest.utils import env
32 from functest.utils import functest_utils
34 LOGGER = logging.getLogger(__name__)
37 class TempestCommon(singlevm.VmReady2):
38 # pylint: disable=too-many-instance-attributes,too-many-public-methods
39 """TempestCommon testcases implementation class."""
42 filename_alt = '/home/opnfv/functest/images/cirros-0.4.0-x86_64-disk.img'
44 tempest_conf_yaml = pkg_resources.resource_filename(
46 'opnfv_tests/openstack/tempest/custom_tests/tempest_conf.yaml')
47 tempest_custom = pkg_resources.resource_filename(
49 'opnfv_tests/openstack/tempest/custom_tests/test_list.txt')
50 tempest_blacklist = pkg_resources.resource_filename(
52 'opnfv_tests/openstack/tempest/custom_tests/blacklist.yaml')
53 tempest_public_blacklist = pkg_resources.resource_filename(
55 'opnfv_tests/openstack/tempest/custom_tests/public_blacklist.yaml')
57 def __init__(self, **kwargs):
58 if "case_name" not in kwargs:
59 kwargs["case_name"] = 'tempest'
60 super(TempestCommon, self).__init__(**kwargs)
61 assert self.orig_cloud
64 if self.orig_cloud.get_role("admin"):
65 self.role_name = "admin"
66 elif self.orig_cloud.get_role("Admin"):
67 self.role_name = "Admin"
69 raise Exception("Cannot detect neither admin nor Admin")
70 self.orig_cloud.grant_role(
71 self.role_name, user=self.project.user.id,
72 project=self.project.project.id,
73 domain=self.project.domain.id)
74 self.orig_cloud.grant_role(
75 self.role_name, user=self.project.user.id,
76 domain=self.project.domain.id)
77 self.deployment_id = None
78 self.verifier_id = None
79 self.verifier_repo_dir = None
80 self.deployment_dir = None
81 self.verification_id = None
82 self.res_dir = os.path.join(
83 getattr(config.CONF, 'dir_results'), self.case_name)
84 self.raw_list = os.path.join(self.res_dir, 'test_raw_list.txt')
85 self.list = os.path.join(self.res_dir, 'test_list.txt')
88 self.flavor_alt = None
91 self.services = kwargs['run']['args']['services']
92 except Exception: # pylint: disable=broad-except
94 self.neutron_extensions = []
96 self.neutron_extensions = kwargs['run']['args'][
98 except Exception: # pylint: disable=broad-except
100 self.deny_skipping = kwargs.get("deny_skipping", False)
101 self.tests_count = kwargs.get("tests_count", 0)
103 def check_services(self):
104 """Check the mandatory services."""
105 for service in self.services:
107 self.cloud.search_services(service)[0]
108 except Exception: # pylint: disable=broad-except
109 self.is_skipped = True
112 def check_extensions(self):
113 """Check the mandatory network extensions."""
114 extensions = self.cloud.get_network_extensions()
115 for network_extension in self.neutron_extensions:
116 if network_extension not in extensions:
118 "Cannot find Neutron extension: %s", network_extension)
119 self.is_skipped = True
122 def check_requirements(self):
123 self.check_services()
124 self.check_extensions()
129 def read_file(filename):
130 """Read file and return content as a stripped list."""
131 with open(filename) as src:
132 return [line.strip() for line in src.readlines()]
135 def get_verifier_result(verif_id):
136 """Retrieve verification results."""
143 cmd = ["rally", "verify", "show", "--uuid", verif_id]
144 LOGGER.info("Showing result for a verification: '%s'.", cmd)
145 proc = subprocess.Popen(cmd,
146 stdout=subprocess.PIPE,
147 stderr=subprocess.STDOUT)
148 for line in proc.stdout:
149 LOGGER.info(line.decode("utf-8").rstrip())
150 new_line = line.decode("utf-8").replace(' ', '').split('|')
151 if 'Tests' in new_line:
153 if 'Testscount' in new_line:
154 result['num_tests'] = int(new_line[2])
155 elif 'Success' in new_line:
156 result['num_success'] = int(new_line[2])
157 elif 'Skipped' in new_line:
158 result['num_skipped'] = int(new_line[2])
159 elif 'Failures' in new_line:
160 result['num_failures'] = int(new_line[2])
164 def backup_tempest_config(conf_file, res_dir):
166 Copy config file to tempest results directory
168 if not os.path.exists(res_dir):
170 shutil.copyfile(conf_file,
171 os.path.join(res_dir, 'tempest.conf'))
174 def create_verifier():
175 """Create new verifier"""
176 LOGGER.info("Create verifier from existing repo...")
177 cmd = ['rally', 'verify', 'delete-verifier',
178 '--id', str(getattr(config.CONF, 'tempest_verifier_name')),
181 output = subprocess.check_output(cmd)
182 LOGGER.info("%s\n%s", " ".join(cmd), output.decode("utf-8"))
183 except subprocess.CalledProcessError:
186 cmd = ['rally', 'verify', 'create-verifier',
187 '--source', str(getattr(config.CONF, 'dir_repo_tempest')),
188 '--name', str(getattr(config.CONF, 'tempest_verifier_name')),
189 '--type', 'tempest', '--system-wide']
190 output = subprocess.check_output(cmd)
191 LOGGER.info("%s\n%s", " ".join(cmd), output.decode("utf-8"))
192 return TempestCommon.get_verifier_id()
195 def get_verifier_id():
197 Returns verifier id for current Tempest
199 cmd = ("rally verify list-verifiers | awk '/" +
200 getattr(config.CONF, 'tempest_verifier_name') +
202 proc = subprocess.Popen(cmd, shell=True,
203 stdout=subprocess.PIPE,
204 stderr=subprocess.DEVNULL)
205 verifier_uuid = proc.stdout.readline().rstrip()
206 return verifier_uuid.decode("utf-8")
209 def get_verifier_repo_dir(verifier_id):
211 Returns installed verifier repo directory for Tempest
213 return os.path.join(getattr(config.CONF, 'dir_rally_inst'),
215 'verifier-{}'.format(verifier_id),
219 def get_verifier_deployment_dir(verifier_id, deployment_id):
221 Returns Rally deployment directory for current verifier
223 return os.path.join(getattr(config.CONF, 'dir_rally_inst'),
225 'verifier-{}'.format(verifier_id),
226 'for-deployment-{}'.format(deployment_id))
229 def update_tempest_conf_file(conf_file, rconfig):
230 """Update defined paramters into tempest config file"""
231 with open(TempestCommon.tempest_conf_yaml) as yfile:
232 conf_yaml = yaml.safe_load(yfile)
234 sections = rconfig.sections()
235 for section in conf_yaml:
236 if section not in sections:
237 rconfig.add_section(section)
238 sub_conf = conf_yaml.get(section)
239 for key, value in sub_conf.items():
240 rconfig.set(section, key, value)
242 with open(conf_file, 'w') as config_file:
243 rconfig.write(config_file)
246 def configure_tempest_update_params(
247 tempest_conf_file, image_id=None, flavor_id=None,
248 compute_cnt=1, image_alt_id=None, flavor_alt_id=None,
249 admin_role_name='admin', cidr='192.168.120.0/24',
250 domain_id='default'):
251 # pylint: disable=too-many-branches,too-many-arguments
252 # pylint: disable=too-many-statements,too-many-locals
254 Add/update needed parameters into tempest.conf file
256 LOGGER.debug("Updating selected tempest.conf parameters...")
257 rconfig = configparser.RawConfigParser()
258 rconfig.read(tempest_conf_file)
260 'compute', 'volume_device_name', env.get('VOLUME_DEVICE_NAME'))
261 if image_id is not None:
262 rconfig.set('compute', 'image_ref', image_id)
263 if image_alt_id is not None:
264 rconfig.set('compute', 'image_ref_alt', image_alt_id)
265 if flavor_id is not None:
266 rconfig.set('compute', 'flavor_ref', flavor_id)
267 if flavor_alt_id is not None:
268 rconfig.set('compute', 'flavor_ref_alt', flavor_alt_id)
270 # enable multinode tests
271 rconfig.set('compute', 'min_compute_nodes', compute_cnt)
272 rconfig.set('compute-feature-enabled', 'live_migration', True)
273 if os.environ.get('OS_REGION_NAME'):
274 rconfig.set('identity', 'region', os.environ.get('OS_REGION_NAME'))
275 if env.get("NEW_USER_ROLE").lower() != "member":
277 'auth', 'tempest_roles',
278 functest_utils.convert_list_to_ini([env.get("NEW_USER_ROLE")]))
279 if not json.loads(env.get("USE_DYNAMIC_CREDENTIALS").lower()):
280 rconfig.set('auth', 'use_dynamic_credentials', False)
281 account_file = os.path.join(
282 getattr(config.CONF, 'dir_functest_data'), 'accounts.yaml')
283 assert os.path.exists(
284 account_file), "{} doesn't exist".format(account_file)
285 rconfig.set('auth', 'test_accounts_file', account_file)
286 if env.get('NO_TENANT_NETWORK').lower() == 'true':
287 rconfig.set('auth', 'create_isolated_networks', False)
288 rconfig.set('identity', 'admin_role', admin_role_name)
289 rconfig.set('identity', 'default_domain_id', domain_id)
290 if not rconfig.has_section('network'):
291 rconfig.add_section('network')
292 rconfig.set('network', 'default_network', cidr)
293 rconfig.set('network', 'project_network_cidr', cidr)
294 rconfig.set('network', 'project_networks_reachable', False)
296 'identity', 'v3_endpoint_type',
297 os.environ.get('OS_INTERFACE', 'public'))
299 sections = rconfig.sections()
301 'compute', 'volume', 'image', 'network', 'data-processing',
302 'object-storage', 'orchestration']
303 for service in services_list:
304 if service not in sections:
305 rconfig.add_section(service)
306 rconfig.set(service, 'endpoint_type',
307 os.environ.get('OS_INTERFACE', 'public'))
309 LOGGER.debug('Add/Update required params defined in tempest_conf.yaml '
310 'into tempest.conf file')
311 TempestCommon.update_tempest_conf_file(tempest_conf_file, rconfig)
314 def configure_verifier(deployment_dir):
316 Execute rally verify configure-verifier, which generates tempest.conf
318 cmd = ['rally', 'verify', 'configure-verifier', '--reconfigure',
319 '--id', str(getattr(config.CONF, 'tempest_verifier_name'))]
320 output = subprocess.check_output(cmd)
321 LOGGER.info("%s\n%s", " ".join(cmd), output.decode("utf-8"))
323 LOGGER.debug("Looking for tempest.conf file...")
324 tempest_conf_file = os.path.join(deployment_dir, "tempest.conf")
325 if not os.path.isfile(tempest_conf_file):
326 LOGGER.error("Tempest configuration file %s NOT found.",
329 return tempest_conf_file
331 def generate_test_list(self, **kwargs):
332 """Generate test list based on the test mode."""
333 LOGGER.debug("Generating test case list...")
334 self.backup_tempest_config(self.conf_file, '/etc')
335 if kwargs.get('mode') == 'custom':
336 if os.path.isfile(self.tempest_custom):
338 self.tempest_custom, self.list)
340 raise Exception("Tempest test list file %s NOT found."
341 % self.tempest_custom)
343 testr_mode = kwargs.get(
344 'mode', r'^tempest\.(api|scenario).*\[.*\bsmoke\b.*\]$')
345 cmd = "(cd {0}; stestr list '{1}' >{2} 2>/dev/null)".format(
346 self.verifier_repo_dir, testr_mode, self.list)
347 output = subprocess.check_output(cmd, shell=True)
348 LOGGER.info("%s\n%s", cmd, output.decode("utf-8"))
349 os.remove('/etc/tempest.conf')
351 def apply_tempest_blacklist(self, black_list):
352 """Exclude blacklisted test cases."""
353 LOGGER.debug("Applying tempest blacklist...")
354 if os.path.exists(self.raw_list):
355 os.remove(self.raw_list)
356 os.rename(self.list, self.raw_list)
357 cases_file = self.read_file(self.raw_list)
358 result_file = open(self.list, 'w')
361 deploy_scenario = env.get('DEPLOY_SCENARIO')
362 if bool(deploy_scenario):
363 # if DEPLOY_SCENARIO is set we read the file
364 black_list_file = open(black_list)
365 black_list_yaml = yaml.safe_load(black_list_file)
366 black_list_file.close()
367 for item in black_list_yaml:
368 scenarios = item['scenarios']
369 in_it = rally.RallyBase.in_iterable_re
370 if in_it(deploy_scenario, scenarios):
371 tests = item['tests']
372 black_tests.extend(tests)
373 except Exception: # pylint: disable=broad-except
375 LOGGER.debug("Tempest blacklist file does not exist.")
377 for cases_line in cases_file:
378 for black_tests_line in black_tests:
379 if re.search(black_tests_line, cases_line):
382 result_file.write(str(cases_line) + '\n')
385 def run_verifier_tests(self, **kwargs):
386 """Execute tempest test cases."""
387 cmd = ["rally", "verify", "start", "--load-list",
389 cmd.extend(kwargs.get('option', []))
390 LOGGER.info("Starting Tempest test suite: '%s'.", cmd)
393 os.path.join(self.res_dir, "tempest.log"), 'w+')
395 proc = subprocess.Popen(
397 stdout=subprocess.PIPE,
398 stderr=subprocess.STDOUT,
402 for line in iter(proc.stdout.readline, b''):
403 if re.search(r"\} tempest\.", line.decode("utf-8")):
404 LOGGER.info(line.rstrip())
405 elif re.search(r'(?=\(UUID=(.*)\))', line.decode("utf-8")):
406 self.verification_id = re.search(
407 r'(?=\(UUID=(.*)\))', line.decode("utf-8")).group(1)
408 f_stdout.write(line.decode("utf-8"))
412 if self.verification_id is None:
413 raise Exception('Verification UUID not found')
414 LOGGER.info('Verification UUID: %s', self.verification_id)
417 "{}/tempest.log".format(self.deployment_dir),
418 "{}/tempest.debug.log".format(self.res_dir))
420 def parse_verifier_result(self):
421 """Parse and save test results."""
422 stat = self.get_verifier_result(self.verification_id)
424 num_executed = stat['num_tests'] - stat['num_skipped']
426 self.result = 100 * stat['num_success'] / num_executed
427 except ZeroDivisionError:
429 if stat['num_tests'] > 0:
430 LOGGER.info("All tests have been skipped")
432 LOGGER.error("No test has been executed")
435 with open(os.path.join(self.res_dir,
436 "rally.log"), 'r') as logfile:
437 output = logfile.read()
439 success_testcases = []
440 for match in re.findall(r'.*\{\d{1,2}\} (.*?) \.{3} success ',
442 success_testcases.append(match)
443 failed_testcases = []
444 for match in re.findall(r'.*\{\d{1,2}\} (.*?) \.{3} fail',
446 failed_testcases.append(match)
447 skipped_testcases = []
448 for match in re.findall(r'.*\{\d{1,2}\} (.*?) \.{3} skip(?::| )',
450 skipped_testcases.append(match)
452 self.details = {"tests_number": stat['num_tests'],
453 "success_number": stat['num_success'],
454 "skipped_number": stat['num_skipped'],
455 "failures_number": stat['num_failures'],
456 "success": success_testcases,
457 "skipped": skipped_testcases,
458 "failures": failed_testcases}
459 except Exception: # pylint: disable=broad-except
462 LOGGER.info("Tempest %s success_rate is %s%%",
463 self.case_name, self.result)
465 def update_rally_regex(self, rally_conf='/etc/rally/rally.conf'):
466 """Set image name as tempest img_name_regex"""
467 rconfig = configparser.RawConfigParser()
468 rconfig.read(rally_conf)
469 if not rconfig.has_section('openstack'):
470 rconfig.add_section('openstack')
471 rconfig.set('openstack', 'img_name_regex', '^{}$'.format(
473 with open(rally_conf, 'w') as config_file:
474 rconfig.write(config_file)
476 def update_default_role(self, rally_conf='/etc/rally/rally.conf'):
477 """Detect and update the default role if required"""
478 role = self.get_default_role(self.cloud)
481 rconfig = configparser.RawConfigParser()
482 rconfig.read(rally_conf)
483 if not rconfig.has_section('openstack'):
484 rconfig.add_section('openstack')
485 rconfig.set('openstack', 'swift_operator_role', role.name)
486 with open(rally_conf, 'w') as config_file:
487 rconfig.write(config_file)
490 def clean_rally_conf(rally_conf='/etc/rally/rally.conf'):
491 """Clean Rally config"""
492 rconfig = configparser.RawConfigParser()
493 rconfig.read(rally_conf)
494 if rconfig.has_option('openstack', 'img_name_regex'):
495 rconfig.remove_option('openstack', 'img_name_regex')
496 if rconfig.has_option('openstack', 'swift_operator_role'):
497 rconfig.remove_option('openstack', 'swift_operator_role')
498 with open(rally_conf, 'w') as config_file:
499 rconfig.write(config_file)
501 def update_network_section(self):
502 """Update network section in tempest.conf"""
503 rconfig = configparser.RawConfigParser()
504 rconfig.read(self.conf_file)
506 if not rconfig.has_section('network'):
507 rconfig.add_section('network')
508 rconfig.set('network', 'public_network_id', self.ext_net.id)
509 rconfig.set('network', 'floating_network_name', self.ext_net.name)
510 rconfig.set('network-feature-enabled', 'floating_ips', True)
512 if not rconfig.has_section('network-feature-enabled'):
513 rconfig.add_section('network-feature-enabled')
514 rconfig.set('network-feature-enabled', 'floating_ips', False)
515 with open(self.conf_file, 'w') as config_file:
516 rconfig.write(config_file)
518 def update_compute_section(self):
519 """Update compute section in tempest.conf"""
520 rconfig = configparser.RawConfigParser()
521 rconfig.read(self.conf_file)
522 if not rconfig.has_section('compute'):
523 rconfig.add_section('compute')
525 'compute', 'fixed_network_name',
526 self.network.name if self.network else env.get("EXTERNAL_NETWORK"))
527 with open(self.conf_file, 'w') as config_file:
528 rconfig.write(config_file)
530 def update_validation_section(self):
531 """Update validation section in tempest.conf"""
532 rconfig = configparser.RawConfigParser()
533 rconfig.read(self.conf_file)
534 if not rconfig.has_section('validation'):
535 rconfig.add_section('validation')
537 'validation', 'connect_method',
538 'floating' if self.ext_net else 'fixed')
540 'validation', 'network_for_ssh',
541 self.network.name if self.network else env.get("EXTERNAL_NETWORK"))
542 with open(self.conf_file, 'w') as config_file:
543 rconfig.write(config_file)
545 def update_scenario_section(self):
546 """Update scenario section in tempest.conf"""
547 rconfig = configparser.RawConfigParser()
548 rconfig.read(self.conf_file)
550 config.CONF, '{}_image'.format(self.case_name), self.filename)
551 if not rconfig.has_section('scenario'):
552 rconfig.add_section('scenario')
553 rconfig.set('scenario', 'img_file', os.path.basename(filename))
554 rconfig.set('scenario', 'img_dir', os.path.dirname(filename))
555 rconfig.set('scenario', 'img_disk_format', getattr(
556 config.CONF, '{}_image_format'.format(self.case_name),
558 extra_properties = self.extra_properties.copy()
559 if env.get('IMAGE_PROPERTIES'):
560 extra_properties.update(
561 functest_utils.convert_ini_to_dict(
562 env.get('IMAGE_PROPERTIES')))
563 extra_properties.update(
564 getattr(config.CONF, '{}_extra_properties'.format(
565 self.case_name), {}))
567 'scenario', 'img_properties',
568 functest_utils.convert_dict_to_ini(extra_properties))
569 with open(self.conf_file, 'w') as config_file:
570 rconfig.write(config_file)
572 def configure(self, **kwargs): # pylint: disable=unused-argument
574 Create all openstack resources for tempest-based testcases and write
577 if not os.path.exists(self.res_dir):
578 os.makedirs(self.res_dir)
579 self.deployment_id = rally.RallyBase.create_rally_deployment(
580 environ=self.project.get_environ())
581 if not self.deployment_id:
582 raise Exception("Deployment create failed")
583 self.verifier_id = self.create_verifier()
584 if not self.verifier_id:
585 raise Exception("Verifier create failed")
586 self.verifier_repo_dir = self.get_verifier_repo_dir(
588 self.deployment_dir = self.get_verifier_deployment_dir(
589 self.verifier_id, self.deployment_id)
591 compute_cnt = self.count_hypervisors() if self.count_hypervisors(
593 self.image_alt = self.publish_image_alt()
594 self.flavor_alt = self.create_flavor_alt()
595 LOGGER.debug("flavor: %s", self.flavor_alt)
597 self.conf_file = self.configure_verifier(self.deployment_dir)
598 if not self.conf_file:
599 raise Exception("Tempest verifier configuring failed")
600 self.configure_tempest_update_params(
602 image_id=self.image.id,
603 flavor_id=self.flavor.id,
604 compute_cnt=compute_cnt,
605 image_alt_id=self.image_alt.id,
606 flavor_alt_id=self.flavor_alt.id,
607 admin_role_name=self.role_name, cidr=self.cidr,
608 domain_id=self.project.domain.id)
609 self.update_network_section()
610 self.update_compute_section()
611 self.update_validation_section()
612 self.update_scenario_section()
613 self.backup_tempest_config(self.conf_file, self.res_dir)
615 def run(self, **kwargs):
616 self.start_time = time.time()
618 assert super(TempestCommon, self).run(
619 **kwargs) == testcase.TestCase.EX_OK
620 if not os.path.exists(self.res_dir):
621 os.makedirs(self.res_dir)
622 self.update_rally_regex()
623 self.update_default_role()
624 rally.RallyBase.update_rally_logs(self.res_dir)
625 shutil.copy("/etc/rally/rally.conf", self.res_dir)
626 self.configure(**kwargs)
627 self.generate_test_list(**kwargs)
628 self.apply_tempest_blacklist(TempestCommon.tempest_blacklist)
629 if env.get('PUBLIC_ENDPOINT_ONLY').lower() == 'true':
630 self.apply_tempest_blacklist(
631 TempestCommon.tempest_public_blacklist)
632 self.run_verifier_tests(**kwargs)
633 self.parse_verifier_result()
634 rally.RallyBase.verify_report(
635 os.path.join(self.res_dir, "tempest-report.html"),
636 self.verification_id)
637 rally.RallyBase.verify_report(
638 os.path.join(self.res_dir, "tempest-report.xml"),
639 self.verification_id, "junit-xml")
640 res = testcase.TestCase.EX_OK
641 except Exception: # pylint: disable=broad-except
642 LOGGER.exception('Error with run')
644 res = testcase.TestCase.EX_RUN_ERROR
645 self.stop_time = time.time()
650 Cleanup all OpenStack objects. Should be called on completion.
652 self.clean_rally_conf()
653 rally.RallyBase.clean_rally_logs()
655 self.cloud.delete_image(self.image_alt)
657 self.orig_cloud.delete_flavor(self.flavor_alt.id)
658 super(TempestCommon, self).clean()
660 def is_successful(self):
661 """The overall result of the test."""
662 skips = self.details.get("skipped_number", 0)
663 if skips > 0 and self.deny_skipping:
664 return testcase.TestCase.EX_TESTCASE_FAILED
665 if self.tests_count and (
666 self.details.get("tests_number", 0) != self.tests_count):
667 return testcase.TestCase.EX_TESTCASE_FAILED
668 return super(TempestCommon, self).is_successful()
671 class TempestHorizon(TempestCommon):
672 """Tempest Horizon testcase implementation class."""
674 def configure(self, **kwargs):
675 super(TempestHorizon, self).configure(**kwargs)
676 rconfig = configparser.RawConfigParser()
677 rconfig.read(self.conf_file)
678 if not rconfig.has_section('dashboard'):
679 rconfig.add_section('dashboard')
680 rconfig.set('dashboard', 'dashboard_url', env.get('DASHBOARD_URL'))
681 with open(self.conf_file, 'w') as config_file:
682 rconfig.write(config_file)
683 self.backup_tempest_config(self.conf_file, self.res_dir)
686 class TempestHeat(TempestCommon):
687 """Tempest Heat testcase implementation class."""
689 filename_alt = ('/home/opnfv/functest/images/'
690 'Fedora-Cloud-Base-30-1.2.x86_64.qcow2')
695 def __init__(self, **kwargs):
696 super(TempestHeat, self).__init__(**kwargs)
697 self.user2 = self.orig_cloud.create_user(
698 name='{}-user2_{}'.format(self.case_name, self.project.guid),
699 password=self.project.password,
700 domain_id=self.project.domain.id)
701 if not self.orig_cloud.get_role("heat_stack_owner"):
702 self.role = self.orig_cloud.create_role("heat_stack_owner")
703 self.orig_cloud.grant_role(
704 "heat_stack_owner", user=self.user2.id,
705 project=self.project.project.id,
706 domain=self.project.domain.id)
708 def configure(self, **kwargs):
710 super(TempestHeat, self).configure(**kwargs)
711 rconfig = configparser.RawConfigParser()
712 rconfig.read(self.conf_file)
713 if not rconfig.has_section('heat_plugin'):
714 rconfig.add_section('heat_plugin')
715 # It fails if region and domain ids are unset
717 'heat_plugin', 'region',
718 os.environ.get('OS_REGION_NAME', 'RegionOne'))
719 rconfig.set('heat_plugin', 'auth_url', os.environ["OS_AUTH_URL"])
720 rconfig.set('heat_plugin', 'project_domain_id', self.project.domain.id)
721 rconfig.set('heat_plugin', 'user_domain_id', self.project.domain.id)
723 'heat_plugin', 'project_domain_name', self.project.domain.name)
725 'heat_plugin', 'user_domain_name', self.project.domain.name)
726 rconfig.set('heat_plugin', 'username', self.user2.name)
727 rconfig.set('heat_plugin', 'password', self.project.password)
728 rconfig.set('heat_plugin', 'project_name', self.project.project.name)
729 rconfig.set('heat_plugin', 'admin_username', self.project.user.name)
730 rconfig.set('heat_plugin', 'admin_password', self.project.password)
732 'heat_plugin', 'admin_project_name', self.project.project.name)
733 rconfig.set('heat_plugin', 'image_ref', self.image_alt.id)
734 rconfig.set('heat_plugin', 'instance_type', self.flavor_alt.id)
735 rconfig.set('heat_plugin', 'minimal_image_ref', self.image.id)
736 rconfig.set('heat_plugin', 'minimal_instance_type', self.flavor.id)
739 'heat_plugin', 'floating_network_name', self.ext_net.name)
741 rconfig.set('heat_plugin', 'fixed_network_name', self.network.name)
742 rconfig.set('heat_plugin', 'fixed_subnet_name', self.subnet.name)
743 rconfig.set('heat_plugin', 'network_for_ssh', self.network.name)
746 'No tenant network created. '
747 'Trying EXTERNAL_NETWORK as a fallback')
749 'heat_plugin', 'fixed_network_name',
750 env.get("EXTERNAL_NETWORK"))
752 'heat_plugin', 'network_for_ssh', env.get("EXTERNAL_NETWORK"))
753 with open(self.conf_file, 'w') as config_file:
754 rconfig.write(config_file)
755 self.backup_tempest_config(self.conf_file, self.res_dir)
759 Cleanup all OpenStack objects. Should be called on completion.
761 super(TempestHeat, self).clean()
763 self.orig_cloud.delete_user(self.user2.id)