Best Python code snippet using tempest_python
credentials_factory.py
Source:credentials_factory.py
...34 'admin_role': CONF.identity.admin_role35 }36def get_dynamic_provider_params():37 return get_common_provider_params()38def get_preprov_provider_params():39 _common_params = get_common_provider_params()40 reseller_admin_role = CONF.object_storage.reseller_admin_role41 return dict(_common_params, **dict([42 ('accounts_lock_dir', lockutils.get_lock_path(CONF)),43 ('test_accounts_file', CONF.auth.test_accounts_file),44 ('object_storage_operator_role', CONF.object_storage.operator_role),45 ('object_storage_reseller_admin_role', reseller_admin_role)46 ]))47# Return the right implementation of CredentialProvider based on config48# Dropping interface and password, as they are never used anyways49# TODO(andreaf) Drop them from the CredentialsProvider interface completely50def get_credentials_provider(name, network_resources=None,51 force_tenant_isolation=False,52 identity_version=None):53 # If a test requires a new account to work, it can have it via forcing54 # dynamic credentials. A new account will be produced only for that test.55 # In case admin credentials are not available for the account creation,56 # the test should be skipped else it would fail.57 identity_version = identity_version or CONF.identity.auth_version58 if CONF.auth.use_dynamic_credentials or force_tenant_isolation:59 admin_creds = get_configured_admin_credentials(60 fill_in=True, identity_version=identity_version)61 return dynamic_creds.DynamicCredentialProvider(62 name=name,63 network_resources=network_resources,64 identity_version=identity_version,65 admin_creds=admin_creds,66 identity_admin_domain_scope=CONF.identity.admin_domain_scope,67 identity_admin_role=CONF.identity.admin_role,68 extra_roles=CONF.auth.tempest_roles,69 neutron_available=CONF.service_available.neutron,70 project_network_cidr=CONF.network.project_network_cidr,71 project_network_mask_bits=CONF.network.project_network_mask_bits,72 public_network_id=CONF.network.public_network_id,73 create_networks=(CONF.auth.create_isolated_networks and not74 CONF.network.shared_physical_network),75 resource_prefix=CONF.resources_prefix,76 **get_dynamic_provider_params())77 else:78 if CONF.auth.test_accounts_file:79 # Most params are not relevant for pre-created accounts80 return preprov_creds.PreProvisionedCredentialProvider(81 name=name, identity_version=identity_version,82 **get_preprov_provider_params())83 else:84 raise exceptions.InvalidConfiguration(85 'A valid credential provider is needed')86# We want a helper function here to check and see if admin credentials87# are available so we can do a single call from skip_checks if admin88# creds area available.89# This depends on identity_version as there may be admin credentials90# available for v2 but not for v3.91def is_admin_available(identity_version):92 is_admin = True93 # If dynamic credentials is enabled admin will be available94 if CONF.auth.use_dynamic_credentials:95 return is_admin96 # Check whether test accounts file has the admin specified or not97 elif CONF.auth.test_accounts_file:98 check_accounts = preprov_creds.PreProvisionedCredentialProvider(99 identity_version=identity_version, name='check_admin',100 **get_preprov_provider_params())101 if not check_accounts.admin_available():102 is_admin = False103 else:104 try:105 get_configured_admin_credentials(fill_in=False,106 identity_version=identity_version)107 except exceptions.InvalidConfiguration:108 is_admin = False109 return is_admin110# We want a helper function here to check and see if alt credentials111# are available so we can do a single call from skip_checks if alt112# creds area available.113# This depends on identity_version as there may be alt credentials114# available for v2 but not for v3.115def is_alt_available(identity_version):116 # If dynamic credentials is enabled alt will be available117 if CONF.auth.use_dynamic_credentials:118 return True119 # Check whether test accounts file has the admin specified or not120 if CONF.auth.test_accounts_file:121 check_accounts = preprov_creds.PreProvisionedCredentialProvider(122 identity_version=identity_version, name='check_alt',123 **get_preprov_provider_params())124 else:125 raise exceptions.InvalidConfiguration(126 'A valid credential provider is needed')127 try:128 if not check_accounts.is_multi_user():129 return False130 else:131 return True132 except exceptions.InvalidConfiguration:133 return False134# === Credentials135# Type of credentials available from configuration136CREDENTIAL_TYPES = {137 'identity_admin': ('auth', 'admin'),...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!