rajalakshmi-ganesan | ab42672 | 2013-02-08 15:49:15 +0530 | [diff] [blame] | 1 | # 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 Dague | 1937d09 | 2013-05-17 16:36:38 -0400 | [diff] [blame] | 16 | from tempest.api.identity import base |
Ken'ichi Ohmichi | 7bd2575 | 2017-03-10 10:45:39 -0800 | [diff] [blame] | 17 | from tempest.lib.common.utils import data_utils |
Andrea Frittoli | 7f60fa6 | 2017-09-09 16:31:34 +0200 | [diff] [blame] | 18 | from tempest.lib.common.utils import test_utils |
Ken'ichi Ohmichi | eeabdd2 | 2017-01-27 17:46:00 -0800 | [diff] [blame] | 19 | from tempest.lib import decorators |
rajalakshmi-ganesan | ab42672 | 2013-02-08 15:49:15 +0530 | [diff] [blame] | 20 | |
| 21 | |
Matthew Treinish | db2c597 | 2014-01-31 22:18:59 +0000 | [diff] [blame] | 22 | class EndPointsTestJSON(base.BaseIdentityV3AdminTest): |
zhufl | b935820 | 2020-04-27 16:12:52 +0800 | [diff] [blame] | 23 | """Test keystone endpoints""" |
| 24 | |
Trevor McCasland | 87a7182 | 2018-01-05 11:45:49 -0600 | [diff] [blame] | 25 | # 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-ganesan | ab42672 | 2013-02-08 15:49:15 +0530 | [diff] [blame] | 29 | |
| 30 | @classmethod |
Rohan Kanade | b645e17 | 2015-02-05 17:38:59 +0530 | [diff] [blame] | 31 | def setup_clients(cls): |
| 32 | super(EndPointsTestJSON, cls).setup_clients() |
rajalakshmi-ganesan | ab42672 | 2013-02-08 15:49:15 +0530 | [diff] [blame] | 33 | cls.client = cls.endpoints_client |
Rohan Kanade | b645e17 | 2015-02-05 17:38:59 +0530 | [diff] [blame] | 34 | |
| 35 | @classmethod |
| 36 | def resource_setup(cls): |
| 37 | super(EndPointsTestJSON, cls).resource_setup() |
rajalakshmi-ganesan | ab42672 | 2013-02-08 15:49:15 +0530 | [diff] [blame] | 38 | cls.service_ids = list() |
Felipe Monteiro | 63444d6 | 2017-04-29 20:44:19 +0100 | [diff] [blame] | 39 | |
| 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 Frittoli | 7f60fa6 | 2017-09-09 16:31:34 +0200 | [diff] [blame] | 44 | 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 Ollivier | 1a457ac | 2019-06-02 21:47:01 +0200 | [diff] [blame] | 49 | region_name = data_utils.rand_name('region') |
Felipe Monteiro | 63444d6 | 2017-04-29 20:44:19 +0100 | [diff] [blame] | 50 | url = data_utils.rand_url() |
| 51 | endpoint = cls.client.create_endpoint( |
| 52 | service_id=cls.service_ids[i], interface=interfaces[i], |
Cédric Ollivier | 1a457ac | 2019-06-02 21:47:01 +0200 | [diff] [blame] | 53 | 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 Frittoli | 7f60fa6 | 2017-09-09 16:31:34 +0200 | [diff] [blame] | 57 | cls.addClassResourceCleanup( |
| 58 | cls.client.delete_endpoint, endpoint['id']) |
Felipe Monteiro | 63444d6 | 2017-04-29 20:44:19 +0100 | [diff] [blame] | 59 | 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') |
zhufl | 95a3281 | 2017-03-01 17:52:21 +0800 | [diff] [blame] | 69 | service_data = ( |
Yaroslav Lobankov | 69d9056 | 2015-12-18 12:06:40 +0300 | [diff] [blame] | 70 | cls.services_client.create_service(name=s_name, type=s_type, |
| 71 | description=s_description)) |
Andrea Frittoli | 7f60fa6 | 2017-09-09 16:31:34 +0200 | [diff] [blame] | 72 | return service_data['service'] |
rajalakshmi-ganesan | ab42672 | 2013-02-08 15:49:15 +0530 | [diff] [blame] | 73 | |
Ken'ichi Ohmichi | eeabdd2 | 2017-01-27 17:46:00 -0800 | [diff] [blame] | 74 | @decorators.idempotent_id('c19ecf90-240e-4e23-9966-21cee3f6a618') |
rajalakshmi-ganesan | ab42672 | 2013-02-08 15:49:15 +0530 | [diff] [blame] | 75 | def test_list_endpoints(self): |
zhufl | b935820 | 2020-04-27 16:12:52 +0800 | [diff] [blame] | 76 | """Test listing keystone endpoints by filters""" |
Felipe Monteiro | 63444d6 | 2017-04-29 20:44:19 +0100 | [diff] [blame] | 77 | # Get the list of all the endpoints. |
John Warren | 47f504b | 2015-08-11 20:25:05 +0000 | [diff] [blame] | 78 | fetched_endpoints = self.client.list_endpoints()['endpoints'] |
Felipe Monteiro | 63444d6 | 2017-04-29 20:44:19 +0100 | [diff] [blame] | 79 | fetched_endpoint_ids = [e['id'] for e in fetched_endpoints] |
| 80 | # Check that all the created endpoints are present in |
| 81 | # "fetched_endpoints". |
rajalakshmi-ganesan | ab42672 | 2013-02-08 15:49:15 +0530 | [diff] [blame] | 82 | missing_endpoints =\ |
Felipe Monteiro | 63444d6 | 2017-04-29 20:44:19 +0100 | [diff] [blame] | 83 | [e for e in self.setup_endpoint_ids |
| 84 | if e not in fetched_endpoint_ids] |
| 85 | self.assertEqual(0, len(missing_endpoints), |
rajalakshmi-ganesan | ab42672 | 2013-02-08 15:49:15 +0530 | [diff] [blame] | 86 | "Failed to find endpoint %s in fetched list" % |
| 87 | ', '.join(str(e) for e in missing_endpoints)) |
| 88 | |
Felipe Monteiro | 63444d6 | 2017-04-29 20:44:19 +0100 | [diff] [blame] | 89 | # 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 Ohmichi | eeabdd2 | 2017-01-27 17:46:00 -0800 | [diff] [blame] | 115 | @decorators.idempotent_id('0e2446d2-c1fd-461b-a729-b9e73e3e3b37') |
apetrov | 5ae389f | 2016-01-21 16:16:13 +0100 | [diff] [blame] | 116 | def test_create_list_show_delete_endpoint(self): |
zhufl | b935820 | 2020-04-27 16:12:52 +0800 | [diff] [blame] | 117 | """Test creating, listing, showing and deleting keystone endpoint""" |
Cédric Ollivier | 1a457ac | 2019-06-02 21:47:01 +0200 | [diff] [blame] | 118 | region_name = data_utils.rand_name('region') |
Dolph Mathews | 064e965 | 2014-07-11 10:54:38 -0500 | [diff] [blame] | 119 | url = data_utils.rand_url() |
rajalakshmi-ganesan | ab42672 | 2013-02-08 15:49:15 +0530 | [diff] [blame] | 120 | interface = 'public' |
Felipe Monteiro | 63444d6 | 2017-04-29 20:44:19 +0100 | [diff] [blame] | 121 | endpoint = self.client.create_endpoint(service_id=self.service_ids[0], |
Yaroslav Lobankov | 2b459ec | 2015-11-09 15:01:48 +0300 | [diff] [blame] | 122 | interface=interface, |
Cédric Ollivier | 1a457ac | 2019-06-02 21:47:01 +0200 | [diff] [blame] | 123 | url=url, region=region_name, |
Yaroslav Lobankov | 2b459ec | 2015-11-09 15:01:48 +0300 | [diff] [blame] | 124 | enabled=True)['endpoint'] |
Cédric Ollivier | 1a457ac | 2019-06-02 21:47:01 +0200 | [diff] [blame] | 125 | region = self.regions_client.show_region(region_name)['region'] |
| 126 | self.addCleanup(self.regions_client.delete_region, region['id']) |
Andrea Frittoli | 7f60fa6 | 2017-09-09 16:31:34 +0200 | [diff] [blame] | 127 | self.addCleanup(test_utils.call_and_ignore_notfound_exc, |
| 128 | self.client.delete_endpoint, endpoint['id']) |
Giulio Fidente | 92f7719 | 2013-08-26 17:13:28 +0200 | [diff] [blame] | 129 | # Asserting Create Endpoint response body |
Cédric Ollivier | 1a457ac | 2019-06-02 21:47:01 +0200 | [diff] [blame] | 130 | self.assertEqual(region_name, endpoint['region']) |
Giulio Fidente | 92f7719 | 2013-08-26 17:13:28 +0200 | [diff] [blame] | 131 | self.assertEqual(url, endpoint['url']) |
apetrov | 5ae389f | 2016-01-21 16:16:13 +0100 | [diff] [blame] | 132 | |
Giulio Fidente | 92f7719 | 2013-08-26 17:13:28 +0200 | [diff] [blame] | 133 | # Checking if created endpoint is present in the list of endpoints |
John Warren | 47f504b | 2015-08-11 20:25:05 +0000 | [diff] [blame] | 134 | fetched_endpoints = self.client.list_endpoints()['endpoints'] |
Giulio Fidente | 92f7719 | 2013-08-26 17:13:28 +0200 | [diff] [blame] | 135 | fetched_endpoints_id = [e['id'] for e in fetched_endpoints] |
| 136 | self.assertIn(endpoint['id'], fetched_endpoints_id) |
apetrov | 5ae389f | 2016-01-21 16:16:13 +0100 | [diff] [blame] | 137 | |
| 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 Monteiro | 63444d6 | 2017-04-29 20:44:19 +0100 | [diff] [blame] | 142 | self.assertEqual(self.service_ids[0], fetched_endpoint['service_id']) |
apetrov | 5ae389f | 2016-01-21 16:16:13 +0100 | [diff] [blame] | 143 | self.assertEqual(interface, fetched_endpoint['interface']) |
| 144 | self.assertEqual(url, fetched_endpoint['url']) |
Cédric Ollivier | 1a457ac | 2019-06-02 21:47:01 +0200 | [diff] [blame] | 145 | self.assertEqual(region_name, fetched_endpoint['region']) |
apetrov | 5ae389f | 2016-01-21 16:16:13 +0100 | [diff] [blame] | 146 | self.assertEqual(True, fetched_endpoint['enabled']) |
| 147 | |
Giulio Fidente | 92f7719 | 2013-08-26 17:13:28 +0200 | [diff] [blame] | 148 | # Deleting the endpoint created in this method |
ghanshyam | a201637 | 2014-10-24 11:15:01 +0900 | [diff] [blame] | 149 | self.client.delete_endpoint(endpoint['id']) |
apetrov | 5ae389f | 2016-01-21 16:16:13 +0100 | [diff] [blame] | 150 | |
Giulio Fidente | 92f7719 | 2013-08-26 17:13:28 +0200 | [diff] [blame] | 151 | # Checking whether endpoint is deleted successfully |
John Warren | 47f504b | 2015-08-11 20:25:05 +0000 | [diff] [blame] | 152 | fetched_endpoints = self.client.list_endpoints()['endpoints'] |
Giulio Fidente | 92f7719 | 2013-08-26 17:13:28 +0200 | [diff] [blame] | 153 | fetched_endpoints_id = [e['id'] for e in fetched_endpoints] |
| 154 | self.assertNotIn(endpoint['id'], fetched_endpoints_id) |
rajalakshmi-ganesan | ab42672 | 2013-02-08 15:49:15 +0530 | [diff] [blame] | 155 | |
Jordan Pittier | 3b46d27 | 2017-04-12 16:17:28 +0200 | [diff] [blame] | 156 | @decorators.attr(type='smoke') |
Ken'ichi Ohmichi | eeabdd2 | 2017-01-27 17:46:00 -0800 | [diff] [blame] | 157 | @decorators.idempotent_id('37e8f15e-ee7c-4657-a1e7-f6b61e375eff') |
rajalakshmi-ganesan | ab42672 | 2013-02-08 15:49:15 +0530 | [diff] [blame] | 158 | def test_update_endpoint(self): |
zhufl | b935820 | 2020-04-27 16:12:52 +0800 | [diff] [blame] | 159 | """Test updating keystone endpoint""" |
Andrea Frittoli | 7f60fa6 | 2017-09-09 16:31:34 +0200 | [diff] [blame] | 160 | # 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 Ollivier | 1a457ac | 2019-06-02 21:47:01 +0200 | [diff] [blame] | 174 | region1_name = data_utils.rand_name('region') |
Dolph Mathews | 064e965 | 2014-07-11 10:54:38 -0500 | [diff] [blame] | 175 | url1 = data_utils.rand_url() |
rajalakshmi-ganesan | ab42672 | 2013-02-08 15:49:15 +0530 | [diff] [blame] | 176 | interface1 = 'public' |
Yaroslav Lobankov | 2b459ec | 2015-11-09 15:01:48 +0300 | [diff] [blame] | 177 | endpoint_for_update = ( |
Felipe Monteiro | 63444d6 | 2017-04-29 20:44:19 +0100 | [diff] [blame] | 178 | self.client.create_endpoint(service_id=self.service_ids[0], |
Yaroslav Lobankov | 2b459ec | 2015-11-09 15:01:48 +0300 | [diff] [blame] | 179 | interface=interface1, |
Cédric Ollivier | 1a457ac | 2019-06-02 21:47:01 +0200 | [diff] [blame] | 180 | url=url1, region=region1_name, |
Yaroslav Lobankov | 2b459ec | 2015-11-09 15:01:48 +0300 | [diff] [blame] | 181 | enabled=True)['endpoint']) |
Cédric Ollivier | 1a457ac | 2019-06-02 21:47:01 +0200 | [diff] [blame] | 182 | region1 = self.regions_client.show_region(region1_name)['region'] |
| 183 | self.addCleanup(self.regions_client.delete_region, region1['id']) |
Andrea Frittoli | 7f60fa6 | 2017-09-09 16:31:34 +0200 | [diff] [blame] | 184 | |
Attila Fazekas | f7f34f9 | 2013-08-01 17:01:44 +0200 | [diff] [blame] | 185 | # Updating endpoint with new values |
Cédric Ollivier | 1a457ac | 2019-06-02 21:47:01 +0200 | [diff] [blame] | 186 | region2_name = data_utils.rand_name('region') |
Dolph Mathews | 064e965 | 2014-07-11 10:54:38 -0500 | [diff] [blame] | 187 | url2 = data_utils.rand_url() |
rajalakshmi-ganesan | ab42672 | 2013-02-08 15:49:15 +0530 | [diff] [blame] | 188 | interface2 = 'internal' |
Yaroslav Lobankov | 2b459ec | 2015-11-09 15:01:48 +0300 | [diff] [blame] | 189 | endpoint = self.client.update_endpoint(endpoint_for_update['id'], |
| 190 | service_id=service2['id'], |
| 191 | interface=interface2, |
Cédric Ollivier | 1a457ac | 2019-06-02 21:47:01 +0200 | [diff] [blame] | 192 | url=url2, region=region2_name, |
Yaroslav Lobankov | 2b459ec | 2015-11-09 15:01:48 +0300 | [diff] [blame] | 193 | enabled=False)['endpoint'] |
Cédric Ollivier | 1a457ac | 2019-06-02 21:47:01 +0200 | [diff] [blame] | 194 | 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 Fazekas | f7f34f9 | 2013-08-01 17:01:44 +0200 | [diff] [blame] | 198 | # Asserting if the attributes of endpoint are updated |
Pranav Salunke | 9b3029c | 2014-05-25 00:01:05 +0530 | [diff] [blame] | 199 | self.assertEqual(service2['id'], endpoint['service_id']) |
rajalakshmi-ganesan | ab42672 | 2013-02-08 15:49:15 +0530 | [diff] [blame] | 200 | self.assertEqual(interface2, endpoint['interface']) |
| 201 | self.assertEqual(url2, endpoint['url']) |
Cédric Ollivier | 1a457ac | 2019-06-02 21:47:01 +0200 | [diff] [blame] | 202 | self.assertEqual(region2_name, endpoint['region']) |
Ken'ichi Ohmichi | 73cb70b | 2015-04-17 02:31:12 +0000 | [diff] [blame] | 203 | self.assertEqual(False, endpoint['enabled']) |