How to use get_credentials_provider method in tempest

Best Python code snippet using tempest_python

test_credentials_factory.py

Source:test_credentials_factory.py Github

copy

Full Screen

...28 self.assertEqual(new_cls._get_credentials_provider, mock_gcp)29 self.assertEqual(new_cls.are_roles_available, mock_ara)30 self.assertEqual(new_cls.get_client_manager, mock_gcm)31 @mock.patch.object(creds, 'get_credentials_provider')32 def test_get_credentials_provider(self, mock_gcp):33 cls = mock.Mock()34 del cls.force_tenant_isolation35 del cls._creds_provider36 self._do_creds_provider_test(cls, mock_gcp)37 @mock.patch.object(creds, 'get_credentials_provider')38 def test_get_credentials_provider_with_tenant_iso(self, mock_gcp):39 cls = mock.Mock()40 self._do_creds_provider_test(cls, mock_gcp, tenant_iso=True)41 @mock.patch.object(creds, 'get_credentials_provider')42 def test_get_credentials_provider_none_creds_provider(self, mock_gcp):43 cls = mock.Mock()44 del cls.force_tenant_isolation45 cls._creds_provider = None46 self._do_creds_provider_test(cls, mock_gcp)47 @mock.patch.object(creds, 'get_credentials_provider')48 def test_get_credentials_provider_with_different_name(self, mock_gcp):49 cls = mock.Mock()50 del cls.force_tenant_isolation51 cls._creds_provider.__name__ = 'notfoo'52 self._do_creds_provider_test(cls, mock_gcp)53 @mock.patch.object(creds, 'get_credentials_provider')54 def test_get_credentials_already_has_provider(self, mock_gcp):55 cls = mock.Mock()56 cls.__name__ = 'foo'57 mock_prov = mock.Mock()58 mock_prov.name = cls.__name__59 cls._creds_provider = mock_prov60 prov = creds._get_credentials_provider(cls)61 self.assertEqual(mock_prov, prov)62 mock_gcp.assert_not_called()63 def test_are_roles_available(self):64 cls = mock.Mock()65 mock_prov = mock.Mock()66 mock_prov.are_roles_available.return_value = False67 cls._get_credentials_provider.return_value = mock_prov68 roles = ['foo', 'bar']69 are_avail = creds._are_roles_available(cls, roles)70 self.assertFalse(are_avail)71 mock_prov.are_roles_available.assert_called_once_with(roles)72 def test_are_roles_available_not_on_cred_provider(self):73 cls = mock.Mock()74 mock_prov = mock.Mock()75 del mock_prov.are_roles_available76 cls._get_credentials_provider.return_value = mock_prov77 roles = ['foo', 'bar']78 are_avail = creds._are_roles_available(cls, roles)79 self.assertTrue(are_avail)80 def test_get_client_manager(self):81 cls = mock.Mock()82 cls.are_roles_available.return_value = True83 self._do_client_manager_test(cls, roles=['foo', 'bar'])84 cls.are_roles_available.assert_called_once_with(['foo', 'bar'])85 def test_get_client_manager_without_roles(self):86 self._do_client_manager_test(mock.Mock())87 def test_get_client_manager_raises_skip(self):88 cls = mock.Mock()89 cls.__name__ = 'foo'90 cls.are_roles_available.return_value = False91 class MyException(Exception):92 pass93 cls.skipException = MyException94 self.assertRaises(MyException, creds._get_client_manager,95 cls, roles=['foo'])96 @mock.patch.object(t_creds, 'get_credentials_provider')97 @mock.patch.object(t_creds, '_get_preprov_provider_params')98 @mock.patch.object(creds, 'CONF')99 def test_public_get_credentials_provider(self, mock_conf,100 mock_params, mock_gcp):101 cls_name = 'ExactRoleMatchingPreProvisionedCredentialProvider'102 mock_conf.auth.test_accounts_file = 'foo.yaml'103 name = 'foo'104 params = {'foo': 'bar'}105 mock_params.return_value = params106 kwargs = {'network_resources': ['net1', 'net2'],107 'force_tenant_isolation': False, 'identity_version': 'v3'}108 with mock.patch.object(ppc, cls_name) as mock_creds:109 mock_provider = mock.Mock()110 mock_creds.return_value = mock_provider111 prov = creds.get_credentials_provider(name, **kwargs)112 self.assertEqual(mock_provider, prov)113 mock_gcp.assert_called_once_with(name, **kwargs)114 mock_params.assert_called_once_with()115 kwargs.update(params)116 del kwargs['force_tenant_isolation']117 del kwargs['network_resources']118 mock_creds.assert_called_once_with(name=name, **kwargs)119 @mock.patch.object(t_creds, 'get_credentials_provider')120 @mock.patch.object(creds, 'CONF')121 def test_get_credentials_provider_no_accounts_file(self, mock_conf,122 mock_gcp):123 mock_conf.auth.test_accounts_file = None124 mock_prov = mock.Mock()125 mock_gcp.return_value = mock_prov126 name = 'foo'127 kwargs = {'network_resources': ['net1', 'net2'],128 'force_tenant_isolation': True, 'identity_version': 'v3'}129 prov = creds.get_credentials_provider(name, **kwargs)130 self.assertEqual(mock_prov, prov)131 mock_gcp.assert_called_once_with(name, **kwargs)132 def _do_creds_provider_test(self, mock_cls, mock_get, tenant_iso=False):133 mock_cls.__name__ = 'foo'134 mock_cls.network_resources = ['net1', 'net2']135 mock_cls.get_identity_version = mock.Mock()136 mock_cls.get_identity_version.return_value = 'v3'137 mock_cls.force_tenant_isolation = tenant_iso138 mock_prov = mock.Mock()139 mock_get.return_value = mock_prov140 provider = creds._get_credentials_provider(mock_cls)141 self.assertEqual(provider, mock_prov)142 self.assertEqual(provider, mock_cls._creds_provider)143 mock_get.assert_called_once_with(144 name=mock_cls.__name__,145 network_resources=mock_cls.network_resources,146 force_tenant_isolation=tenant_iso,147 identity_version=mock_cls.get_identity_version())148 def _do_client_manager_test(self, cls, roles=None):149 mock_gcm = mock.Mock()150 mock_man = mock.Mock()151 mock_gcm.return_value = mock_man152 my_super = mock.Mock()153 my_super.get_client_manager = mock_gcm154 with mock.patch('cinnamon_role.credentials_factory.super') as mock_sup:...

Full Screen

Full Screen

credentials_factory.py

Source:credentials_factory.py Github

copy

Full Screen

...24 cls._get_credentials_provider = classmethod(_get_credentials_provider)25 cls.are_roles_available = classmethod(_are_roles_available)26 cls.get_client_manager = classmethod(_get_client_manager)27 return cls28def _get_credentials_provider(cls):29 # The new _get_credentails_provider() of the class30 # it runs the local get_credentials_provider() if _creds_provider is31 # not already set32 if (not hasattr(cls, '_creds_provider') or not cls._creds_provider or33 not cls._creds_provider.name == cls.__name__):34 force_tenant_isolation = getattr(cls, 'force_tenant_isolation',35 False)36 cls._creds_provider = get_credentials_provider(37 name=cls.__name__, network_resources=cls.network_resources,38 force_tenant_isolation=force_tenant_isolation,39 identity_version=cls.get_identity_version())40 return cls._creds_provider41def _are_roles_available(cls, roles):42 # A new method that checks to see if there exists a user with exactly43 # the roles specified.44 # Calls into the cred provider to get that information, if the45 # creds provider can supply it.46 cred_provider = cls._get_credentials_provider()47 # Only check if the roles are available if we're using48 # the custom cred provider, otherwise return True49 # so we don't hold things up50 if hasattr(cred_provider, 'are_roles_available'):51 return cred_provider.are_roles_available(roles)52 else:53 return True54def _get_client_manager(cls, credential_type=None, roles=None,55 force_new=None):56 # The new get_client_manager() method of the class.57 # It raises a skip exception if there is no user with exactly the roles58 # on a user.59 if roles:60 if not cls.are_roles_available(roles):61 skip_msg = (62 "%s skipped because the configured credential provider"63 " is not able to provide credentials with the roles "64 "%s assigned" % (cls.__name__, roles))65 raise cls.skipException(skip_msg)66 return super(cls, cls).get_client_manager(67 credential_type=credential_type, roles=roles, force_new=force_new)68def get_credentials_provider(name, network_resources=None,69 force_tenant_isolation=False,70 identity_version=None):71 # A new get_credentials_provider() function. It gets the tempest72 # credentials provider, and if an accounts yaml is specified, gets73 # the new creds provider that is used to exactly match roles on users74 provider = credentials_factory.get_credentials_provider(75 name, network_resources=network_resources,76 force_tenant_isolation=force_tenant_isolation,77 identity_version=identity_version)78 if CONF.auth.test_accounts_file:79 return ppc.ExactRoleMatchingPreProvisionedCredentialProvider(80 name=name, identity_version=identity_version,81 **credentials_factory._get_preprov_provider_params())82 else:...

Full Screen

Full Screen

test_load.py

Source:test_load.py Github

copy

Full Screen

...15 ami,err = load_artifact_obj('ami', {})16 print(err)17 self.assertTrue(not err)18 def test_k8s_creds_load(self):19 creds,err = get_credentials_provider('nordstrom-k8s', {})20 self.assertTrue(not err)21 def test_s3_vault_load(self):22 vault,err = get_vault_provider('s3', {})...

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