How to use _mock_list_role method in tempest

Best Python code snippet using tempest_python

test_dynamic_creds.py

Source:test_dynamic_creds.py Github

copy

Full Screen

...101 'assign_user_role',102 return_value=(service_client.ResponseBody103 (200, {}))))104 return tenant_fix105 def _mock_list_role(self):106 roles_fix = self.useFixture(mockpatch.PatchObject(107 json_roles_client.RolesClient,108 'list_roles',109 return_value=(service_client.ResponseBody110 (200, {'roles': [{'id': '1',111 'name': 'FakeRole'}]}))))112 return roles_fix113 def _mock_list_ec2_credentials(self, user_id, tenant_id):114 ec2_creds_fix = self.useFixture(mockpatch.PatchObject(115 json_users_client.UsersClient,116 'list_user_ec2_credentials',117 return_value=(service_client.ResponseBody118 (200, {'credentials': [{119 'access': 'fake_access',120 'secret': 'fake_secret',121 'tenant_id': tenant_id,122 'user_id': user_id,123 'trust_id': None}]}))))124 return ec2_creds_fix125 def _mock_network_create(self, iso_creds, id, name):126 net_fix = self.useFixture(mockpatch.PatchObject(127 iso_creds.networks_admin_client,128 'create_network',129 return_value={'network': {'id': id, 'name': name}}))130 return net_fix131 def _mock_subnet_create(self, iso_creds, id, name):132 subnet_fix = self.useFixture(mockpatch.PatchObject(133 iso_creds.subnets_admin_client,134 'create_subnet',135 return_value={'subnet': {'id': id, 'name': name}}))136 return subnet_fix137 def _mock_router_create(self, id, name):138 router_fix = self.useFixture(mockpatch.PatchObject(139 json_network_client.NetworkClient,140 'create_router',141 return_value={'router': {'id': id, 'name': name}}))142 return router_fix143 @mock.patch('tempest_lib.common.rest_client.RestClient')144 def test_primary_creds(self, MockRestClient):145 cfg.CONF.set_default('neutron', False, 'service_available')146 creds = dynamic_creds.DynamicCredentialProvider(**self.fixed_params)147 self._mock_assign_user_role()148 self._mock_list_role()149 self._mock_tenant_create('1234', 'fake_prim_tenant')150 self._mock_user_create('1234', 'fake_prim_user')151 primary_creds = creds.get_primary_creds()152 self.assertEqual(primary_creds.username, 'fake_prim_user')153 self.assertEqual(primary_creds.tenant_name, 'fake_prim_tenant')154 # Verify IDs155 self.assertEqual(primary_creds.tenant_id, '1234')156 self.assertEqual(primary_creds.user_id, '1234')157 @mock.patch('tempest_lib.common.rest_client.RestClient')158 def test_admin_creds(self, MockRestClient):159 cfg.CONF.set_default('neutron', False, 'service_available')160 creds = dynamic_creds.DynamicCredentialProvider(**self.fixed_params)161 self._mock_list_roles('1234', 'admin')162 self._mock_user_create('1234', 'fake_admin_user')163 self._mock_tenant_create('1234', 'fake_admin_tenant')164 user_mock = mock.patch.object(json_roles_client.RolesClient,165 'assign_user_role')166 user_mock.start()167 self.addCleanup(user_mock.stop)168 with mock.patch.object(json_roles_client.RolesClient,169 'assign_user_role') as user_mock:170 admin_creds = creds.get_admin_creds()171 user_mock.assert_has_calls([172 mock.call('1234', '1234', '1234')])173 self.assertEqual(admin_creds.username, 'fake_admin_user')174 self.assertEqual(admin_creds.tenant_name, 'fake_admin_tenant')175 # Verify IDs176 self.assertEqual(admin_creds.tenant_id, '1234')177 self.assertEqual(admin_creds.user_id, '1234')178 @mock.patch('tempest_lib.common.rest_client.RestClient')179 def test_role_creds(self, MockRestClient):180 cfg.CONF.set_default('neutron', False, 'service_available')181 creds = dynamic_creds.DynamicCredentialProvider(**self.fixed_params)182 self._mock_list_2_roles()183 self._mock_user_create('1234', 'fake_role_user')184 self._mock_tenant_create('1234', 'fake_role_tenant')185 user_mock = mock.patch.object(json_roles_client.RolesClient,186 'assign_user_role')187 user_mock.start()188 self.addCleanup(user_mock.stop)189 with mock.patch.object(json_roles_client.RolesClient,190 'assign_user_role') as user_mock:191 role_creds = creds.get_creds_by_roles(192 roles=['role1', 'role2'])193 calls = user_mock.mock_calls194 # Assert that the role creation is called with the 2 specified roles195 self.assertEqual(len(calls), 2)196 args = map(lambda x: x[1], calls)197 args = list(args)198 self.assertIn(('1234', '1234', '1234'), args)199 self.assertIn(('1234', '1234', '12345'), args)200 self.assertEqual(role_creds.username, 'fake_role_user')201 self.assertEqual(role_creds.tenant_name, 'fake_role_tenant')202 # Verify IDs203 self.assertEqual(role_creds.tenant_id, '1234')204 self.assertEqual(role_creds.user_id, '1234')205 @mock.patch('tempest_lib.common.rest_client.RestClient')206 def test_all_cred_cleanup(self, MockRestClient):207 cfg.CONF.set_default('neutron', False, 'service_available')208 creds = dynamic_creds.DynamicCredentialProvider(**self.fixed_params)209 self._mock_assign_user_role()210 self._mock_list_role()211 self._mock_tenant_create('1234', 'fake_prim_tenant')212 self._mock_user_create('1234', 'fake_prim_user')213 creds.get_primary_creds()214 self._mock_tenant_create('12345', 'fake_alt_tenant')215 self._mock_user_create('12345', 'fake_alt_user')216 creds.get_alt_creds()217 self._mock_tenant_create('123456', 'fake_admin_tenant')218 self._mock_user_create('123456', 'fake_admin_user')219 self._mock_list_roles('123456', 'admin')220 creds.get_admin_creds()221 user_mock = self.patch(222 'tempest.services.identity.v2.json.users_client.'223 'UsersClient.delete_user')224 tenant_mock = self.patch(225 'tempest.services.identity.v2.json.tenants_client.'226 'TenantsClient.delete_tenant')227 creds.clear_creds()228 # Verify user delete calls229 calls = user_mock.mock_calls230 self.assertEqual(len(calls), 3)231 args = map(lambda x: x[1][0], calls)232 args = list(args)233 self.assertIn('1234', args)234 self.assertIn('12345', args)235 self.assertIn('123456', args)236 # Verify tenant delete calls237 calls = tenant_mock.mock_calls238 self.assertEqual(len(calls), 3)239 args = map(lambda x: x[1][0], calls)240 args = list(args)241 self.assertIn('1234', args)242 self.assertIn('12345', args)243 self.assertIn('123456', args)244 @mock.patch('tempest_lib.common.rest_client.RestClient')245 def test_alt_creds(self, MockRestClient):246 cfg.CONF.set_default('neutron', False, 'service_available')247 creds = dynamic_creds.DynamicCredentialProvider(**self.fixed_params)248 self._mock_assign_user_role()249 self._mock_list_role()250 self._mock_user_create('1234', 'fake_alt_user')251 self._mock_tenant_create('1234', 'fake_alt_tenant')252 alt_creds = creds.get_alt_creds()253 self.assertEqual(alt_creds.username, 'fake_alt_user')254 self.assertEqual(alt_creds.tenant_name, 'fake_alt_tenant')255 # Verify IDs256 self.assertEqual(alt_creds.tenant_id, '1234')257 self.assertEqual(alt_creds.user_id, '1234')258 @mock.patch('tempest_lib.common.rest_client.RestClient')259 def test_no_network_creation_with_config_set(self, MockRestClient):260 cfg.CONF.set_default('create_isolated_networks', False, group='auth')261 creds = dynamic_creds.DynamicCredentialProvider(**self.fixed_params)262 self._mock_assign_user_role()263 self._mock_list_role()264 self._mock_user_create('1234', 'fake_prim_user')265 self._mock_tenant_create('1234', 'fake_prim_tenant')266 net = mock.patch.object(creds.networks_admin_client,267 'delete_network')268 net_mock = net.start()269 subnet = mock.patch.object(creds.subnets_admin_client,270 'delete_subnet')271 subnet_mock = subnet.start()272 router = mock.patch.object(creds.network_admin_client,273 'delete_router')274 router_mock = router.start()275 primary_creds = creds.get_primary_creds()276 self.assertEqual(net_mock.mock_calls, [])277 self.assertEqual(subnet_mock.mock_calls, [])278 self.assertEqual(router_mock.mock_calls, [])279 network = primary_creds.network280 subnet = primary_creds.subnet281 router = primary_creds.router282 self.assertIsNone(network)283 self.assertIsNone(subnet)284 self.assertIsNone(router)285 @mock.patch('tempest_lib.common.rest_client.RestClient')286 def test_network_creation(self, MockRestClient):287 creds = dynamic_creds.DynamicCredentialProvider(**self.fixed_params)288 self._mock_assign_user_role()289 self._mock_list_role()290 self._mock_user_create('1234', 'fake_prim_user')291 self._mock_tenant_create('1234', 'fake_prim_tenant')292 self._mock_network_create(creds, '1234', 'fake_net')293 self._mock_subnet_create(creds, '1234', 'fake_subnet')294 self._mock_router_create('1234', 'fake_router')295 router_interface_mock = self.patch(296 'tempest.services.network.json.network_client.NetworkClient.'297 'add_router_interface_with_subnet_id')298 primary_creds = creds.get_primary_creds()299 router_interface_mock.assert_called_once_with('1234', '1234')300 network = primary_creds.network301 subnet = primary_creds.subnet302 router = primary_creds.router303 self.assertEqual(network['id'], '1234')304 self.assertEqual(network['name'], 'fake_net')305 self.assertEqual(subnet['id'], '1234')306 self.assertEqual(subnet['name'], 'fake_subnet')307 self.assertEqual(router['id'], '1234')308 self.assertEqual(router['name'], 'fake_router')309 @mock.patch('tempest_lib.common.rest_client.RestClient')310 def test_network_cleanup(self, MockRestClient):311 def side_effect(**args):312 return {"security_groups": [{"tenant_id": args['tenant_id'],313 "name": args['name'],314 "description": args['name'],315 "security_group_rules": [],316 "id": "sg-%s" % args['tenant_id']}]}317 creds = dynamic_creds.DynamicCredentialProvider(**self.fixed_params)318 # Create primary tenant and network319 self._mock_assign_user_role()320 self._mock_list_role()321 self._mock_user_create('1234', 'fake_prim_user')322 self._mock_tenant_create('1234', 'fake_prim_tenant')323 self._mock_network_create(creds, '1234', 'fake_net')324 self._mock_subnet_create(creds, '1234', 'fake_subnet')325 self._mock_router_create('1234', 'fake_router')326 router_interface_mock = self.patch(327 'tempest.services.network.json.network_client.NetworkClient.'328 'add_router_interface_with_subnet_id')329 creds.get_primary_creds()330 router_interface_mock.assert_called_once_with('1234', '1234')331 router_interface_mock.reset_mock()332 # Create alternate tenant and network333 self._mock_user_create('12345', 'fake_alt_user')334 self._mock_tenant_create('12345', 'fake_alt_tenant')335 self._mock_network_create(creds, '12345', 'fake_alt_net')336 self._mock_subnet_create(creds, '12345', 'fake_alt_subnet')337 self._mock_router_create('12345', 'fake_alt_router')338 creds.get_alt_creds()339 router_interface_mock.assert_called_once_with('12345', '12345')340 router_interface_mock.reset_mock()341 # Create admin tenant and networks342 self._mock_user_create('123456', 'fake_admin_user')343 self._mock_tenant_create('123456', 'fake_admin_tenant')344 self._mock_network_create(creds, '123456', 'fake_admin_net')345 self._mock_subnet_create(creds, '123456', 'fake_admin_subnet')346 self._mock_router_create('123456', 'fake_admin_router')347 self._mock_list_roles('123456', 'admin')348 creds.get_admin_creds()349 self.patch('tempest.services.identity.v2.json.users_client.'350 'UsersClient.delete_user')351 self.patch('tempest.services.identity.v2.json.tenants_client.'352 'TenantsClient.delete_tenant')353 net = mock.patch.object(creds.networks_admin_client,354 'delete_network')355 net_mock = net.start()356 subnet = mock.patch.object(creds.subnets_admin_client,357 'delete_subnet')358 subnet_mock = subnet.start()359 router = mock.patch.object(creds.network_admin_client,360 'delete_router')361 router_mock = router.start()362 remove_router_interface_mock = self.patch(363 'tempest.services.network.json.network_client.NetworkClient.'364 'remove_router_interface_with_subnet_id')365 return_values = ({'status': 200}, {'ports': []})366 port_list_mock = mock.patch.object(creds.ports_admin_client,367 'list_ports',368 return_value=return_values)369 port_list_mock.start()370 secgroup_list_mock = mock.patch.object(371 creds.security_groups_admin_client,372 'list_security_groups',373 side_effect=side_effect)374 secgroup_list_mock.start()375 return_values = (fake_http.fake_httplib({}, status=204), {})376 remove_secgroup_mock = self.patch(377 'tempest.services.network.json.security_groups_client.'378 'SecurityGroupsClient.delete', return_value=return_values)379 creds.clear_creds()380 # Verify default security group delete381 calls = remove_secgroup_mock.mock_calls382 self.assertEqual(len(calls), 3)383 args = map(lambda x: x[1][0], calls)384 args = list(args)385 self.assertIn('v2.0/security-groups/sg-1234', args)386 self.assertIn('v2.0/security-groups/sg-12345', args)387 self.assertIn('v2.0/security-groups/sg-123456', args)388 # Verify remove router interface calls389 calls = remove_router_interface_mock.mock_calls390 self.assertEqual(len(calls), 3)391 args = map(lambda x: x[1], calls)392 args = list(args)393 self.assertIn(('1234', '1234'), args)394 self.assertIn(('12345', '12345'), args)395 self.assertIn(('123456', '123456'), args)396 # Verify network delete calls397 calls = net_mock.mock_calls398 self.assertEqual(len(calls), 3)399 args = map(lambda x: x[1][0], calls)400 args = list(args)401 self.assertIn('1234', args)402 self.assertIn('12345', args)403 self.assertIn('123456', args)404 # Verify subnet delete calls405 calls = subnet_mock.mock_calls406 self.assertEqual(len(calls), 3)407 args = map(lambda x: x[1][0], calls)408 args = list(args)409 self.assertIn('1234', args)410 self.assertIn('12345', args)411 self.assertIn('123456', args)412 # Verify router delete calls413 calls = router_mock.mock_calls414 self.assertEqual(len(calls), 3)415 args = map(lambda x: x[1][0], calls)416 args = list(args)417 self.assertIn('1234', args)418 self.assertIn('12345', args)419 self.assertIn('123456', args)420 @mock.patch('tempest_lib.common.rest_client.RestClient')421 def test_network_alt_creation(self, MockRestClient):422 creds = dynamic_creds.DynamicCredentialProvider(**self.fixed_params)423 self._mock_assign_user_role()424 self._mock_list_role()425 self._mock_user_create('1234', 'fake_alt_user')426 self._mock_tenant_create('1234', 'fake_alt_tenant')427 self._mock_network_create(creds, '1234', 'fake_alt_net')428 self._mock_subnet_create(creds, '1234', 'fake_alt_subnet')429 self._mock_router_create('1234', 'fake_alt_router')430 router_interface_mock = self.patch(431 'tempest.services.network.json.network_client.NetworkClient.'432 'add_router_interface_with_subnet_id')433 alt_creds = creds.get_alt_creds()434 router_interface_mock.assert_called_once_with('1234', '1234')435 network = alt_creds.network436 subnet = alt_creds.subnet437 router = alt_creds.router438 self.assertEqual(network['id'], '1234')439 self.assertEqual(network['name'], 'fake_alt_net')440 self.assertEqual(subnet['id'], '1234')441 self.assertEqual(subnet['name'], 'fake_alt_subnet')442 self.assertEqual(router['id'], '1234')443 self.assertEqual(router['name'], 'fake_alt_router')444 @mock.patch('tempest_lib.common.rest_client.RestClient')445 def test_network_admin_creation(self, MockRestClient):446 creds = dynamic_creds.DynamicCredentialProvider(**self.fixed_params)447 self._mock_assign_user_role()448 self._mock_user_create('1234', 'fake_admin_user')449 self._mock_tenant_create('1234', 'fake_admin_tenant')450 self._mock_network_create(creds, '1234', 'fake_admin_net')451 self._mock_subnet_create(creds, '1234', 'fake_admin_subnet')452 self._mock_router_create('1234', 'fake_admin_router')453 router_interface_mock = self.patch(454 'tempest.services.network.json.network_client.NetworkClient.'455 'add_router_interface_with_subnet_id')456 self._mock_list_roles('123456', 'admin')457 admin_creds = creds.get_admin_creds()458 router_interface_mock.assert_called_once_with('1234', '1234')459 network = admin_creds.network460 subnet = admin_creds.subnet461 router = admin_creds.router462 self.assertEqual(network['id'], '1234')463 self.assertEqual(network['name'], 'fake_admin_net')464 self.assertEqual(subnet['id'], '1234')465 self.assertEqual(subnet['name'], 'fake_admin_subnet')466 self.assertEqual(router['id'], '1234')467 self.assertEqual(router['name'], 'fake_admin_router')468 @mock.patch('tempest_lib.common.rest_client.RestClient')469 def test_no_network_resources(self, MockRestClient):470 net_dict = {471 'network': False,472 'router': False,473 'subnet': False,474 'dhcp': False,475 }476 creds = dynamic_creds.DynamicCredentialProvider(477 network_resources=net_dict,478 **self.fixed_params)479 self._mock_assign_user_role()480 self._mock_list_role()481 self._mock_user_create('1234', 'fake_prim_user')482 self._mock_tenant_create('1234', 'fake_prim_tenant')483 net = mock.patch.object(creds.networks_admin_client,484 'delete_network')485 net_mock = net.start()486 subnet = mock.patch.object(creds.subnets_admin_client,487 'delete_subnet')488 subnet_mock = subnet.start()489 router = mock.patch.object(creds.network_admin_client,490 'delete_router')491 router_mock = router.start()492 primary_creds = creds.get_primary_creds()493 self.assertEqual(net_mock.mock_calls, [])494 self.assertEqual(subnet_mock.mock_calls, [])495 self.assertEqual(router_mock.mock_calls, [])496 network = primary_creds.network497 subnet = primary_creds.subnet498 router = primary_creds.router499 self.assertIsNone(network)500 self.assertIsNone(subnet)501 self.assertIsNone(router)502 @mock.patch('tempest_lib.common.rest_client.RestClient')503 def test_router_without_network(self, MockRestClient):504 net_dict = {505 'network': False,506 'router': True,507 'subnet': False,508 'dhcp': False,509 }510 creds = dynamic_creds.DynamicCredentialProvider(511 network_resources=net_dict,512 **self.fixed_params)513 self._mock_assign_user_role()514 self._mock_list_role()515 self._mock_user_create('1234', 'fake_prim_user')516 self._mock_tenant_create('1234', 'fake_prim_tenant')517 self.assertRaises(exceptions.InvalidConfiguration,518 creds.get_primary_creds)519 @mock.patch('tempest_lib.common.rest_client.RestClient')520 def test_subnet_without_network(self, MockRestClient):521 net_dict = {522 'network': False,523 'router': False,524 'subnet': True,525 'dhcp': False,526 }527 creds = dynamic_creds.DynamicCredentialProvider(528 network_resources=net_dict,529 **self.fixed_params)530 self._mock_assign_user_role()531 self._mock_list_role()532 self._mock_user_create('1234', 'fake_prim_user')533 self._mock_tenant_create('1234', 'fake_prim_tenant')534 self.assertRaises(exceptions.InvalidConfiguration,535 creds.get_primary_creds)536 @mock.patch('tempest_lib.common.rest_client.RestClient')537 def test_dhcp_without_subnet(self, MockRestClient):538 net_dict = {539 'network': False,540 'router': False,541 'subnet': False,542 'dhcp': True,543 }544 creds = dynamic_creds.DynamicCredentialProvider(545 network_resources=net_dict,546 **self.fixed_params)547 self._mock_assign_user_role()548 self._mock_list_role()549 self._mock_user_create('1234', 'fake_prim_user')550 self._mock_tenant_create('1234', 'fake_prim_tenant')551 self.assertRaises(exceptions.InvalidConfiguration,...

Full Screen

Full Screen

test_tenant_isolation.py

Source:test_tenant_isolation.py Github

copy

Full Screen

...68 'assign_user_role',69 return_value=({'status': 200},70 {})))71 return tenant_fix72 def _mock_list_role(self):73 roles_fix = self.useFixture(mockpatch.PatchObject(74 json_iden_client.IdentityClientJSON,75 'list_roles',76 return_value=({'status': 200},77 [{'id': '1', 'name': 'FakeRole'}])))78 return roles_fix79 def _mock_network_create(self, iso_creds, id, name):80 net_fix = self.useFixture(mockpatch.PatchObject(81 iso_creds.network_admin_client,82 'create_network',83 return_value={'network': {'id': id, 'name': name}}))84 return net_fix85 def _mock_subnet_create(self, iso_creds, id, name):86 subnet_fix = self.useFixture(mockpatch.PatchObject(87 iso_creds.network_admin_client,88 'create_subnet',89 return_value={'subnet': {'id': id, 'name': name}}))90 return subnet_fix91 def _mock_router_create(self, id, name):92 router_fix = self.useFixture(mockpatch.PatchObject(93 json_network_client.NetworkClientJSON,94 'create_router',95 return_value={'router': {'id': id, 'name': name}}))96 return router_fix97 @mock.patch('tempest.common.rest_client.RestClient')98 def test_primary_creds(self, MockRestClient):99 cfg.CONF.set_default('neutron', False, 'service_available')100 iso_creds = isolated_creds.IsolatedCreds('test class',101 password='fake_password')102 self._mock_assign_user_role()103 self._mock_list_role()104 self._mock_tenant_create('1234', 'fake_prim_tenant')105 self._mock_user_create('1234', 'fake_prim_user')106 primary_creds = iso_creds.get_primary_creds()107 self.assertEqual(primary_creds.username, 'fake_prim_user')108 self.assertEqual(primary_creds.tenant_name, 'fake_prim_tenant')109 # Verify IDs110 self.assertEqual(primary_creds.tenant_id, '1234')111 self.assertEqual(primary_creds.user_id, '1234')112 @mock.patch('tempest.common.rest_client.RestClient')113 def test_admin_creds(self, MockRestClient):114 cfg.CONF.set_default('neutron', False, 'service_available')115 iso_creds = isolated_creds.IsolatedCreds('test class',116 password='fake_password')117 self._mock_list_roles('1234', 'admin')118 self._mock_user_create('1234', 'fake_admin_user')119 self._mock_tenant_create('1234', 'fake_admin_tenant')120 user_mock = mock.patch.object(json_iden_client.IdentityClientJSON,121 'assign_user_role')122 user_mock.start()123 self.addCleanup(user_mock.stop)124 with mock.patch.object(json_iden_client.IdentityClientJSON,125 'assign_user_role') as user_mock:126 admin_creds = iso_creds.get_admin_creds()127 user_mock.assert_has_calls([128 mock.call('1234', '1234', '1'),129 mock.call('1234', '1234', '1234')])130 self.assertEqual(admin_creds.username, 'fake_admin_user')131 self.assertEqual(admin_creds.tenant_name, 'fake_admin_tenant')132 # Verify IDs133 self.assertEqual(admin_creds.tenant_id, '1234')134 self.assertEqual(admin_creds.user_id, '1234')135 @mock.patch('tempest.common.rest_client.RestClient')136 def test_all_cred_cleanup(self, MockRestClient):137 cfg.CONF.set_default('neutron', False, 'service_available')138 iso_creds = isolated_creds.IsolatedCreds('test class',139 password='fake_password')140 self._mock_assign_user_role()141 roles_fix = self._mock_list_role()142 tenant_fix = self._mock_tenant_create('1234', 'fake_prim_tenant')143 user_fix = self._mock_user_create('1234', 'fake_prim_user')144 iso_creds.get_primary_creds()145 tenant_fix.cleanUp()146 user_fix.cleanUp()147 tenant_fix = self._mock_tenant_create('12345', 'fake_alt_tenant')148 user_fix = self._mock_user_create('12345', 'fake_alt_user')149 iso_creds.get_alt_creds()150 tenant_fix.cleanUp()151 user_fix.cleanUp()152 roles_fix.cleanUp()153 tenant_fix = self._mock_tenant_create('123456', 'fake_admin_tenant')154 user_fix = self._mock_user_create('123456', 'fake_admin_user')155 self._mock_list_roles('123456', 'admin')156 iso_creds.get_admin_creds()157 user_mock = self.patch(158 'tempest.services.identity.json.identity_client.'159 'IdentityClientJSON.delete_user')160 tenant_mock = self.patch(161 'tempest.services.identity.json.identity_client.'162 'IdentityClientJSON.delete_tenant')163 iso_creds.clear_isolated_creds()164 # Verify user delete calls165 calls = user_mock.mock_calls166 self.assertEqual(len(calls), 3)167 args = map(lambda x: x[1][0], calls)168 self.assertIn('1234', args)169 self.assertIn('12345', args)170 self.assertIn('123456', args)171 # Verify tenant delete calls172 calls = tenant_mock.mock_calls173 self.assertEqual(len(calls), 3)174 args = map(lambda x: x[1][0], calls)175 self.assertIn('1234', args)176 self.assertIn('12345', args)177 self.assertIn('123456', args)178 @mock.patch('tempest.common.rest_client.RestClient')179 def test_alt_creds(self, MockRestClient):180 cfg.CONF.set_default('neutron', False, 'service_available')181 iso_creds = isolated_creds.IsolatedCreds('test class',182 password='fake_password')183 self._mock_assign_user_role()184 self._mock_list_role()185 self._mock_user_create('1234', 'fake_alt_user')186 self._mock_tenant_create('1234', 'fake_alt_tenant')187 alt_creds = iso_creds.get_alt_creds()188 self.assertEqual(alt_creds.username, 'fake_alt_user')189 self.assertEqual(alt_creds.tenant_name, 'fake_alt_tenant')190 # Verify IDs191 self.assertEqual(alt_creds.tenant_id, '1234')192 self.assertEqual(alt_creds.user_id, '1234')193 @mock.patch('tempest.common.rest_client.RestClient')194 def test_network_creation(self, MockRestClient):195 iso_creds = isolated_creds.IsolatedCreds('test class',196 password='fake_password')197 self._mock_assign_user_role()198 self._mock_list_role()199 self._mock_user_create('1234', 'fake_prim_user')200 self._mock_tenant_create('1234', 'fake_prim_tenant')201 self._mock_network_create(iso_creds, '1234', 'fake_net')202 self._mock_subnet_create(iso_creds, '1234', 'fake_subnet')203 self._mock_router_create('1234', 'fake_router')204 router_interface_mock = self.patch(205 'tempest.services.network.json.network_client.NetworkClientJSON.'206 'add_router_interface_with_subnet_id')207 iso_creds.get_primary_creds()208 router_interface_mock.called_once_with('1234', '1234')209 network = iso_creds.get_primary_network()210 subnet = iso_creds.get_primary_subnet()211 router = iso_creds.get_primary_router()212 self.assertEqual(network['id'], '1234')213 self.assertEqual(network['name'], 'fake_net')214 self.assertEqual(subnet['id'], '1234')215 self.assertEqual(subnet['name'], 'fake_subnet')216 self.assertEqual(router['id'], '1234')217 self.assertEqual(router['name'], 'fake_router')218 @mock.patch('tempest.common.rest_client.RestClient')219 def test_network_cleanup(self, MockRestClient):220 def side_effect(**args):221 return {"security_groups": [{"tenant_id": args['tenant_id'],222 "name": args['name'],223 "description": args['name'],224 "security_group_rules": [],225 "id": "sg-%s" % args['tenant_id']}]}226 iso_creds = isolated_creds.IsolatedCreds('test class',227 password='fake_password')228 # Create primary tenant and network229 self._mock_assign_user_role()230 roles_fix = self._mock_list_role()231 user_fix = self._mock_user_create('1234', 'fake_prim_user')232 tenant_fix = self._mock_tenant_create('1234', 'fake_prim_tenant')233 net_fix = self._mock_network_create(iso_creds, '1234', 'fake_net')234 subnet_fix = self._mock_subnet_create(iso_creds, '1234', 'fake_subnet')235 router_fix = self._mock_router_create('1234', 'fake_router')236 router_interface_mock = self.patch(237 'tempest.services.network.json.network_client.NetworkClientJSON.'238 'add_router_interface_with_subnet_id')239 iso_creds.get_primary_creds()240 router_interface_mock.called_once_with('1234', '1234')241 router_interface_mock.reset_mock()242 tenant_fix.cleanUp()243 user_fix.cleanUp()244 net_fix.cleanUp()245 subnet_fix.cleanUp()246 router_fix.cleanUp()247 # Create alternate tenant and network248 user_fix = self._mock_user_create('12345', 'fake_alt_user')249 tenant_fix = self._mock_tenant_create('12345', 'fake_alt_tenant')250 net_fix = self._mock_network_create(iso_creds, '12345', 'fake_alt_net')251 subnet_fix = self._mock_subnet_create(iso_creds, '12345',252 'fake_alt_subnet')253 router_fix = self._mock_router_create('12345', 'fake_alt_router')254 iso_creds.get_alt_creds()255 router_interface_mock.called_once_with('12345', '12345')256 router_interface_mock.reset_mock()257 tenant_fix.cleanUp()258 user_fix.cleanUp()259 net_fix.cleanUp()260 subnet_fix.cleanUp()261 router_fix.cleanUp()262 roles_fix.cleanUp()263 # Create admin tenant and networks264 user_fix = self._mock_user_create('123456', 'fake_admin_user')265 tenant_fix = self._mock_tenant_create('123456', 'fake_admin_tenant')266 net_fix = self._mock_network_create(iso_creds, '123456',267 'fake_admin_net')268 subnet_fix = self._mock_subnet_create(iso_creds, '123456',269 'fake_admin_subnet')270 router_fix = self._mock_router_create('123456', 'fake_admin_router')271 self._mock_list_roles('123456', 'admin')272 iso_creds.get_admin_creds()273 self.patch('tempest.services.identity.json.identity_client.'274 'IdentityClientJSON.delete_user')275 self.patch('tempest.services.identity.json.identity_client.'276 'IdentityClientJSON.delete_tenant')277 net = mock.patch.object(iso_creds.network_admin_client,278 'delete_network')279 net_mock = net.start()280 subnet = mock.patch.object(iso_creds.network_admin_client,281 'delete_subnet')282 subnet_mock = subnet.start()283 router = mock.patch.object(iso_creds.network_admin_client,284 'delete_router')285 router_mock = router.start()286 remove_router_interface_mock = self.patch(287 'tempest.services.network.json.network_client.NetworkClientJSON.'288 'remove_router_interface_with_subnet_id')289 return_values = ({'status': 200}, {'ports': []})290 port_list_mock = mock.patch.object(iso_creds.network_admin_client,291 'list_ports',292 return_value=return_values)293 port_list_mock.start()294 secgroup_list_mock = mock.patch.object(iso_creds.network_admin_client,295 'list_security_groups',296 side_effect=side_effect)297 secgroup_list_mock.start()298 return_values = (fake_http.fake_httplib({}, status=204), {})299 remove_secgroup_mock = self.patch(300 'tempest.services.network.json.network_client.'301 'NetworkClientJSON.delete', return_value=return_values)302 iso_creds.clear_isolated_creds()303 # Verify default security group delete304 calls = remove_secgroup_mock.mock_calls305 self.assertEqual(len(calls), 3)306 args = map(lambda x: x[1][0], calls)307 self.assertIn('v2.0/security-groups/sg-1234', args)308 self.assertIn('v2.0/security-groups/sg-12345', args)309 self.assertIn('v2.0/security-groups/sg-123456', args)310 # Verify remove router interface calls311 calls = remove_router_interface_mock.mock_calls312 self.assertEqual(len(calls), 3)313 args = map(lambda x: x[1], calls)314 self.assertIn(('1234', '1234'), args)315 self.assertIn(('12345', '12345'), args)316 self.assertIn(('123456', '123456'), args)317 # Verify network delete calls318 calls = net_mock.mock_calls319 self.assertEqual(len(calls), 3)320 args = map(lambda x: x[1][0], calls)321 self.assertIn('1234', args)322 self.assertIn('12345', args)323 self.assertIn('123456', args)324 # Verify subnet delete calls325 calls = subnet_mock.mock_calls326 self.assertEqual(len(calls), 3)327 args = map(lambda x: x[1][0], calls)328 self.assertIn('1234', args)329 self.assertIn('12345', args)330 self.assertIn('123456', args)331 # Verify router delete calls332 calls = router_mock.mock_calls333 self.assertEqual(len(calls), 3)334 args = map(lambda x: x[1][0], calls)335 self.assertIn('1234', args)336 self.assertIn('12345', args)337 self.assertIn('123456', args)338 @mock.patch('tempest.common.rest_client.RestClient')339 def test_network_alt_creation(self, MockRestClient):340 iso_creds = isolated_creds.IsolatedCreds('test class',341 password='fake_password')342 self._mock_assign_user_role()343 self._mock_list_role()344 self._mock_user_create('1234', 'fake_alt_user')345 self._mock_tenant_create('1234', 'fake_alt_tenant')346 self._mock_network_create(iso_creds, '1234', 'fake_alt_net')347 self._mock_subnet_create(iso_creds, '1234', 'fake_alt_subnet')348 self._mock_router_create('1234', 'fake_alt_router')349 router_interface_mock = self.patch(350 'tempest.services.network.json.network_client.NetworkClientJSON.'351 'add_router_interface_with_subnet_id')352 iso_creds.get_alt_creds()353 router_interface_mock.called_once_with('1234', '1234')354 network = iso_creds.get_alt_network()355 subnet = iso_creds.get_alt_subnet()356 router = iso_creds.get_alt_router()357 self.assertEqual(network['id'], '1234')358 self.assertEqual(network['name'], 'fake_alt_net')359 self.assertEqual(subnet['id'], '1234')360 self.assertEqual(subnet['name'], 'fake_alt_subnet')361 self.assertEqual(router['id'], '1234')362 self.assertEqual(router['name'], 'fake_alt_router')363 @mock.patch('tempest.common.rest_client.RestClient')364 def test_network_admin_creation(self, MockRestClient):365 iso_creds = isolated_creds.IsolatedCreds('test class',366 password='fake_password')367 self._mock_assign_user_role()368 self._mock_user_create('1234', 'fake_admin_user')369 self._mock_tenant_create('1234', 'fake_admin_tenant')370 self._mock_network_create(iso_creds, '1234', 'fake_admin_net')371 self._mock_subnet_create(iso_creds, '1234', 'fake_admin_subnet')372 self._mock_router_create('1234', 'fake_admin_router')373 router_interface_mock = self.patch(374 'tempest.services.network.json.network_client.NetworkClientJSON.'375 'add_router_interface_with_subnet_id')376 self._mock_list_roles('123456', 'admin')377 iso_creds.get_admin_creds()378 router_interface_mock.called_once_with('1234', '1234')379 network = iso_creds.get_admin_network()380 subnet = iso_creds.get_admin_subnet()381 router = iso_creds.get_admin_router()382 self.assertEqual(network['id'], '1234')383 self.assertEqual(network['name'], 'fake_admin_net')384 self.assertEqual(subnet['id'], '1234')385 self.assertEqual(subnet['name'], 'fake_admin_subnet')386 self.assertEqual(router['id'], '1234')387 self.assertEqual(router['name'], 'fake_admin_router')388 @mock.patch('tempest.common.rest_client.RestClient')389 def test_no_network_resources(self, MockRestClient):390 net_dict = {391 'network': False,392 'router': False,393 'subnet': False,394 'dhcp': False,395 }396 iso_creds = isolated_creds.IsolatedCreds('test class',397 password='fake_password',398 network_resources=net_dict)399 self._mock_assign_user_role()400 self._mock_list_role()401 self._mock_user_create('1234', 'fake_prim_user')402 self._mock_tenant_create('1234', 'fake_prim_tenant')403 net = mock.patch.object(iso_creds.network_admin_client,404 'delete_network')405 net_mock = net.start()406 subnet = mock.patch.object(iso_creds.network_admin_client,407 'delete_subnet')408 subnet_mock = subnet.start()409 router = mock.patch.object(iso_creds.network_admin_client,410 'delete_router')411 router_mock = router.start()412 iso_creds.get_primary_creds()413 self.assertEqual(net_mock.mock_calls, [])414 self.assertEqual(subnet_mock.mock_calls, [])415 self.assertEqual(router_mock.mock_calls, [])416 network = iso_creds.get_primary_network()417 subnet = iso_creds.get_primary_subnet()418 router = iso_creds.get_primary_router()419 self.assertIsNone(network)420 self.assertIsNone(subnet)421 self.assertIsNone(router)422 @mock.patch('tempest.common.rest_client.RestClient')423 def test_router_without_network(self, MockRestClient):424 net_dict = {425 'network': False,426 'router': True,427 'subnet': False,428 'dhcp': False,429 }430 iso_creds = isolated_creds.IsolatedCreds('test class',431 password='fake_password',432 network_resources=net_dict)433 self._mock_assign_user_role()434 self._mock_list_role()435 self._mock_user_create('1234', 'fake_prim_user')436 self._mock_tenant_create('1234', 'fake_prim_tenant')437 self.assertRaises(exceptions.InvalidConfiguration,438 iso_creds.get_primary_creds)439 @mock.patch('tempest.common.rest_client.RestClient')440 def test_subnet_without_network(self, MockRestClient):441 net_dict = {442 'network': False,443 'router': False,444 'subnet': True,445 'dhcp': False,446 }447 iso_creds = isolated_creds.IsolatedCreds('test class',448 password='fake_password',449 network_resources=net_dict)450 self._mock_assign_user_role()451 self._mock_list_role()452 self._mock_user_create('1234', 'fake_prim_user')453 self._mock_tenant_create('1234', 'fake_prim_tenant')454 self.assertRaises(exceptions.InvalidConfiguration,455 iso_creds.get_primary_creds)456 @mock.patch('tempest.common.rest_client.RestClient')457 def test_dhcp_without_subnet(self, MockRestClient):458 net_dict = {459 'network': False,460 'router': False,461 'subnet': False,462 'dhcp': True,463 }464 iso_creds = isolated_creds.IsolatedCreds('test class',465 password='fake_password',466 network_resources=net_dict)467 self._mock_assign_user_role()468 self._mock_list_role()469 self._mock_user_create('1234', 'fake_prim_user')470 self._mock_tenant_create('1234', 'fake_prim_tenant')471 self.assertRaises(exceptions.InvalidConfiguration,...

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