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 configuration utilities."""
13 from __future__ import print_function
23 from six.moves import configparser
26 from functest.utils import config
27 from functest.utils import env
30 RALLY_CONF_PATH = "/etc/rally/rally.conf"
31 RALLY_AARCH64_PATCH_PATH = pkg_resources.resource_filename(
32 'functest', 'ci/rally_aarch64_patch.conf')
33 GLANCE_IMAGE_PATH = os.path.join(
34 getattr(config.CONF, 'dir_functest_images'),
35 getattr(config.CONF, 'openstack_image_file_name'))
36 TEMPEST_CUSTOM = pkg_resources.resource_filename(
37 'functest', 'opnfv_tests/openstack/tempest/custom_tests/test_list.txt')
38 TEMPEST_BLACKLIST = pkg_resources.resource_filename(
39 'functest', 'opnfv_tests/openstack/tempest/custom_tests/blacklist.txt')
40 TEMPEST_CONF_YAML = pkg_resources.resource_filename(
41 'functest', 'opnfv_tests/openstack/tempest/custom_tests/tempest_conf.yaml')
43 CI_INSTALLER_TYPE = env.get('INSTALLER_TYPE')
45 """ logging configuration """
46 LOGGER = logging.getLogger(__name__)
49 def create_rally_deployment(environ=None):
50 """Create new rally deployment"""
51 # set the architecture to default
52 pod_arch = env.get("POD_ARCH")
53 arch_filter = ['aarch64']
55 if pod_arch and pod_arch in arch_filter:
56 LOGGER.info("Apply aarch64 specific to rally config...")
57 with open(RALLY_AARCH64_PATCH_PATH, "r") as pfile:
58 rally_patch_conf = pfile.read()
60 for line in fileinput.input(RALLY_CONF_PATH):
62 if "cirros|testvm" in line:
63 print(rally_patch_conf)
65 LOGGER.info("Creating Rally environment...")
68 cmd = ['rally', 'deployment', 'destroy',
70 str(getattr(config.CONF, 'rally_deployment_name'))]
71 output = subprocess.check_output(cmd)
72 LOGGER.info("%s\n%s", " ".join(cmd), output)
73 except subprocess.CalledProcessError:
76 cmd = ['rally', 'deployment', 'create', '--fromenv',
77 '--name', str(getattr(config.CONF, 'rally_deployment_name'))]
78 output = subprocess.check_output(cmd, env=environ)
79 LOGGER.info("%s\n%s", " ".join(cmd), output)
81 cmd = ['rally', 'deployment', 'check']
82 output = subprocess.check_output(cmd)
83 LOGGER.info("%s\n%s", " ".join(cmd), output)
86 def create_verifier():
87 """Create new verifier"""
88 LOGGER.info("Create verifier from existing repo...")
89 cmd = ['rally', 'verify', 'delete-verifier',
90 '--id', str(getattr(config.CONF, 'tempest_verifier_name')),
93 output = subprocess.check_output(cmd)
94 LOGGER.info("%s\n%s", " ".join(cmd), output)
95 except subprocess.CalledProcessError:
98 cmd = ['rally', 'verify', 'create-verifier',
99 '--source', str(getattr(config.CONF, 'dir_repo_tempest')),
100 '--name', str(getattr(config.CONF, 'tempest_verifier_name')),
101 '--type', 'tempest', '--system-wide']
102 output = subprocess.check_output(cmd)
103 LOGGER.info("%s\n%s", " ".join(cmd), output)
106 def get_verifier_id():
108 Returns verifier id for current Tempest
110 cmd = ("rally verify list-verifiers | awk '/" +
111 getattr(config.CONF, 'tempest_verifier_name') +
113 proc = subprocess.Popen(cmd, shell=True,
114 stdout=subprocess.PIPE,
115 stderr=subprocess.STDOUT)
116 verifier_uuid = proc.stdout.readline().rstrip()
117 if verifier_uuid == "":
118 LOGGER.error("Tempest verifier not found.")
119 raise Exception('Error with command:%s' % cmd)
123 def get_verifier_deployment_id():
125 Returns deployment id for active Rally deployment
127 cmd = ("rally deployment list | awk '/" +
128 getattr(config.CONF, 'rally_deployment_name') +
130 proc = subprocess.Popen(cmd, shell=True,
131 stdout=subprocess.PIPE,
132 stderr=subprocess.STDOUT)
133 deployment_uuid = proc.stdout.readline().rstrip()
134 if deployment_uuid == "":
135 LOGGER.error("Rally deployment not found.")
136 raise Exception('Error with command:%s' % cmd)
137 return deployment_uuid
140 def get_verifier_repo_dir(verifier_id):
142 Returns installed verifier repo directory for Tempest
144 return os.path.join(getattr(config.CONF, 'dir_rally_inst'),
146 'verifier-{}'.format(verifier_id),
150 def get_verifier_deployment_dir(verifier_id, deployment_id):
152 Returns Rally deployment directory for current verifier
154 return os.path.join(getattr(config.CONF, 'dir_rally_inst'),
156 'verifier-{}'.format(verifier_id),
157 'for-deployment-{}'.format(deployment_id))
160 def update_tempest_conf_file(conf_file, rconfig):
161 """Update defined paramters into tempest config file"""
162 with open(TEMPEST_CONF_YAML) as yfile:
163 conf_yaml = yaml.safe_load(yfile)
165 sections = rconfig.sections()
166 for section in conf_yaml:
167 if section not in sections:
168 rconfig.add_section(section)
169 sub_conf = conf_yaml.get(section)
170 for key, value in sub_conf.items():
171 rconfig.set(section, key, value)
173 with open(conf_file, 'wb') as config_file:
174 rconfig.write(config_file)
177 def configure_tempest_update_params(
178 tempest_conf_file, network_name=None, image_id=None, flavor_id=None,
179 compute_cnt=1, image_alt_id=None, flavor_alt_id=None,
180 domain_name="Default"):
181 # pylint: disable=too-many-branches, too-many-arguments
183 Add/update needed parameters into tempest.conf file
185 LOGGER.debug("Updating selected tempest.conf parameters...")
186 rconfig = configparser.RawConfigParser()
187 rconfig.read(tempest_conf_file)
188 rconfig.set('compute', 'fixed_network_name', network_name)
189 rconfig.set('compute', 'volume_device_name', env.get('VOLUME_DEVICE_NAME'))
190 if image_id is not None:
191 rconfig.set('compute', 'image_ref', image_id)
192 if image_alt_id is not None:
193 rconfig.set('compute', 'image_ref_alt', image_alt_id)
194 if flavor_id is not None:
195 rconfig.set('compute', 'flavor_ref', flavor_id)
196 if flavor_alt_id is not None:
197 rconfig.set('compute', 'flavor_ref_alt', flavor_alt_id)
199 # enable multinode tests
200 rconfig.set('compute', 'min_compute_nodes', compute_cnt)
201 rconfig.set('compute-feature-enabled', 'live_migration', True)
202 rconfig.set('compute-feature-enabled', 'shelve', False)
203 if os.environ.get('OS_REGION_NAME'):
204 rconfig.set('identity', 'region', os.environ.get('OS_REGION_NAME'))
205 identity_api_version = os.environ.get("OS_IDENTITY_API_VERSION", '3')
206 rconfig.set('auth', 'admin_domain_scope', True)
207 rconfig.set('auth', 'default_credentials_domain_name', domain_name)
208 if identity_api_version == '3':
210 rconfig.set('identity-feature-enabled', 'api_v2', False)
213 if env.get("NEW_USER_ROLE").lower() != "member":
215 'auth', 'tempest_roles',
216 convert_list_to_ini([env.get("NEW_USER_ROLE")]))
217 if not json.loads(env.get("USE_DYNAMIC_CREDENTIALS").lower()):
218 rconfig.set('auth', 'use_dynamic_credentials', False)
219 account_file = os.path.join(
220 getattr(config.CONF, 'dir_functest_data'), 'accounts.yaml')
221 assert os.path.exists(
222 account_file), "{} doesn't exist".format(account_file)
223 rconfig.set('auth', 'test_accounts_file', account_file)
224 rconfig.set('identity', 'auth_version', auth_version)
226 'validation', 'ssh_timeout',
227 getattr(config.CONF, 'tempest_validation_ssh_timeout'))
228 rconfig.set('object-storage', 'operator_role',
229 getattr(config.CONF, 'tempest_object_storage_operator_role'))
232 'identity', 'v3_endpoint_type',
233 os.environ.get('OS_INTERFACE', 'public'))
235 sections = rconfig.sections()
237 'compute', 'volume', 'image', 'network', 'data-processing',
238 'object-storage', 'orchestration']
239 for service in services_list:
240 if service not in sections:
241 rconfig.add_section(service)
243 service, 'endpoint_type', os.environ.get('OS_INTERFACE', 'public'))
245 LOGGER.debug('Add/Update required params defined in tempest_conf.yaml '
246 'into tempest.conf file')
247 update_tempest_conf_file(tempest_conf_file, rconfig)
250 def configure_verifier(deployment_dir):
252 Execute rally verify configure-verifier, which generates tempest.conf
254 cmd = ['rally', 'verify', 'configure-verifier', '--reconfigure',
255 '--id', str(getattr(config.CONF, 'tempest_verifier_name'))]
256 output = subprocess.check_output(cmd)
257 LOGGER.info("%s\n%s", " ".join(cmd), output)
259 LOGGER.debug("Looking for tempest.conf file...")
260 tempest_conf_file = os.path.join(deployment_dir, "tempest.conf")
261 if not os.path.isfile(tempest_conf_file):
262 LOGGER.error("Tempest configuration file %s NOT found.",
264 raise Exception("Tempest configuration file %s NOT found."
267 return tempest_conf_file
270 def convert_dict_to_ini(value):
271 "Convert dict to oslo.conf input"
272 assert isinstance(value, dict)
273 return ",".join("{}={}".format(
274 key, val) for (key, val) in six.iteritems(value))
277 def convert_list_to_ini(value):
278 "Convert list to oslo.conf input"
279 assert isinstance(value, list)
280 return ",".join("{}".format(val) for val in value)