blob: 236ce7cb9f8735682c61005d9d3d0eb31109e6cf [file] [log] [blame]
Zhenzan Zhou494b0a62015-07-17 21:06:31 +08001# Copyright 2013 OpenStack Foundation
2# All Rights Reserved.
3#
4# Licensed under the Apache License, Version 2.0 (the "License"); you may
5# not use this file except in compliance with the License. You may obtain
6# a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13# License for the specific language governing permissions and limitations
14# under the License.
15
16from tempest.api.identity import base
Ken'ichi Ohmichi7bd25752017-03-10 10:45:39 -080017from tempest.lib.common.utils import data_utils
Ken'ichi Ohmichieeabdd22017-01-27 17:46:00 -080018from tempest.lib import decorators
Zhenzan Zhou494b0a62015-07-17 21:06:31 +080019
20
21class EndPointsTestJSON(base.BaseIdentityV2AdminTest):
zhuflc16883f2020-04-16 15:31:44 +080022 """Test keystone v2 endpoints"""
Zhenzan Zhou494b0a62015-07-17 21:06:31 +080023
24 @classmethod
25 def resource_setup(cls):
26 super(EndPointsTestJSON, cls).resource_setup()
Zhenzan Zhou494b0a62015-07-17 21:06:31 +080027 s_name = data_utils.rand_name('service')
28 s_type = data_utils.rand_name('type')
29 s_description = data_utils.rand_name('description')
zhufl95a32812017-03-01 17:52:21 +080030 service_data = cls.services_client.create_service(
ghanshyam6ce39212016-06-15 13:20:11 +090031 name=s_name, type=s_type,
32 description=s_description)['OS-KSADM:service']
Saurabh Chordiyacd5f5862017-10-25 19:20:35 +053033 cls.addClassResourceCleanup(cls.services_client.delete_service,
34 service_data['id'])
zhufl95a32812017-03-01 17:52:21 +080035 cls.service_id = service_data['id']
Zhenzan Zhou494b0a62015-07-17 21:06:31 +080036 # Create endpoints so as to use for LIST and GET test cases
37 cls.setup_endpoints = list()
zhufl8e9a0732017-01-26 16:15:21 +080038 for _ in range(2):
Zhenzan Zhou494b0a62015-07-17 21:06:31 +080039 region = data_utils.rand_name('region')
40 url = data_utils.rand_url()
Daniel Mellado3f951ef2016-01-13 09:48:00 +000041 endpoint = cls.endpoints_client.create_endpoint(
Ken'ichi Ohmichib5ebadb2016-06-13 14:19:22 -070042 service_id=cls.service_id,
43 region=region,
Daniel Mellado3f951ef2016-01-13 09:48:00 +000044 publicurl=url,
45 adminurl=url,
46 internalurl=url)['endpoint']
Saurabh Chordiyacd5f5862017-10-25 19:20:35 +053047 cls.addClassResourceCleanup(cls.endpoints_client.delete_endpoint,
48 endpoint['id'])
Zhenzan Zhou494b0a62015-07-17 21:06:31 +080049 # list_endpoints() will return 'enabled' field
50 endpoint['enabled'] = True
51 cls.setup_endpoints.append(endpoint)
52
Ken'ichi Ohmichieeabdd22017-01-27 17:46:00 -080053 @decorators.idempotent_id('11f590eb-59d8-4067-8b2b-980c7f387f51')
Zhenzan Zhou494b0a62015-07-17 21:06:31 +080054 def test_list_endpoints(self):
zhuflc16883f2020-04-16 15:31:44 +080055 """Test listing keystone endpoints"""
Zhenzan Zhou494b0a62015-07-17 21:06:31 +080056 # Get a list of endpoints
Daniel Mellado3f951ef2016-01-13 09:48:00 +000057 fetched_endpoints = self.endpoints_client.list_endpoints()['endpoints']
Zhenzan Zhou494b0a62015-07-17 21:06:31 +080058 # Asserting LIST endpoints
59 missing_endpoints =\
60 [e for e in self.setup_endpoints if e not in fetched_endpoints]
Masayuki Igawaf9009b42017-04-10 14:49:29 +090061 self.assertEmpty(missing_endpoints,
Zhenzan Zhou494b0a62015-07-17 21:06:31 +080062 "Failed to find endpoint %s in fetched list" %
63 ', '.join(str(e) for e in missing_endpoints))
64
Ken'ichi Ohmichieeabdd22017-01-27 17:46:00 -080065 @decorators.idempotent_id('9974530a-aa28-4362-8403-f06db02b26c1')
Zhenzan Zhou494b0a62015-07-17 21:06:31 +080066 def test_create_list_delete_endpoint(self):
zhuflc16883f2020-04-16 15:31:44 +080067 """Test creating, listing and deleting a keystone endpoint"""
Zhenzan Zhou494b0a62015-07-17 21:06:31 +080068 region = data_utils.rand_name('region')
69 url = data_utils.rand_url()
Daniel Mellado3f951ef2016-01-13 09:48:00 +000070 endpoint = self.endpoints_client.create_endpoint(
Ken'ichi Ohmichib5ebadb2016-06-13 14:19:22 -070071 service_id=self.service_id,
72 region=region,
Daniel Mellado3f951ef2016-01-13 09:48:00 +000073 publicurl=url,
74 adminurl=url,
75 internalurl=url)['endpoint']
Zhenzan Zhou494b0a62015-07-17 21:06:31 +080076 # Asserting Create Endpoint response body
77 self.assertIn('id', endpoint)
78 self.assertEqual(region, endpoint['region'])
79 self.assertEqual(url, endpoint['publicurl'])
80 # Checking if created endpoint is present in the list of endpoints
Daniel Mellado3f951ef2016-01-13 09:48:00 +000081 fetched_endpoints = self.endpoints_client.list_endpoints()['endpoints']
Zhenzan Zhou494b0a62015-07-17 21:06:31 +080082 fetched_endpoints_id = [e['id'] for e in fetched_endpoints]
83 self.assertIn(endpoint['id'], fetched_endpoints_id)
84 # Deleting the endpoint created in this method
Daniel Mellado3f951ef2016-01-13 09:48:00 +000085 self.endpoints_client.delete_endpoint(endpoint['id'])
Zhenzan Zhou494b0a62015-07-17 21:06:31 +080086 # Checking whether endpoint is deleted successfully
Daniel Mellado3f951ef2016-01-13 09:48:00 +000087 fetched_endpoints = self.endpoints_client.list_endpoints()['endpoints']
Zhenzan Zhou494b0a62015-07-17 21:06:31 +080088 fetched_endpoints_id = [e['id'] for e in fetched_endpoints]
89 self.assertNotIn(endpoint['id'], fetched_endpoints_id)