How to use get_creds_by_roles method in tempest

Best Python code snippet using tempest_python

accounts.py

Source:accounts.py Github

copy

Full Screen

...196 creds = self._get_creds()197 alt_credential = cred_provider.get_credentials(**creds)198 self.isolated_creds['alt'] = alt_credential199 return alt_credential200 def get_creds_by_roles(self, roles, force_new=False):201 roles = list(set(roles))202 exist_creds = self.isolated_creds.get(str(roles), None)203 # The force kwarg is used to allocate an additional set of creds with204 # the same role list. The index used for the previously allocation205 # in the isolated_creds dict will be moved.206 if exist_creds and not force_new:207 return exist_creds208 elif exist_creds and force_new:209 new_index = str(roles) + '-' + str(len(self.isolated_creds))210 self.isolated_creds[new_index] = exist_creds211 creds = self._get_creds(roles=roles)212 role_credential = cred_provider.get_credentials(**creds)213 self.isolated_creds[str(roles)] = role_credential214 return role_credential215 def clear_isolated_creds(self):216 for creds in self.isolated_creds.values():217 self.remove_credentials(creds)218 def get_admin_creds(self):219 return self.get_creds_by_roles([CONF.identity.admin_role])220 def is_role_available(self, role):221 if self.use_default_creds:222 return False223 else:224 if self.hash_dict['roles'].get(role):225 return True226 return False227 def admin_available(self):228 return self.is_role_available(CONF.identity.admin_role)229class NotLockingAccounts(Accounts):230 """Credentials provider which always returns the first and second231 configured accounts as primary and alt users.232 This credential provider can be used in case of serial test execution233 to preserve the current behaviour of the serial tempest run.234 """235 def _unique_creds(self, cred_arg=None):236 """Verify that the configured credentials are valid and distinct """237 if self.use_default_creds:238 try:239 user = self.get_primary_creds()240 alt_user = self.get_alt_creds()241 return getattr(user, cred_arg) != getattr(alt_user, cred_arg)242 except exceptions.InvalidCredentials as ic:243 msg = "At least one of the configured credentials is " \244 "not valid: %s" % ic.message245 raise exceptions.InvalidConfiguration(msg)246 else:247 # TODO(andreaf) Add a uniqueness check here248 return len(self.hash_dict['creds']) > 1249 def is_multi_user(self):250 return self._unique_creds('username')251 def is_multi_tenant(self):252 return self._unique_creds('tenant_id')253 def get_creds(self, id, roles=None):254 try:255 hashes = self._get_match_hash_list(roles)256 # No need to sort the dict as within the same python process257 # the HASH seed won't change, so subsequent calls to keys()258 # will return the same result259 _hash = hashes[id]260 except IndexError:261 msg = 'Insufficient number of users provided'262 raise exceptions.InvalidConfiguration(msg)263 return self.hash_dict['creds'][_hash]264 def get_primary_creds(self):265 if self.isolated_creds.get('primary'):266 return self.isolated_creds.get('primary')267 if not self.use_default_creds:268 creds = self.get_creds(0)269 primary_credential = cred_provider.get_credentials(**creds)270 else:271 primary_credential = cred_provider.get_configured_credentials(272 'user')273 self.isolated_creds['primary'] = primary_credential274 return primary_credential275 def get_alt_creds(self):276 if self.isolated_creds.get('alt'):277 return self.isolated_creds.get('alt')278 if not self.use_default_creds:279 creds = self.get_creds(1)280 alt_credential = cred_provider.get_credentials(**creds)281 else:282 alt_credential = cred_provider.get_configured_credentials(283 'alt_user')284 self.isolated_creds['alt'] = alt_credential285 return alt_credential286 def clear_isolated_creds(self):287 self.isolated_creds = {}288 def get_admin_creds(self):289 if not self.use_default_creds:290 return self.get_creds_by_roles([CONF.identity.admin_role])291 else:292 creds = cred_provider.get_configured_credentials(293 "identity_admin", fill_in=False)294 self.isolated_creds['admin'] = creds295 return creds296 def get_creds_by_roles(self, roles, force_new=False):297 roles = list(set(roles))298 exist_creds = self.isolated_creds.get(str(roles), None)299 index = 0300 if exist_creds and not force_new:301 return exist_creds302 elif exist_creds and force_new:303 new_index = str(roles) + '-' + str(len(self.isolated_creds))304 self.isolated_creds[new_index] = exist_creds305 # Figure out how many existing creds for this roles set are present306 # use this as the index the returning hash list to ensure separate307 # creds are returned with force_new being True308 for creds_names in self.isolated_creds:309 if str(roles) in creds_names:310 index = index + 1...

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