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."""
19 from six.moves import configparser
22 from functest.utils import config
23 from functest.utils import env
24 from functest.utils import functest_utils
27 GLANCE_IMAGE_PATH = os.path.join(
28 getattr(config.CONF, 'dir_functest_images'),
29 getattr(config.CONF, 'openstack_image_file_name'))
30 TEMPEST_CUSTOM = pkg_resources.resource_filename(
31 'functest', 'opnfv_tests/openstack/tempest/custom_tests/test_list.txt')
32 TEMPEST_BLACKLIST = pkg_resources.resource_filename(
33 'functest', 'opnfv_tests/openstack/tempest/custom_tests/blacklist.yaml')
34 TEMPEST_CONF_YAML = pkg_resources.resource_filename(
35 'functest', 'opnfv_tests/openstack/tempest/custom_tests/tempest_conf.yaml')
37 CI_INSTALLER_TYPE = env.get('INSTALLER_TYPE')
39 """ logging configuration """
40 LOGGER = logging.getLogger(__name__)
43 def create_verifier():
44 """Create new verifier"""
45 LOGGER.info("Create verifier from existing repo...")
46 cmd = ['rally', 'verify', 'delete-verifier',
47 '--id', str(getattr(config.CONF, 'tempest_verifier_name')),
50 output = subprocess.check_output(cmd)
51 LOGGER.info("%s\n%s", " ".join(cmd), output)
52 except subprocess.CalledProcessError:
55 cmd = ['rally', 'verify', 'create-verifier',
56 '--source', str(getattr(config.CONF, 'dir_repo_tempest')),
57 '--name', str(getattr(config.CONF, 'tempest_verifier_name')),
58 '--type', 'tempest', '--system-wide']
59 output = subprocess.check_output(cmd)
60 LOGGER.info("%s\n%s", " ".join(cmd), output)
61 return get_verifier_id()
64 def get_verifier_id():
66 Returns verifier id for current Tempest
68 cmd = ("rally verify list-verifiers | awk '/" +
69 getattr(config.CONF, 'tempest_verifier_name') +
71 proc = subprocess.Popen(cmd, shell=True,
72 stdout=subprocess.PIPE,
73 stderr=subprocess.STDOUT)
74 verifier_uuid = proc.stdout.readline().rstrip()
78 def get_verifier_repo_dir(verifier_id):
80 Returns installed verifier repo directory for Tempest
82 return os.path.join(getattr(config.CONF, 'dir_rally_inst'),
84 'verifier-{}'.format(verifier_id),
88 def get_verifier_deployment_dir(verifier_id, deployment_id):
90 Returns Rally deployment directory for current verifier
92 return os.path.join(getattr(config.CONF, 'dir_rally_inst'),
94 'verifier-{}'.format(verifier_id),
95 'for-deployment-{}'.format(deployment_id))
98 def update_tempest_conf_file(conf_file, rconfig):
99 """Update defined paramters into tempest config file"""
100 with open(TEMPEST_CONF_YAML) as yfile:
101 conf_yaml = yaml.safe_load(yfile)
103 sections = rconfig.sections()
104 for section in conf_yaml:
105 if section not in sections:
106 rconfig.add_section(section)
107 sub_conf = conf_yaml.get(section)
108 for key, value in sub_conf.items():
109 rconfig.set(section, key, value)
111 with open(conf_file, 'wb') as config_file:
112 rconfig.write(config_file)
115 def configure_tempest_update_params(
116 tempest_conf_file, image_id=None, flavor_id=None,
117 compute_cnt=1, image_alt_id=None, flavor_alt_id=None,
118 admin_role_name='admin', cidr='192.168.120.0/24',
119 domain_id='default'):
120 # pylint: disable=too-many-branches,too-many-arguments,too-many-statements
122 Add/update needed parameters into tempest.conf file
124 LOGGER.debug("Updating selected tempest.conf parameters...")
125 rconfig = configparser.RawConfigParser()
126 rconfig.read(tempest_conf_file)
127 rconfig.set('compute', 'volume_device_name', env.get('VOLUME_DEVICE_NAME'))
128 if image_id is not None:
129 rconfig.set('compute', 'image_ref', image_id)
130 if image_alt_id is not None:
131 rconfig.set('compute', 'image_ref_alt', image_alt_id)
132 if flavor_id is not None:
133 rconfig.set('compute', 'flavor_ref', flavor_id)
134 if flavor_alt_id is not None:
135 rconfig.set('compute', 'flavor_ref_alt', flavor_alt_id)
137 # enable multinode tests
138 rconfig.set('compute', 'min_compute_nodes', compute_cnt)
139 rconfig.set('compute-feature-enabled', 'live_migration', True)
140 filters = ['RetryFilter', 'AvailabilityZoneFilter', 'ComputeFilter',
141 'ComputeCapabilitiesFilter', 'ImagePropertiesFilter',
142 'ServerGroupAntiAffinityFilter', 'ServerGroupAffinityFilter']
144 'compute-feature-enabled', 'scheduler_available_filters',
145 functest_utils.convert_list_to_ini(filters))
146 if os.environ.get('OS_REGION_NAME'):
147 rconfig.set('identity', 'region', os.environ.get('OS_REGION_NAME'))
148 if env.get("NEW_USER_ROLE").lower() != "member":
150 'auth', 'tempest_roles',
151 functest_utils.convert_list_to_ini([env.get("NEW_USER_ROLE")]))
152 if not json.loads(env.get("USE_DYNAMIC_CREDENTIALS").lower()):
153 rconfig.set('auth', 'use_dynamic_credentials', False)
154 account_file = os.path.join(
155 getattr(config.CONF, 'dir_functest_data'), 'accounts.yaml')
156 assert os.path.exists(
157 account_file), "{} doesn't exist".format(account_file)
158 rconfig.set('auth', 'test_accounts_file', account_file)
159 rconfig.set('identity', 'auth_version', 'v3')
160 rconfig.set('identity', 'admin_role', admin_role_name)
161 rconfig.set('identity', 'admin_domain_scope', True)
162 rconfig.set('identity', 'default_domain_id', domain_id)
163 if not rconfig.has_section('network'):
164 rconfig.add_section('network')
165 rconfig.set('network', 'default_network', cidr)
166 rconfig.set('network', 'project_network_cidr', cidr)
167 rconfig.set('network', 'project_networks_reachable', False)
169 'validation', 'ssh_timeout',
170 getattr(config.CONF, 'tempest_validation_ssh_timeout'))
171 rconfig.set('object-storage', 'operator_role',
172 getattr(config.CONF, 'tempest_object_storage_operator_role'))
174 'identity', 'v3_endpoint_type',
175 os.environ.get('OS_INTERFACE', 'public'))
177 sections = rconfig.sections()
179 'compute', 'volume', 'image', 'network', 'data-processing',
180 'object-storage', 'orchestration']
181 for service in services_list:
182 if service not in sections:
183 rconfig.add_section(service)
185 service, 'endpoint_type', os.environ.get('OS_INTERFACE', 'public'))
187 LOGGER.debug('Add/Update required params defined in tempest_conf.yaml '
188 'into tempest.conf file')
189 update_tempest_conf_file(tempest_conf_file, rconfig)
192 def configure_verifier(deployment_dir):
194 Execute rally verify configure-verifier, which generates tempest.conf
196 cmd = ['rally', 'verify', 'configure-verifier', '--reconfigure',
197 '--id', str(getattr(config.CONF, 'tempest_verifier_name'))]
198 output = subprocess.check_output(cmd)
199 LOGGER.info("%s\n%s", " ".join(cmd), output)
201 LOGGER.debug("Looking for tempest.conf file...")
202 tempest_conf_file = os.path.join(deployment_dir, "tempest.conf")
203 if not os.path.isfile(tempest_conf_file):
204 LOGGER.error("Tempest configuration file %s NOT found.",
207 return tempest_conf_file