blob: 0199d737c8124fa994a73149509656ebe4b580ce [file] [log] [blame]
rajalakshmi-ganesanab426722013-02-08 15:49:15 +05301# 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
Sean Dague1937d092013-05-17 16:36:38 -040016from tempest.api.identity import base
Ken'ichi Ohmichi7bd25752017-03-10 10:45:39 -080017from tempest.lib.common.utils import data_utils
Andrea Frittoli7f60fa62017-09-09 16:31:34 +020018from tempest.lib.common.utils import test_utils
Ken'ichi Ohmichieeabdd22017-01-27 17:46:00 -080019from tempest.lib import decorators
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053020
21
Matthew Treinishdb2c5972014-01-31 22:18:59 +000022class EndPointsTestJSON(base.BaseIdentityV3AdminTest):
zhuflb9358202020-04-27 16:12:52 +080023 """Test keystone endpoints"""
24
Trevor McCasland87a71822018-01-05 11:45:49 -060025 # NOTE: force_tenant_isolation is true in the base class by default but
26 # overridden to false here to allow test execution for clouds using the
27 # pre-provisioned credentials provider.
28 force_tenant_isolation = False
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053029
30 @classmethod
Rohan Kanadeb645e172015-02-05 17:38:59 +053031 def setup_clients(cls):
32 super(EndPointsTestJSON, cls).setup_clients()
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053033 cls.client = cls.endpoints_client
Rohan Kanadeb645e172015-02-05 17:38:59 +053034
35 @classmethod
36 def resource_setup(cls):
37 super(EndPointsTestJSON, cls).resource_setup()
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053038 cls.service_ids = list()
Felipe Monteiro63444d62017-04-29 20:44:19 +010039
40 # Create endpoints so as to use for LIST and GET test cases
41 interfaces = ['public', 'internal']
42 cls.setup_endpoint_ids = list()
43 for i in range(2):
Andrea Frittoli7f60fa62017-09-09 16:31:34 +020044 service = cls._create_service()
45 cls.service_ids.append(service['id'])
46 cls.addClassResourceCleanup(
47 cls.services_client.delete_service, service['id'])
48
Cédric Ollivier1a457ac2019-06-02 21:47:01 +020049 region_name = data_utils.rand_name('region')
Felipe Monteiro63444d62017-04-29 20:44:19 +010050 url = data_utils.rand_url()
51 endpoint = cls.client.create_endpoint(
52 service_id=cls.service_ids[i], interface=interfaces[i],
Cédric Ollivier1a457ac2019-06-02 21:47:01 +020053 url=url, region=region_name, enabled=True)['endpoint']
54 region = cls.regions_client.show_region(region_name)['region']
55 cls.addClassResourceCleanup(
56 cls.regions_client.delete_region, region['id'])
Andrea Frittoli7f60fa62017-09-09 16:31:34 +020057 cls.addClassResourceCleanup(
58 cls.client.delete_endpoint, endpoint['id'])
Felipe Monteiro63444d62017-04-29 20:44:19 +010059 cls.setup_endpoint_ids.append(endpoint['id'])
60
61 @classmethod
62 def _create_service(cls, s_name=None, s_type=None, s_description=None):
63 if s_name is None:
64 s_name = data_utils.rand_name('service')
65 if s_type is None:
66 s_type = data_utils.rand_name('type')
67 if s_description is None:
68 s_description = data_utils.rand_name('description')
zhufl95a32812017-03-01 17:52:21 +080069 service_data = (
Yaroslav Lobankov69d90562015-12-18 12:06:40 +030070 cls.services_client.create_service(name=s_name, type=s_type,
71 description=s_description))
Andrea Frittoli7f60fa62017-09-09 16:31:34 +020072 return service_data['service']
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053073
Ken'ichi Ohmichieeabdd22017-01-27 17:46:00 -080074 @decorators.idempotent_id('c19ecf90-240e-4e23-9966-21cee3f6a618')
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053075 def test_list_endpoints(self):
zhuflb9358202020-04-27 16:12:52 +080076 """Test listing keystone endpoints by filters"""
Felipe Monteiro63444d62017-04-29 20:44:19 +010077 # Get the list of all the endpoints.
John Warren47f504b2015-08-11 20:25:05 +000078 fetched_endpoints = self.client.list_endpoints()['endpoints']
Felipe Monteiro63444d62017-04-29 20:44:19 +010079 fetched_endpoint_ids = [e['id'] for e in fetched_endpoints]
80 # Check that all the created endpoints are present in
81 # "fetched_endpoints".
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053082 missing_endpoints =\
Felipe Monteiro63444d62017-04-29 20:44:19 +010083 [e for e in self.setup_endpoint_ids
84 if e not in fetched_endpoint_ids]
85 self.assertEqual(0, len(missing_endpoints),
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053086 "Failed to find endpoint %s in fetched list" %
87 ', '.join(str(e) for e in missing_endpoints))
88
Felipe Monteiro63444d62017-04-29 20:44:19 +010089 # Check that filtering endpoints by service_id works.
90 fetched_endpoints_for_service = self.client.list_endpoints(
91 service_id=self.service_ids[0])['endpoints']
92 fetched_endpoints_for_alt_service = self.client.list_endpoints(
93 service_id=self.service_ids[1])['endpoints']
94
95 # Assert that both filters returned the correct result.
96 self.assertEqual(1, len(fetched_endpoints_for_service))
97 self.assertEqual(1, len(fetched_endpoints_for_alt_service))
98 self.assertEqual(set(self.setup_endpoint_ids),
99 set([fetched_endpoints_for_service[0]['id'],
100 fetched_endpoints_for_alt_service[0]['id']]))
101
102 # Check that filtering endpoints by interface works.
103 fetched_public_endpoints = self.client.list_endpoints(
104 interface='public')['endpoints']
105 fetched_internal_endpoints = self.client.list_endpoints(
106 interface='internal')['endpoints']
107
108 # Check that the expected endpoint_id is present per filter. [0] is
109 # public and [1] is internal.
110 self.assertIn(self.setup_endpoint_ids[0],
111 [e['id'] for e in fetched_public_endpoints])
112 self.assertIn(self.setup_endpoint_ids[1],
113 [e['id'] for e in fetched_internal_endpoints])
114
Ken'ichi Ohmichieeabdd22017-01-27 17:46:00 -0800115 @decorators.idempotent_id('0e2446d2-c1fd-461b-a729-b9e73e3e3b37')
apetrov5ae389f2016-01-21 16:16:13 +0100116 def test_create_list_show_delete_endpoint(self):
zhuflb9358202020-04-27 16:12:52 +0800117 """Test creating, listing, showing and deleting keystone endpoint"""
Cédric Ollivier1a457ac2019-06-02 21:47:01 +0200118 region_name = data_utils.rand_name('region')
Dolph Mathews064e9652014-07-11 10:54:38 -0500119 url = data_utils.rand_url()
rajalakshmi-ganesanab426722013-02-08 15:49:15 +0530120 interface = 'public'
Felipe Monteiro63444d62017-04-29 20:44:19 +0100121 endpoint = self.client.create_endpoint(service_id=self.service_ids[0],
Yaroslav Lobankov2b459ec2015-11-09 15:01:48 +0300122 interface=interface,
Cédric Ollivier1a457ac2019-06-02 21:47:01 +0200123 url=url, region=region_name,
Yaroslav Lobankov2b459ec2015-11-09 15:01:48 +0300124 enabled=True)['endpoint']
Cédric Ollivier1a457ac2019-06-02 21:47:01 +0200125 region = self.regions_client.show_region(region_name)['region']
126 self.addCleanup(self.regions_client.delete_region, region['id'])
Andrea Frittoli7f60fa62017-09-09 16:31:34 +0200127 self.addCleanup(test_utils.call_and_ignore_notfound_exc,
128 self.client.delete_endpoint, endpoint['id'])
Giulio Fidente92f77192013-08-26 17:13:28 +0200129 # Asserting Create Endpoint response body
Cédric Ollivier1a457ac2019-06-02 21:47:01 +0200130 self.assertEqual(region_name, endpoint['region'])
Giulio Fidente92f77192013-08-26 17:13:28 +0200131 self.assertEqual(url, endpoint['url'])
apetrov5ae389f2016-01-21 16:16:13 +0100132
Giulio Fidente92f77192013-08-26 17:13:28 +0200133 # Checking if created endpoint is present in the list of endpoints
John Warren47f504b2015-08-11 20:25:05 +0000134 fetched_endpoints = self.client.list_endpoints()['endpoints']
Giulio Fidente92f77192013-08-26 17:13:28 +0200135 fetched_endpoints_id = [e['id'] for e in fetched_endpoints]
136 self.assertIn(endpoint['id'], fetched_endpoints_id)
apetrov5ae389f2016-01-21 16:16:13 +0100137
138 # Show endpoint
139 fetched_endpoint = (
140 self.client.show_endpoint(endpoint['id'])['endpoint'])
141 # Asserting if the attributes of endpoint are the same
Felipe Monteiro63444d62017-04-29 20:44:19 +0100142 self.assertEqual(self.service_ids[0], fetched_endpoint['service_id'])
apetrov5ae389f2016-01-21 16:16:13 +0100143 self.assertEqual(interface, fetched_endpoint['interface'])
144 self.assertEqual(url, fetched_endpoint['url'])
Cédric Ollivier1a457ac2019-06-02 21:47:01 +0200145 self.assertEqual(region_name, fetched_endpoint['region'])
apetrov5ae389f2016-01-21 16:16:13 +0100146 self.assertEqual(True, fetched_endpoint['enabled'])
147
Giulio Fidente92f77192013-08-26 17:13:28 +0200148 # Deleting the endpoint created in this method
ghanshyama2016372014-10-24 11:15:01 +0900149 self.client.delete_endpoint(endpoint['id'])
apetrov5ae389f2016-01-21 16:16:13 +0100150
Giulio Fidente92f77192013-08-26 17:13:28 +0200151 # Checking whether endpoint is deleted successfully
John Warren47f504b2015-08-11 20:25:05 +0000152 fetched_endpoints = self.client.list_endpoints()['endpoints']
Giulio Fidente92f77192013-08-26 17:13:28 +0200153 fetched_endpoints_id = [e['id'] for e in fetched_endpoints]
154 self.assertNotIn(endpoint['id'], fetched_endpoints_id)
rajalakshmi-ganesanab426722013-02-08 15:49:15 +0530155
Jordan Pittier3b46d272017-04-12 16:17:28 +0200156 @decorators.attr(type='smoke')
Ken'ichi Ohmichieeabdd22017-01-27 17:46:00 -0800157 @decorators.idempotent_id('37e8f15e-ee7c-4657-a1e7-f6b61e375eff')
rajalakshmi-ganesanab426722013-02-08 15:49:15 +0530158 def test_update_endpoint(self):
zhuflb9358202020-04-27 16:12:52 +0800159 """Test updating keystone endpoint"""
Andrea Frittoli7f60fa62017-09-09 16:31:34 +0200160 # NOTE(zhufl) Service2 should be created before endpoint_for_update
161 # is created, because Service2 must be deleted after
162 # endpoint_for_update is deleted, otherwise we will get a 404 error
163 # when deleting endpoint_for_update if endpoint's service is deleted.
164
165 # Creating service for updating endpoint with new service ID
166 s_name = data_utils.rand_name('service')
167 s_type = data_utils.rand_name('type')
168 s_description = data_utils.rand_name('description')
169 service2 = self._create_service(s_name=s_name, s_type=s_type,
170 s_description=s_description)
171 self.addCleanup(self.services_client.delete_service, service2['id'])
172
173 # Creating an endpoint so as to check update endpoint with new values
Cédric Ollivier1a457ac2019-06-02 21:47:01 +0200174 region1_name = data_utils.rand_name('region')
Dolph Mathews064e9652014-07-11 10:54:38 -0500175 url1 = data_utils.rand_url()
rajalakshmi-ganesanab426722013-02-08 15:49:15 +0530176 interface1 = 'public'
Yaroslav Lobankov2b459ec2015-11-09 15:01:48 +0300177 endpoint_for_update = (
Felipe Monteiro63444d62017-04-29 20:44:19 +0100178 self.client.create_endpoint(service_id=self.service_ids[0],
Yaroslav Lobankov2b459ec2015-11-09 15:01:48 +0300179 interface=interface1,
Cédric Ollivier1a457ac2019-06-02 21:47:01 +0200180 url=url1, region=region1_name,
Yaroslav Lobankov2b459ec2015-11-09 15:01:48 +0300181 enabled=True)['endpoint'])
Cédric Ollivier1a457ac2019-06-02 21:47:01 +0200182 region1 = self.regions_client.show_region(region1_name)['region']
183 self.addCleanup(self.regions_client.delete_region, region1['id'])
Andrea Frittoli7f60fa62017-09-09 16:31:34 +0200184
Attila Fazekasf7f34f92013-08-01 17:01:44 +0200185 # Updating endpoint with new values
Cédric Ollivier1a457ac2019-06-02 21:47:01 +0200186 region2_name = data_utils.rand_name('region')
Dolph Mathews064e9652014-07-11 10:54:38 -0500187 url2 = data_utils.rand_url()
rajalakshmi-ganesanab426722013-02-08 15:49:15 +0530188 interface2 = 'internal'
Yaroslav Lobankov2b459ec2015-11-09 15:01:48 +0300189 endpoint = self.client.update_endpoint(endpoint_for_update['id'],
190 service_id=service2['id'],
191 interface=interface2,
Cédric Ollivier1a457ac2019-06-02 21:47:01 +0200192 url=url2, region=region2_name,
Yaroslav Lobankov2b459ec2015-11-09 15:01:48 +0300193 enabled=False)['endpoint']
Cédric Ollivier1a457ac2019-06-02 21:47:01 +0200194 region2 = self.regions_client.show_region(region2_name)['region']
195 self.addCleanup(self.regions_client.delete_region, region2['id'])
196 self.addCleanup(self.client.delete_endpoint, endpoint_for_update['id'])
197
Attila Fazekasf7f34f92013-08-01 17:01:44 +0200198 # Asserting if the attributes of endpoint are updated
Pranav Salunke9b3029c2014-05-25 00:01:05 +0530199 self.assertEqual(service2['id'], endpoint['service_id'])
rajalakshmi-ganesanab426722013-02-08 15:49:15 +0530200 self.assertEqual(interface2, endpoint['interface'])
201 self.assertEqual(url2, endpoint['url'])
Cédric Ollivier1a457ac2019-06-02 21:47:01 +0200202 self.assertEqual(region2_name, endpoint['region'])
Ken'ichi Ohmichi73cb70b2015-04-17 02:31:12 +0000203 self.assertEqual(False, endpoint['enabled'])