3 # Copyright (c) 2017 Huawei Technologies Co.,Ltd and others.
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 """Refstack testcase implementation."""
18 from functest.opnfv_tests.openstack.tempest import tempest
19 from functest.utils import config
22 class Refstack(tempest.TempestCommon):
23 """Refstack testcase implementation class."""
25 __logger = logging.getLogger(__name__)
27 defcorelist = os.path.join(
28 getattr(config.CONF, 'dir_refstack_data'), 'defcore.txt')
30 def _extract_refstack_data(self):
32 with open(self.defcorelist) as def_file:
35 grp = re.search(r'^([^\[]*)(\[.*\])\n*$', line)
36 yaml_data = "{}\n{}: {}".format(
37 yaml_data, grp.group(1), grp.group(2))
38 except Exception: # pylint: disable=broad-except
39 self.__logger.warning("Cannot parse %s", line)
40 return yaml.load(yaml_data)
42 def _extract_tempest_data(self):
45 os.chdir(self.verifier_repo_dir)
46 cmd = ['stestr', 'list', '^tempest.']
47 output = subprocess.check_output(cmd)
48 except subprocess.CalledProcessError as cpe:
50 "Exception when listing tempest tests: %s\n%s",
56 for line in output.splitlines():
58 grp = re.search(r'^([^\[]*)(\[.*\])\n*$', line)
59 yaml_data2 = "{}\n{}: {}".format(
60 yaml_data2, grp.group(1), grp.group(2))
61 except Exception: # pylint: disable=broad-except
62 self.__logger.warning("Cannot parse %s. skipping it", line)
63 return yaml.load(yaml_data2)
65 def generate_test_list(self, **kwargs):
66 self.backup_tempest_config(self.conf_file, '/etc')
67 refstack_data = self._extract_refstack_data()
68 tempest_data = self._extract_tempest_data()
69 with open(self.list, 'w') as ref_file:
70 for key in refstack_data.keys():
72 for data in tempest_data[key]:
73 if data == refstack_data[key][0]:
76 self.__logger.info("%s: ids differ. skipping it", key)
78 ref_file.write("{}{}\n".format(
79 key, str(tempest_data[key]).replace(
80 "'", "").replace(", ", ",")))
81 except Exception: # pylint: disable=broad-except
82 self.__logger.info("%s: not found. skipping it", key)