How to use _wrap_creds_with_network method in tempest

Best Python code snippet using tempest_python

accounts.py

Source:accounts.py Github

copy

Full Screen

...176 free_hash = self._get_free_hash(useable_hashes)177 clean_creds = self._sanitize_creds(178 self.hash_dict['creds'][free_hash])179 LOG.info('%s allocated creds:\n%s' % (self.name, clean_creds))180 return self._wrap_creds_with_network(free_hash)181 @lockutils.synchronized('test_accounts_io', external=True)182 def remove_hash(self, hash_string):183 hash_path = os.path.join(self.accounts_dir, hash_string)184 if not os.path.isfile(hash_path):185 LOG.warning('Expected an account lock file %s to remove, but '186 'one did not exist' % hash_path)187 else:188 os.remove(hash_path)189 if not os.listdir(self.accounts_dir):190 os.rmdir(self.accounts_dir)191 def get_hash(self, creds):192 for _hash in self.hash_dict['creds']:193 # Comparing on the attributes that are expected in the YAML194 init_attributes = creds.get_init_attributes()195 hash_attributes = self.hash_dict['creds'][_hash].copy()196 if ('user_domain_name' in init_attributes and 'user_domain_name'197 not in hash_attributes):198 # Allow for the case of domain_name populated from config199 domain_name = CONF.auth.default_credentials_domain_name200 hash_attributes['user_domain_name'] = domain_name201 if all([getattr(creds, k) == hash_attributes[k] for202 k in init_attributes]):203 return _hash204 raise AttributeError('Invalid credentials %s' % creds)205 def remove_credentials(self, creds):206 _hash = self.get_hash(creds)207 clean_creds = self._sanitize_creds(self.hash_dict['creds'][_hash])208 self.remove_hash(_hash)209 LOG.info("%s returned allocated creds:\n%s" % (self.name, clean_creds))210 def get_primary_creds(self):211 if self.isolated_creds.get('primary'):212 return self.isolated_creds.get('primary')213 net_creds = self._get_creds()214 self.isolated_creds['primary'] = net_creds215 return net_creds216 def get_alt_creds(self):217 if self.isolated_creds.get('alt'):218 return self.isolated_creds.get('alt')219 net_creds = self._get_creds()220 self.isolated_creds['alt'] = net_creds221 return net_creds222 def get_creds_by_roles(self, roles, force_new=False):223 roles = list(set(roles))224 exist_creds = self.isolated_creds.get(six.text_type(roles).encode(225 'utf-8'), None)226 # The force kwarg is used to allocate an additional set of creds with227 # the same role list. The index used for the previously allocation228 # in the isolated_creds dict will be moved.229 if exist_creds and not force_new:230 return exist_creds231 elif exist_creds and force_new:232 new_index = six.text_type(roles).encode('utf-8') + '-' + \233 six.text_type(len(self.isolated_creds)).encode('utf-8')234 self.isolated_creds[new_index] = exist_creds235 net_creds = self._get_creds(roles=roles)236 self.isolated_creds[six.text_type(roles).encode('utf-8')] = net_creds237 return net_creds238 def clear_isolated_creds(self):239 for creds in self.isolated_creds.values():240 self.remove_credentials(creds)241 def get_admin_creds(self):242 return self.get_creds_by_roles([CONF.identity.admin_role])243 def is_role_available(self, role):244 if self.use_default_creds:245 return False246 else:247 if self.hash_dict['roles'].get(role):248 return True249 return False250 def admin_available(self):251 return self.is_role_available(CONF.identity.admin_role)252 def _wrap_creds_with_network(self, hash):253 creds_dict = self.hash_dict['creds'][hash]254 credential = cred_provider.get_credentials(255 identity_version=self.identity_version, **creds_dict)256 net_creds = cred_provider.TestResources(credential)257 net_clients = clients.Manager(credentials=credential)258 compute_network_client = net_clients.networks_client259 net_name = self.hash_dict['networks'].get(hash, None)260 try:261 network = fixed_network.get_network_from_name(262 net_name, compute_network_client)263 except exceptions.InvalidConfiguration:264 network = {}265 net_creds.set_resources(network=network)266 return net_creds...

Full Screen

Full Screen

preprov_creds.py

Source:preprov_creds.py Github

copy

Full Screen

...176 free_hash = self._get_free_hash(useable_hashes)177 clean_creds = self._sanitize_creds(178 self.hash_dict['creds'][free_hash])179 LOG.info('%s allocated creds:\n%s' % (self.name, clean_creds))180 return self._wrap_creds_with_network(free_hash)181 @lockutils.synchronized('test_accounts_io', external=True)182 def remove_hash(self, hash_string):183 hash_path = os.path.join(self.accounts_dir, hash_string)184 if not os.path.isfile(hash_path):185 LOG.warning('Expected an account lock file %s to remove, but '186 'one did not exist' % hash_path)187 else:188 os.remove(hash_path)189 if not os.listdir(self.accounts_dir):190 os.rmdir(self.accounts_dir)191 def get_hash(self, creds):192 for _hash in self.hash_dict['creds']:193 # Comparing on the attributes that are expected in the YAML194 init_attributes = creds.get_init_attributes()195 hash_attributes = self.hash_dict['creds'][_hash].copy()196 if ('user_domain_name' in init_attributes and 'user_domain_name'197 not in hash_attributes):198 # Allow for the case of domain_name populated from config199 domain_name = CONF.auth.default_credentials_domain_name200 hash_attributes['user_domain_name'] = domain_name201 if all([getattr(creds, k) == hash_attributes[k] for202 k in init_attributes]):203 return _hash204 raise AttributeError('Invalid credentials %s' % creds)205 def remove_credentials(self, creds):206 _hash = self.get_hash(creds)207 clean_creds = self._sanitize_creds(self.hash_dict['creds'][_hash])208 self.remove_hash(_hash)209 LOG.info("%s returned allocated creds:\n%s" % (self.name, clean_creds))210 def get_primary_creds(self):211 if self._creds.get('primary'):212 return self._creds.get('primary')213 net_creds = self._get_creds()214 self._creds['primary'] = net_creds215 return net_creds216 def get_alt_creds(self):217 if self._creds.get('alt'):218 return self._creds.get('alt')219 net_creds = self._get_creds()220 self._creds['alt'] = net_creds221 return net_creds222 def get_creds_by_roles(self, roles, force_new=False):223 roles = list(set(roles))224 exist_creds = self._creds.get(six.text_type(roles).encode(225 'utf-8'), None)226 # The force kwarg is used to allocate an additional set of creds with227 # the same role list. The index used for the previously allocation228 # in the _creds dict will be moved.229 if exist_creds and not force_new:230 return exist_creds231 elif exist_creds and force_new:232 new_index = six.text_type(roles).encode('utf-8') + '-' + \233 six.text_type(len(self._creds)).encode('utf-8')234 self._creds[new_index] = exist_creds235 net_creds = self._get_creds(roles=roles)236 self._creds[six.text_type(roles).encode('utf-8')] = net_creds237 return net_creds238 def clear_creds(self):239 for creds in self._creds.values():240 self.remove_credentials(creds)241 def get_admin_creds(self):242 return self.get_creds_by_roles([CONF.identity.admin_role])243 def is_role_available(self, role):244 if self.use_default_creds:245 return False246 else:247 if self.hash_dict['roles'].get(role):248 return True249 return False250 def admin_available(self):251 return self.is_role_available(CONF.identity.admin_role)252 def _wrap_creds_with_network(self, hash):253 creds_dict = self.hash_dict['creds'][hash]254 credential = cred_provider.get_credentials(255 identity_version=self.identity_version, **creds_dict)256 net_creds = cred_provider.TestResources(credential)257 net_clients = clients.Manager(credentials=credential)258 compute_network_client = net_clients.compute_networks_client259 net_name = self.hash_dict['networks'].get(hash, None)260 try:261 network = fixed_network.get_network_from_name(262 net_name, compute_network_client)263 except exceptions.InvalidConfiguration:264 network = {}265 net_creds.set_resources(network=network)266 return net_creds...

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