How to use get_primary_creds method in tempest

Best Python code snippet using tempest_python

test_dynamic_creds.py

Source:test_dynamic_creds.py Github

copy

Full Screen

...129 self._mock_assign_user_role()130 self._mock_list_role()131 self._mock_tenant_create('1234', 'fake_prim_tenant')132 self._mock_user_create('1234', 'fake_prim_user')133 primary_creds = creds.get_primary_creds()134 self.assertEqual(primary_creds.username, 'fake_prim_user')135 self.assertEqual(primary_creds.tenant_name, 'fake_prim_tenant')136 # Verify IDs137 self.assertEqual(primary_creds.tenant_id, '1234')138 self.assertEqual(primary_creds.user_id, '1234')139 @mock.patch('tempest_lib.common.rest_client.RestClient')140 def test_admin_creds(self, MockRestClient):141 cfg.CONF.set_default('neutron', False, 'service_available')142 creds = dynamic_creds.DynamicCredentialProvider(name='test class')143 self._mock_list_roles('1234', 'admin')144 self._mock_user_create('1234', 'fake_admin_user')145 self._mock_tenant_create('1234', 'fake_admin_tenant')146 user_mock = mock.patch.object(json_iden_client.IdentityClient,147 'assign_user_role')148 user_mock.start()149 self.addCleanup(user_mock.stop)150 with mock.patch.object(json_iden_client.IdentityClient,151 'assign_user_role') as user_mock:152 admin_creds = creds.get_admin_creds()153 user_mock.assert_has_calls([154 mock.call('1234', '1234', '1234')])155 self.assertEqual(admin_creds.username, 'fake_admin_user')156 self.assertEqual(admin_creds.tenant_name, 'fake_admin_tenant')157 # Verify IDs158 self.assertEqual(admin_creds.tenant_id, '1234')159 self.assertEqual(admin_creds.user_id, '1234')160 @mock.patch('tempest_lib.common.rest_client.RestClient')161 def test_role_creds(self, MockRestClient):162 cfg.CONF.set_default('neutron', False, 'service_available')163 creds = dynamic_creds.DynamicCredentialProvider('v2', 'test class')164 self._mock_list_2_roles()165 self._mock_user_create('1234', 'fake_role_user')166 self._mock_tenant_create('1234', 'fake_role_tenant')167 user_mock = mock.patch.object(json_iden_client.IdentityClient,168 'assign_user_role')169 user_mock.start()170 self.addCleanup(user_mock.stop)171 with mock.patch.object(json_iden_client.IdentityClient,172 'assign_user_role') as user_mock:173 role_creds = creds.get_creds_by_roles(174 roles=['role1', 'role2'])175 calls = user_mock.mock_calls176 # Assert that the role creation is called with the 2 specified roles177 self.assertEqual(len(calls), 2)178 args = map(lambda x: x[1], calls)179 args = list(args)180 self.assertIn(('1234', '1234', '1234'), args)181 self.assertIn(('1234', '1234', '12345'), args)182 self.assertEqual(role_creds.username, 'fake_role_user')183 self.assertEqual(role_creds.tenant_name, 'fake_role_tenant')184 # Verify IDs185 self.assertEqual(role_creds.tenant_id, '1234')186 self.assertEqual(role_creds.user_id, '1234')187 @mock.patch('tempest_lib.common.rest_client.RestClient')188 def test_all_cred_cleanup(self, MockRestClient):189 cfg.CONF.set_default('neutron', False, 'service_available')190 creds = dynamic_creds.DynamicCredentialProvider(name='test class')191 self._mock_assign_user_role()192 self._mock_list_role()193 self._mock_tenant_create('1234', 'fake_prim_tenant')194 self._mock_user_create('1234', 'fake_prim_user')195 creds.get_primary_creds()196 self._mock_tenant_create('12345', 'fake_alt_tenant')197 self._mock_user_create('12345', 'fake_alt_user')198 creds.get_alt_creds()199 self._mock_tenant_create('123456', 'fake_admin_tenant')200 self._mock_user_create('123456', 'fake_admin_user')201 self._mock_list_roles('123456', 'admin')202 creds.get_admin_creds()203 user_mock = self.patch(204 'tempest.services.identity.v2.json.identity_client.'205 'IdentityClient.delete_user')206 tenant_mock = self.patch(207 'tempest.services.identity.v2.json.identity_client.'208 'IdentityClient.delete_tenant')209 creds.clear_creds()210 # Verify user delete calls211 calls = user_mock.mock_calls212 self.assertEqual(len(calls), 3)213 args = map(lambda x: x[1][0], calls)214 args = list(args)215 self.assertIn('1234', args)216 self.assertIn('12345', args)217 self.assertIn('123456', args)218 # Verify tenant delete calls219 calls = tenant_mock.mock_calls220 self.assertEqual(len(calls), 3)221 args = map(lambda x: x[1][0], calls)222 args = list(args)223 self.assertIn('1234', args)224 self.assertIn('12345', args)225 self.assertIn('123456', args)226 @mock.patch('tempest_lib.common.rest_client.RestClient')227 def test_alt_creds(self, MockRestClient):228 cfg.CONF.set_default('neutron', False, 'service_available')229 creds = dynamic_creds.DynamicCredentialProvider(name='test class')230 self._mock_assign_user_role()231 self._mock_list_role()232 self._mock_user_create('1234', 'fake_alt_user')233 self._mock_tenant_create('1234', 'fake_alt_tenant')234 alt_creds = creds.get_alt_creds()235 self.assertEqual(alt_creds.username, 'fake_alt_user')236 self.assertEqual(alt_creds.tenant_name, 'fake_alt_tenant')237 # Verify IDs238 self.assertEqual(alt_creds.tenant_id, '1234')239 self.assertEqual(alt_creds.user_id, '1234')240 @mock.patch('tempest_lib.common.rest_client.RestClient')241 def test_no_network_creation_with_config_set(self, MockRestClient):242 cfg.CONF.set_default('create_isolated_networks', False, group='auth')243 creds = dynamic_creds.DynamicCredentialProvider(name='test class')244 self._mock_assign_user_role()245 self._mock_list_role()246 self._mock_user_create('1234', 'fake_prim_user')247 self._mock_tenant_create('1234', 'fake_prim_tenant')248 net = mock.patch.object(creds.networks_admin_client,249 'delete_network')250 net_mock = net.start()251 subnet = mock.patch.object(creds.subnets_admin_client,252 'delete_subnet')253 subnet_mock = subnet.start()254 router = mock.patch.object(creds.network_admin_client,255 'delete_router')256 router_mock = router.start()257 primary_creds = creds.get_primary_creds()258 self.assertEqual(net_mock.mock_calls, [])259 self.assertEqual(subnet_mock.mock_calls, [])260 self.assertEqual(router_mock.mock_calls, [])261 network = primary_creds.network262 subnet = primary_creds.subnet263 router = primary_creds.router264 self.assertIsNone(network)265 self.assertIsNone(subnet)266 self.assertIsNone(router)267 @mock.patch('tempest_lib.common.rest_client.RestClient')268 def test_network_creation(self, MockRestClient):269 creds = dynamic_creds.DynamicCredentialProvider(name='test class')270 self._mock_assign_user_role()271 self._mock_list_role()272 self._mock_user_create('1234', 'fake_prim_user')273 self._mock_tenant_create('1234', 'fake_prim_tenant')274 self._mock_network_create(creds, '1234', 'fake_net')275 self._mock_subnet_create(creds, '1234', 'fake_subnet')276 self._mock_router_create('1234', 'fake_router')277 router_interface_mock = self.patch(278 'tempest.services.network.json.network_client.NetworkClient.'279 'add_router_interface_with_subnet_id')280 primary_creds = creds.get_primary_creds()281 router_interface_mock.called_once_with('1234', '1234')282 network = primary_creds.network283 subnet = primary_creds.subnet284 router = primary_creds.router285 self.assertEqual(network['id'], '1234')286 self.assertEqual(network['name'], 'fake_net')287 self.assertEqual(subnet['id'], '1234')288 self.assertEqual(subnet['name'], 'fake_subnet')289 self.assertEqual(router['id'], '1234')290 self.assertEqual(router['name'], 'fake_router')291 @mock.patch('tempest_lib.common.rest_client.RestClient')292 def test_network_cleanup(self, MockRestClient):293 def side_effect(**args):294 return {"security_groups": [{"tenant_id": args['tenant_id'],295 "name": args['name'],296 "description": args['name'],297 "security_group_rules": [],298 "id": "sg-%s" % args['tenant_id']}]}299 creds = dynamic_creds.DynamicCredentialProvider(name='test class')300 # Create primary tenant and network301 self._mock_assign_user_role()302 self._mock_list_role()303 self._mock_user_create('1234', 'fake_prim_user')304 self._mock_tenant_create('1234', 'fake_prim_tenant')305 self._mock_network_create(creds, '1234', 'fake_net')306 self._mock_subnet_create(creds, '1234', 'fake_subnet')307 self._mock_router_create('1234', 'fake_router')308 router_interface_mock = self.patch(309 'tempest.services.network.json.network_client.NetworkClient.'310 'add_router_interface_with_subnet_id')311 creds.get_primary_creds()312 router_interface_mock.called_once_with('1234', '1234')313 router_interface_mock.reset_mock()314 # Create alternate tenant and network315 self._mock_user_create('12345', 'fake_alt_user')316 self._mock_tenant_create('12345', 'fake_alt_tenant')317 self._mock_network_create(creds, '12345', 'fake_alt_net')318 self._mock_subnet_create(creds, '12345', 'fake_alt_subnet')319 self._mock_router_create('12345', 'fake_alt_router')320 creds.get_alt_creds()321 router_interface_mock.called_once_with('12345', '12345')322 router_interface_mock.reset_mock()323 # Create admin tenant and networks324 self._mock_user_create('123456', 'fake_admin_user')325 self._mock_tenant_create('123456', 'fake_admin_tenant')326 self._mock_network_create(creds, '123456', 'fake_admin_net')327 self._mock_subnet_create(creds, '123456', 'fake_admin_subnet')328 self._mock_router_create('123456', 'fake_admin_router')329 self._mock_list_roles('123456', 'admin')330 creds.get_admin_creds()331 self.patch('tempest.services.identity.v2.json.identity_client.'332 'IdentityClient.delete_user')333 self.patch('tempest.services.identity.v2.json.identity_client.'334 'IdentityClient.delete_tenant')335 net = mock.patch.object(creds.networks_admin_client,336 'delete_network')337 net_mock = net.start()338 subnet = mock.patch.object(creds.subnets_admin_client,339 'delete_subnet')340 subnet_mock = subnet.start()341 router = mock.patch.object(creds.network_admin_client,342 'delete_router')343 router_mock = router.start()344 remove_router_interface_mock = self.patch(345 'tempest.services.network.json.network_client.NetworkClient.'346 'remove_router_interface_with_subnet_id')347 return_values = ({'status': 200}, {'ports': []})348 port_list_mock = mock.patch.object(creds.network_admin_client,349 'list_ports',350 return_value=return_values)351 port_list_mock.start()352 secgroup_list_mock = mock.patch.object(353 creds.network_admin_client,354 'list_security_groups',355 side_effect=side_effect)356 secgroup_list_mock.start()357 return_values = (fake_http.fake_httplib({}, status=204), {})358 remove_secgroup_mock = self.patch(359 'tempest.services.network.json.network_client.'360 'NetworkClient.delete', return_value=return_values)361 creds.clear_creds()362 # Verify default security group delete363 calls = remove_secgroup_mock.mock_calls364 self.assertEqual(len(calls), 3)365 args = map(lambda x: x[1][0], calls)366 args = list(args)367 self.assertIn('v2.0/security-groups/sg-1234', args)368 self.assertIn('v2.0/security-groups/sg-12345', args)369 self.assertIn('v2.0/security-groups/sg-123456', args)370 # Verify remove router interface calls371 calls = remove_router_interface_mock.mock_calls372 self.assertEqual(len(calls), 3)373 args = map(lambda x: x[1], calls)374 args = list(args)375 self.assertIn(('1234', '1234'), args)376 self.assertIn(('12345', '12345'), args)377 self.assertIn(('123456', '123456'), args)378 # Verify network delete calls379 calls = net_mock.mock_calls380 self.assertEqual(len(calls), 3)381 args = map(lambda x: x[1][0], calls)382 args = list(args)383 self.assertIn('1234', args)384 self.assertIn('12345', args)385 self.assertIn('123456', args)386 # Verify subnet delete calls387 calls = subnet_mock.mock_calls388 self.assertEqual(len(calls), 3)389 args = map(lambda x: x[1][0], calls)390 args = list(args)391 self.assertIn('1234', args)392 self.assertIn('12345', args)393 self.assertIn('123456', args)394 # Verify router delete calls395 calls = router_mock.mock_calls396 self.assertEqual(len(calls), 3)397 args = map(lambda x: x[1][0], calls)398 args = list(args)399 self.assertIn('1234', args)400 self.assertIn('12345', args)401 self.assertIn('123456', args)402 @mock.patch('tempest_lib.common.rest_client.RestClient')403 def test_network_alt_creation(self, MockRestClient):404 creds = dynamic_creds.DynamicCredentialProvider(name='test class')405 self._mock_assign_user_role()406 self._mock_list_role()407 self._mock_user_create('1234', 'fake_alt_user')408 self._mock_tenant_create('1234', 'fake_alt_tenant')409 self._mock_network_create(creds, '1234', 'fake_alt_net')410 self._mock_subnet_create(creds, '1234', 'fake_alt_subnet')411 self._mock_router_create('1234', 'fake_alt_router')412 router_interface_mock = self.patch(413 'tempest.services.network.json.network_client.NetworkClient.'414 'add_router_interface_with_subnet_id')415 alt_creds = creds.get_alt_creds()416 router_interface_mock.called_once_with('1234', '1234')417 network = alt_creds.network418 subnet = alt_creds.subnet419 router = alt_creds.router420 self.assertEqual(network['id'], '1234')421 self.assertEqual(network['name'], 'fake_alt_net')422 self.assertEqual(subnet['id'], '1234')423 self.assertEqual(subnet['name'], 'fake_alt_subnet')424 self.assertEqual(router['id'], '1234')425 self.assertEqual(router['name'], 'fake_alt_router')426 @mock.patch('tempest_lib.common.rest_client.RestClient')427 def test_network_admin_creation(self, MockRestClient):428 creds = dynamic_creds.DynamicCredentialProvider(name='test class')429 self._mock_assign_user_role()430 self._mock_user_create('1234', 'fake_admin_user')431 self._mock_tenant_create('1234', 'fake_admin_tenant')432 self._mock_network_create(creds, '1234', 'fake_admin_net')433 self._mock_subnet_create(creds, '1234', 'fake_admin_subnet')434 self._mock_router_create('1234', 'fake_admin_router')435 router_interface_mock = self.patch(436 'tempest.services.network.json.network_client.NetworkClient.'437 'add_router_interface_with_subnet_id')438 self._mock_list_roles('123456', 'admin')439 admin_creds = creds.get_admin_creds()440 router_interface_mock.called_once_with('1234', '1234')441 network = admin_creds.network442 subnet = admin_creds.subnet443 router = admin_creds.router444 self.assertEqual(network['id'], '1234')445 self.assertEqual(network['name'], 'fake_admin_net')446 self.assertEqual(subnet['id'], '1234')447 self.assertEqual(subnet['name'], 'fake_admin_subnet')448 self.assertEqual(router['id'], '1234')449 self.assertEqual(router['name'], 'fake_admin_router')450 @mock.patch('tempest_lib.common.rest_client.RestClient')451 def test_no_network_resources(self, MockRestClient):452 net_dict = {453 'network': False,454 'router': False,455 'subnet': False,456 'dhcp': False,457 }458 creds = dynamic_creds.DynamicCredentialProvider(459 name='test class', network_resources=net_dict)460 self._mock_assign_user_role()461 self._mock_list_role()462 self._mock_user_create('1234', 'fake_prim_user')463 self._mock_tenant_create('1234', 'fake_prim_tenant')464 net = mock.patch.object(creds.networks_admin_client,465 'delete_network')466 net_mock = net.start()467 subnet = mock.patch.object(creds.subnets_admin_client,468 'delete_subnet')469 subnet_mock = subnet.start()470 router = mock.patch.object(creds.network_admin_client,471 'delete_router')472 router_mock = router.start()473 primary_creds = creds.get_primary_creds()474 self.assertEqual(net_mock.mock_calls, [])475 self.assertEqual(subnet_mock.mock_calls, [])476 self.assertEqual(router_mock.mock_calls, [])477 network = primary_creds.network478 subnet = primary_creds.subnet479 router = primary_creds.router480 self.assertIsNone(network)481 self.assertIsNone(subnet)482 self.assertIsNone(router)483 @mock.patch('tempest_lib.common.rest_client.RestClient')484 def test_router_without_network(self, MockRestClient):485 net_dict = {486 'network': False,487 'router': True,...

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