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