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 def _extract_refstack_data(self, refstack_list):
29 with open(refstack_list) as def_file:
32 grp = re.search(r'^([^\[]*)(\[.*\])\n*$', line)
33 yaml_data = "{}\n{}: {}".format(
34 yaml_data, grp.group(1), grp.group(2))
35 except Exception: # pylint: disable=broad-except
36 self.__logger.warning("Cannot parse %s", line)
37 return yaml.full_load(yaml_data)
39 def _extract_tempest_data(self):
42 os.chdir(self.verifier_repo_dir)
43 cmd = ['stestr', 'list', '^tempest.']
44 output = subprocess.check_output(cmd)
45 except subprocess.CalledProcessError as cpe:
47 "Exception when listing tempest tests: %s\n%s",
53 for line in output.splitlines():
55 grp = re.search(r'^([^\[]*)(\[.*\])\n*$', line.decode("utf-8"))
56 yaml_data2 = "{}\n{}: {}".format(
57 yaml_data2, grp.group(1), grp.group(2))
58 except Exception: # pylint: disable=broad-except
59 self.__logger.warning("Cannot parse %s. skipping it", line)
60 return yaml.full_load(yaml_data2)
62 def generate_test_list(self, **kwargs):
63 refstack_list = os.path.join(
64 getattr(config.CONF, 'dir_refstack_data'),
65 "{}.txt".format(kwargs.get('target', 'compute')))
66 self.backup_tempest_config(self.conf_file, '/etc')
67 refstack_data = self._extract_refstack_data(refstack_list)
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)