How to use verify_api_versions method in tempest

Best Python code snippet using tempest_python

verify_tempest_config.py

Source:verify_tempest_config.py Github

copy

Full Screen

...89 not CONF.volume_feature_enabled.api_v1, update)90 if CONF.volume_feature_enabled.api_v2 != ('v2.0' in versions):91 print_and_or_update('api_v2', 'volume_feature_enabled',92 not CONF.volume_feature_enabled.api_v2, update)93def verify_api_versions(os, service, update):94 verify = {95 'cinder': verify_cinder_api_versions,96 'glance': verify_glance_api_versions,97 'keystone': verify_keystone_api_versions,98 }99 if service not in verify:100 return101 verify[service](os, update)102def get_extension_client(os, service):103 extensions_client = {104 'nova': os.extensions_client,105 'cinder': os.volumes_extension_client,106 'neutron': os.network_client,107 'swift': os.account_client,108 }109 if service not in extensions_client:110 print('No tempest extensions client for %s' % service)111 exit(1)112 return extensions_client[service]113def get_enabled_extensions(service):114 extensions_options = {115 'nova': CONF.compute_feature_enabled.api_extensions,116 'cinder': CONF.volume_feature_enabled.api_extensions,117 'neutron': CONF.network_feature_enabled.api_extensions,118 'swift': CONF.object_storage_feature_enabled.discoverable_apis,119 }120 if service not in extensions_options:121 print('No supported extensions list option for %s' % service)122 exit(1)123 return extensions_options[service]124def verify_extensions(os, service, results):125 extensions_client = get_extension_client(os, service)126 if service == 'neutron':127 resp = extensions_client.list_extensions()128 else:129 __, resp = extensions_client.list_extensions()130 # For Nova, Cinder and Neutron we use the alias name rather than the131 # 'name' field because the alias is considered to be the canonical132 # name.133 if isinstance(resp, dict):134 if service == 'swift':135 # Remove Swift general information from extensions list136 resp.pop('swift')137 extensions = resp.keys()138 else:139 extensions = map(lambda x: x['alias'], resp['extensions'])140 else:141 extensions = map(lambda x: x['alias'], resp)142 if not results.get(service):143 results[service] = {}144 extensions_opt = get_enabled_extensions(service)145 if extensions_opt[0] == 'all':146 results[service]['extensions'] = extensions147 return results148 # Verify that all configured extensions are actually enabled149 for extension in extensions_opt:150 results[service][extension] = extension in extensions151 # Verify that there aren't additional extensions enabled that aren't152 # specified in the config list153 for extension in extensions:154 if extension not in extensions_opt:155 results[service][extension] = False156 return results157def display_results(results, update, replace):158 update_dict = {159 'swift': 'object-storage-feature-enabled',160 'nova': 'compute-feature-enabled',161 'cinder': 'volume-feature-enabled',162 'neutron': 'network-feature-enabled',163 }164 for service in results:165 # If all extensions are specified as being enabled there is no way to166 # verify this so we just assume this to be true167 if results[service].get('extensions'):168 if replace:169 output_list = results[service].get('extensions')170 else:171 output_list = ['all']172 else:173 extension_list = get_enabled_extensions(service)174 output_list = []175 for extension in results[service]:176 if not results[service][extension]:177 if extension in extension_list:178 print("%s extension: %s should not be included in the "179 "list of enabled extensions" % (service,180 extension))181 else:182 print("%s extension: %s should be included in the list"183 " of enabled extensions" % (service, extension))184 output_list.append(extension)185 else:186 output_list.append(extension)187 if update:188 # Sort List189 output_list.sort()190 # Convert list to a string191 output_string = ', '.join(output_list)192 if service == 'swift':193 change_option('discoverable_apis', update_dict[service],194 output_string)195 else:196 change_option('api_extensions', update_dict[service],197 output_string)198def check_service_availability(os, update):199 services = []200 avail_services = []201 codename_match = {202 'volume': 'cinder',203 'network': 'neutron',204 'image': 'glance',205 'object_storage': 'swift',206 'compute': 'nova',207 'orchestration': 'heat',208 'metering': 'ceilometer',209 'telemetry': 'ceilometer',210 'data_processing': 'sahara',211 'baremetal': 'ironic',212 'identity': 'keystone',213 'messaging': 'zaqar',214 'database': 'trove'215 }216 # Get catalog list for endpoints to use for validation217 endpoints = os.endpoints_client.list_endpoints()218 for endpoint in endpoints:219 service = os.service_client.get_service(endpoint['service_id'])220 services.append(service['type'])221 # Pull all catalog types from config file and compare against endpoint list222 for cfgname in dir(CONF._config):223 cfg = getattr(CONF, cfgname)224 catalog_type = getattr(cfg, 'catalog_type', None)225 if not catalog_type:226 continue227 else:228 if cfgname == 'identity':229 # Keystone is a required service for tempest230 continue231 if catalog_type not in services:232 if getattr(CONF.service_available, codename_match[cfgname]):233 print('Endpoint type %s not found either disable service '234 '%s or fix the catalog_type in the config file' % (235 catalog_type, codename_match[cfgname]))236 if update:237 change_option(codename_match[cfgname],238 'service_available', False)239 else:240 if not getattr(CONF.service_available,241 codename_match[cfgname]):242 print('Endpoint type %s is available, service %s should be'243 ' set as available in the config file.' % (244 catalog_type, codename_match[cfgname]))245 if update:246 change_option(codename_match[cfgname],247 'service_available', True)248 # If we are going to enable this we should allow249 # extension checks.250 avail_services.append(codename_match[cfgname])251 else:252 avail_services.append(codename_match[cfgname])253 return avail_services254def parse_args():255 parser = argparse.ArgumentParser()256 parser.add_argument('-u', '--update', action='store_true',257 help='Update the config file with results from api '258 'queries. This assumes whatever is set in the '259 'config file is incorrect. In the case of '260 'endpoint checks where it could either be the '261 'incorrect catalog type or the service available '262 'option the service available option is assumed '263 'to be incorrect and is thus changed')264 parser.add_argument('-o', '--output',265 help="Output file to write an updated config file to. "266 "This has to be a separate file from the "267 "original config file. If one isn't specified "268 "with -u the new config file will be printed to "269 "STDOUT")270 parser.add_argument('-r', '--replace-ext', action='store_true',271 help="If specified the all option will be replaced "272 "with a full list of extensions")273 args = parser.parse_args()274 return args275def main():276 print('Running config verification...')277 opts = parse_args()278 update = opts.update279 replace = opts.replace_ext280 global CONF_PARSER281 outfile = sys.stdout282 if update:283 conf_file = _get_config_file()284 if opts.output:285 outfile = open(opts.output, 'w+')286 CONF_PARSER = moves.configparser.SafeConfigParser()287 CONF_PARSER.optionxform = str288 CONF_PARSER.readfp(conf_file)289 os = clients.AdminManager(interface='json')290 services = check_service_availability(os, update)291 results = {}292 for service in ['nova', 'cinder', 'neutron', 'swift']:293 if service not in services:294 continue295 results = verify_extensions(os, service, results)296 # Verify API verisons of all services in the keystone catalog and keystone297 # itself.298 services.append('keystone')299 for service in services:300 verify_api_versions(os, service, update)301 display_results(results, update, replace)302 if update:303 conf_file.close()304 CONF_PARSER.write(outfile)305 outfile.close()306if __name__ == "__main__":...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run tempest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful