Zhenzan Zhou | 494b0a6 | 2015-07-17 21:06:31 +0800 | [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 | |
| 16 | from tempest.api.identity import base |
Martin Kopec | 213d0a4 | 2023-11-30 10:28:14 +0100 | [diff] [blame] | 17 | from tempest import config |
Ken'ichi Ohmichi | 7bd2575 | 2017-03-10 10:45:39 -0800 | [diff] [blame] | 18 | from tempest.lib.common.utils import data_utils |
Ken'ichi Ohmichi | eeabdd2 | 2017-01-27 17:46:00 -0800 | [diff] [blame] | 19 | from tempest.lib import decorators |
Zhenzan Zhou | 494b0a6 | 2015-07-17 21:06:31 +0800 | [diff] [blame] | 20 | |
Martin Kopec | 213d0a4 | 2023-11-30 10:28:14 +0100 | [diff] [blame] | 21 | CONF = config.CONF |
| 22 | |
Zhenzan Zhou | 494b0a6 | 2015-07-17 21:06:31 +0800 | [diff] [blame] | 23 | |
| 24 | class EndPointsTestJSON(base.BaseIdentityV2AdminTest): |
zhufl | c16883f | 2020-04-16 15:31:44 +0800 | [diff] [blame] | 25 | """Test keystone v2 endpoints""" |
Zhenzan Zhou | 494b0a6 | 2015-07-17 21:06:31 +0800 | [diff] [blame] | 26 | |
| 27 | @classmethod |
| 28 | def resource_setup(cls): |
| 29 | super(EndPointsTestJSON, cls).resource_setup() |
Martin Kopec | 213d0a4 | 2023-11-30 10:28:14 +0100 | [diff] [blame] | 30 | s_name = data_utils.rand_name( |
| 31 | name='service', prefix=CONF.resource_name_prefix) |
| 32 | s_type = data_utils.rand_name( |
| 33 | name='type', prefix=CONF.resource_name_prefix) |
| 34 | s_description = data_utils.rand_name( |
| 35 | name='description', prefix=CONF.resource_name_prefix) |
zhufl | 95a3281 | 2017-03-01 17:52:21 +0800 | [diff] [blame] | 36 | service_data = cls.services_client.create_service( |
ghanshyam | 6ce3921 | 2016-06-15 13:20:11 +0900 | [diff] [blame] | 37 | name=s_name, type=s_type, |
| 38 | description=s_description)['OS-KSADM:service'] |
Saurabh Chordiya | cd5f586 | 2017-10-25 19:20:35 +0530 | [diff] [blame] | 39 | cls.addClassResourceCleanup(cls.services_client.delete_service, |
| 40 | service_data['id']) |
zhufl | 95a3281 | 2017-03-01 17:52:21 +0800 | [diff] [blame] | 41 | cls.service_id = service_data['id'] |
Zhenzan Zhou | 494b0a6 | 2015-07-17 21:06:31 +0800 | [diff] [blame] | 42 | # Create endpoints so as to use for LIST and GET test cases |
| 43 | cls.setup_endpoints = list() |
zhufl | 8e9a073 | 2017-01-26 16:15:21 +0800 | [diff] [blame] | 44 | for _ in range(2): |
Martin Kopec | 213d0a4 | 2023-11-30 10:28:14 +0100 | [diff] [blame] | 45 | region = data_utils.rand_name( |
| 46 | name='region', prefix=CONF.resource_name_prefix) |
Zhenzan Zhou | 494b0a6 | 2015-07-17 21:06:31 +0800 | [diff] [blame] | 47 | url = data_utils.rand_url() |
Daniel Mellado | 3f951ef | 2016-01-13 09:48:00 +0000 | [diff] [blame] | 48 | endpoint = cls.endpoints_client.create_endpoint( |
Ken'ichi Ohmichi | b5ebadb | 2016-06-13 14:19:22 -0700 | [diff] [blame] | 49 | service_id=cls.service_id, |
| 50 | region=region, |
Daniel Mellado | 3f951ef | 2016-01-13 09:48:00 +0000 | [diff] [blame] | 51 | publicurl=url, |
| 52 | adminurl=url, |
| 53 | internalurl=url)['endpoint'] |
Saurabh Chordiya | cd5f586 | 2017-10-25 19:20:35 +0530 | [diff] [blame] | 54 | cls.addClassResourceCleanup(cls.endpoints_client.delete_endpoint, |
| 55 | endpoint['id']) |
Zhenzan Zhou | 494b0a6 | 2015-07-17 21:06:31 +0800 | [diff] [blame] | 56 | # list_endpoints() will return 'enabled' field |
| 57 | endpoint['enabled'] = True |
| 58 | cls.setup_endpoints.append(endpoint) |
| 59 | |
Ken'ichi Ohmichi | eeabdd2 | 2017-01-27 17:46:00 -0800 | [diff] [blame] | 60 | @decorators.idempotent_id('11f590eb-59d8-4067-8b2b-980c7f387f51') |
Zhenzan Zhou | 494b0a6 | 2015-07-17 21:06:31 +0800 | [diff] [blame] | 61 | def test_list_endpoints(self): |
zhufl | c16883f | 2020-04-16 15:31:44 +0800 | [diff] [blame] | 62 | """Test listing keystone endpoints""" |
Zhenzan Zhou | 494b0a6 | 2015-07-17 21:06:31 +0800 | [diff] [blame] | 63 | # Get a list of endpoints |
Daniel Mellado | 3f951ef | 2016-01-13 09:48:00 +0000 | [diff] [blame] | 64 | fetched_endpoints = self.endpoints_client.list_endpoints()['endpoints'] |
Zhenzan Zhou | 494b0a6 | 2015-07-17 21:06:31 +0800 | [diff] [blame] | 65 | # Asserting LIST endpoints |
| 66 | missing_endpoints =\ |
| 67 | [e for e in self.setup_endpoints if e not in fetched_endpoints] |
Masayuki Igawa | f9009b4 | 2017-04-10 14:49:29 +0900 | [diff] [blame] | 68 | self.assertEmpty(missing_endpoints, |
Zhenzan Zhou | 494b0a6 | 2015-07-17 21:06:31 +0800 | [diff] [blame] | 69 | "Failed to find endpoint %s in fetched list" % |
| 70 | ', '.join(str(e) for e in missing_endpoints)) |
| 71 | |
Ken'ichi Ohmichi | eeabdd2 | 2017-01-27 17:46:00 -0800 | [diff] [blame] | 72 | @decorators.idempotent_id('9974530a-aa28-4362-8403-f06db02b26c1') |
Zhenzan Zhou | 494b0a6 | 2015-07-17 21:06:31 +0800 | [diff] [blame] | 73 | def test_create_list_delete_endpoint(self): |
zhufl | c16883f | 2020-04-16 15:31:44 +0800 | [diff] [blame] | 74 | """Test creating, listing and deleting a keystone endpoint""" |
Martin Kopec | 213d0a4 | 2023-11-30 10:28:14 +0100 | [diff] [blame] | 75 | region = data_utils.rand_name( |
| 76 | name='region', prefix=CONF.resource_name_prefix) |
Zhenzan Zhou | 494b0a6 | 2015-07-17 21:06:31 +0800 | [diff] [blame] | 77 | url = data_utils.rand_url() |
Daniel Mellado | 3f951ef | 2016-01-13 09:48:00 +0000 | [diff] [blame] | 78 | endpoint = self.endpoints_client.create_endpoint( |
Ken'ichi Ohmichi | b5ebadb | 2016-06-13 14:19:22 -0700 | [diff] [blame] | 79 | service_id=self.service_id, |
| 80 | region=region, |
Daniel Mellado | 3f951ef | 2016-01-13 09:48:00 +0000 | [diff] [blame] | 81 | publicurl=url, |
| 82 | adminurl=url, |
| 83 | internalurl=url)['endpoint'] |
Zhenzan Zhou | 494b0a6 | 2015-07-17 21:06:31 +0800 | [diff] [blame] | 84 | # Asserting Create Endpoint response body |
| 85 | self.assertIn('id', endpoint) |
| 86 | self.assertEqual(region, endpoint['region']) |
| 87 | self.assertEqual(url, endpoint['publicurl']) |
| 88 | # Checking if created endpoint is present in the list of endpoints |
Daniel Mellado | 3f951ef | 2016-01-13 09:48:00 +0000 | [diff] [blame] | 89 | fetched_endpoints = self.endpoints_client.list_endpoints()['endpoints'] |
Zhenzan Zhou | 494b0a6 | 2015-07-17 21:06:31 +0800 | [diff] [blame] | 90 | fetched_endpoints_id = [e['id'] for e in fetched_endpoints] |
| 91 | self.assertIn(endpoint['id'], fetched_endpoints_id) |
| 92 | # Deleting the endpoint created in this method |
Daniel Mellado | 3f951ef | 2016-01-13 09:48:00 +0000 | [diff] [blame] | 93 | self.endpoints_client.delete_endpoint(endpoint['id']) |
Zhenzan Zhou | 494b0a6 | 2015-07-17 21:06:31 +0800 | [diff] [blame] | 94 | # Checking whether endpoint is deleted successfully |
Daniel Mellado | 3f951ef | 2016-01-13 09:48:00 +0000 | [diff] [blame] | 95 | fetched_endpoints = self.endpoints_client.list_endpoints()['endpoints'] |
Zhenzan Zhou | 494b0a6 | 2015-07-17 21:06:31 +0800 | [diff] [blame] | 96 | fetched_endpoints_id = [e['id'] for e in fetched_endpoints] |
| 97 | self.assertNotIn(endpoint['id'], fetched_endpoints_id) |