blob: c9faa9aa56cdae018a0425d393c318cd3b710746 [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
Ken'ichi Ohmichieeabdd22017-01-27 17:46:00 -080018from tempest.lib import decorators
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053019
20
Matthew Treinishdb2c5972014-01-31 22:18:59 +000021class EndPointsTestJSON(base.BaseIdentityV3AdminTest):
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053022
23 @classmethod
Rohan Kanadeb645e172015-02-05 17:38:59 +053024 def setup_clients(cls):
25 super(EndPointsTestJSON, cls).setup_clients()
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053026 cls.client = cls.endpoints_client
Rohan Kanadeb645e172015-02-05 17:38:59 +053027
28 @classmethod
29 def resource_setup(cls):
30 super(EndPointsTestJSON, cls).resource_setup()
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053031 cls.service_ids = list()
Felipe Monteiro63444d62017-04-29 20:44:19 +010032
33 # Create endpoints so as to use for LIST and GET test cases
34 interfaces = ['public', 'internal']
35 cls.setup_endpoint_ids = list()
36 for i in range(2):
37 cls._create_service()
38 region = data_utils.rand_name('region')
39 url = data_utils.rand_url()
40 endpoint = cls.client.create_endpoint(
41 service_id=cls.service_ids[i], interface=interfaces[i],
42 url=url, region=region, enabled=True)['endpoint']
43 cls.setup_endpoint_ids.append(endpoint['id'])
44
45 @classmethod
46 def _create_service(cls, s_name=None, s_type=None, s_description=None):
47 if s_name is None:
48 s_name = data_utils.rand_name('service')
49 if s_type is None:
50 s_type = data_utils.rand_name('type')
51 if s_description is None:
52 s_description = data_utils.rand_name('description')
zhufl95a32812017-03-01 17:52:21 +080053 service_data = (
Yaroslav Lobankov69d90562015-12-18 12:06:40 +030054 cls.services_client.create_service(name=s_name, type=s_type,
55 description=s_description))
Felipe Monteiro63444d62017-04-29 20:44:19 +010056 service = service_data['service']
57 cls.service_ids.append(service['id'])
58 return service
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053059
60 @classmethod
Andrea Frittoli7688e742014-09-15 12:38:22 +010061 def resource_cleanup(cls):
Felipe Monteiro63444d62017-04-29 20:44:19 +010062 for e in cls.setup_endpoint_ids:
63 cls.client.delete_endpoint(e)
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053064 for s in cls.service_ids:
Yaroslav Lobankov69d90562015-12-18 12:06:40 +030065 cls.services_client.delete_service(s)
Andrea Frittoli7688e742014-09-15 12:38:22 +010066 super(EndPointsTestJSON, cls).resource_cleanup()
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053067
Ken'ichi Ohmichieeabdd22017-01-27 17:46:00 -080068 @decorators.idempotent_id('c19ecf90-240e-4e23-9966-21cee3f6a618')
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053069 def test_list_endpoints(self):
Felipe Monteiro63444d62017-04-29 20:44:19 +010070 # Get the list of all the endpoints.
John Warren47f504b2015-08-11 20:25:05 +000071 fetched_endpoints = self.client.list_endpoints()['endpoints']
Felipe Monteiro63444d62017-04-29 20:44:19 +010072 fetched_endpoint_ids = [e['id'] for e in fetched_endpoints]
73 # Check that all the created endpoints are present in
74 # "fetched_endpoints".
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053075 missing_endpoints =\
Felipe Monteiro63444d62017-04-29 20:44:19 +010076 [e for e in self.setup_endpoint_ids
77 if e not in fetched_endpoint_ids]
78 self.assertEqual(0, len(missing_endpoints),
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053079 "Failed to find endpoint %s in fetched list" %
80 ', '.join(str(e) for e in missing_endpoints))
81
Felipe Monteiro63444d62017-04-29 20:44:19 +010082 # Check that filtering endpoints by service_id works.
83 fetched_endpoints_for_service = self.client.list_endpoints(
84 service_id=self.service_ids[0])['endpoints']
85 fetched_endpoints_for_alt_service = self.client.list_endpoints(
86 service_id=self.service_ids[1])['endpoints']
87
88 # Assert that both filters returned the correct result.
89 self.assertEqual(1, len(fetched_endpoints_for_service))
90 self.assertEqual(1, len(fetched_endpoints_for_alt_service))
91 self.assertEqual(set(self.setup_endpoint_ids),
92 set([fetched_endpoints_for_service[0]['id'],
93 fetched_endpoints_for_alt_service[0]['id']]))
94
95 # Check that filtering endpoints by interface works.
96 fetched_public_endpoints = self.client.list_endpoints(
97 interface='public')['endpoints']
98 fetched_internal_endpoints = self.client.list_endpoints(
99 interface='internal')['endpoints']
100
101 # Check that the expected endpoint_id is present per filter. [0] is
102 # public and [1] is internal.
103 self.assertIn(self.setup_endpoint_ids[0],
104 [e['id'] for e in fetched_public_endpoints])
105 self.assertIn(self.setup_endpoint_ids[1],
106 [e['id'] for e in fetched_internal_endpoints])
107
Ken'ichi Ohmichieeabdd22017-01-27 17:46:00 -0800108 @decorators.idempotent_id('0e2446d2-c1fd-461b-a729-b9e73e3e3b37')
apetrov5ae389f2016-01-21 16:16:13 +0100109 def test_create_list_show_delete_endpoint(self):
Masayuki Igawa259c1132013-10-31 17:48:44 +0900110 region = data_utils.rand_name('region')
Dolph Mathews064e9652014-07-11 10:54:38 -0500111 url = data_utils.rand_url()
rajalakshmi-ganesanab426722013-02-08 15:49:15 +0530112 interface = 'public'
Felipe Monteiro63444d62017-04-29 20:44:19 +0100113 endpoint = self.client.create_endpoint(service_id=self.service_ids[0],
Yaroslav Lobankov2b459ec2015-11-09 15:01:48 +0300114 interface=interface,
115 url=url, region=region,
116 enabled=True)['endpoint']
apetrov5ae389f2016-01-21 16:16:13 +0100117
Felipe Monteiro63444d62017-04-29 20:44:19 +0100118 self.setup_endpoint_ids.append(endpoint['id'])
Giulio Fidente92f77192013-08-26 17:13:28 +0200119 # Asserting Create Endpoint response body
Giulio Fidente92f77192013-08-26 17:13:28 +0200120 self.assertIn('id', endpoint)
121 self.assertEqual(region, endpoint['region'])
122 self.assertEqual(url, endpoint['url'])
apetrov5ae389f2016-01-21 16:16:13 +0100123
Giulio Fidente92f77192013-08-26 17:13:28 +0200124 # Checking if created endpoint is present in the list of endpoints
John Warren47f504b2015-08-11 20:25:05 +0000125 fetched_endpoints = self.client.list_endpoints()['endpoints']
Giulio Fidente92f77192013-08-26 17:13:28 +0200126 fetched_endpoints_id = [e['id'] for e in fetched_endpoints]
127 self.assertIn(endpoint['id'], fetched_endpoints_id)
apetrov5ae389f2016-01-21 16:16:13 +0100128
129 # Show endpoint
130 fetched_endpoint = (
131 self.client.show_endpoint(endpoint['id'])['endpoint'])
132 # Asserting if the attributes of endpoint are the same
Felipe Monteiro63444d62017-04-29 20:44:19 +0100133 self.assertEqual(self.service_ids[0], fetched_endpoint['service_id'])
apetrov5ae389f2016-01-21 16:16:13 +0100134 self.assertEqual(interface, fetched_endpoint['interface'])
135 self.assertEqual(url, fetched_endpoint['url'])
136 self.assertEqual(region, fetched_endpoint['region'])
137 self.assertEqual(True, fetched_endpoint['enabled'])
138
Giulio Fidente92f77192013-08-26 17:13:28 +0200139 # Deleting the endpoint created in this method
ghanshyama2016372014-10-24 11:15:01 +0900140 self.client.delete_endpoint(endpoint['id'])
Felipe Monteiro63444d62017-04-29 20:44:19 +0100141 self.setup_endpoint_ids.remove(endpoint['id'])
apetrov5ae389f2016-01-21 16:16:13 +0100142
Giulio Fidente92f77192013-08-26 17:13:28 +0200143 # Checking whether endpoint is deleted successfully
John Warren47f504b2015-08-11 20:25:05 +0000144 fetched_endpoints = self.client.list_endpoints()['endpoints']
Giulio Fidente92f77192013-08-26 17:13:28 +0200145 fetched_endpoints_id = [e['id'] for e in fetched_endpoints]
146 self.assertNotIn(endpoint['id'], fetched_endpoints_id)
rajalakshmi-ganesanab426722013-02-08 15:49:15 +0530147
Jordan Pittier3b46d272017-04-12 16:17:28 +0200148 @decorators.attr(type='smoke')
Ken'ichi Ohmichieeabdd22017-01-27 17:46:00 -0800149 @decorators.idempotent_id('37e8f15e-ee7c-4657-a1e7-f6b61e375eff')
rajalakshmi-ganesanab426722013-02-08 15:49:15 +0530150 def test_update_endpoint(self):
Attila Fazekasf7f34f92013-08-01 17:01:44 +0200151 # Creating an endpoint so as to check update endpoint
152 # with new values
Masayuki Igawa259c1132013-10-31 17:48:44 +0900153 region1 = data_utils.rand_name('region')
Dolph Mathews064e9652014-07-11 10:54:38 -0500154 url1 = data_utils.rand_url()
rajalakshmi-ganesanab426722013-02-08 15:49:15 +0530155 interface1 = 'public'
Yaroslav Lobankov2b459ec2015-11-09 15:01:48 +0300156 endpoint_for_update = (
Felipe Monteiro63444d62017-04-29 20:44:19 +0100157 self.client.create_endpoint(service_id=self.service_ids[0],
Yaroslav Lobankov2b459ec2015-11-09 15:01:48 +0300158 interface=interface1,
159 url=url1, region=region1,
160 enabled=True)['endpoint'])
Brant Knudson3a9bdf92014-02-27 17:09:50 -0600161 self.addCleanup(self.client.delete_endpoint, endpoint_for_update['id'])
Attila Fazekasf7f34f92013-08-01 17:01:44 +0200162 # Creating service so as update endpoint with new service ID
Ken'ichi Ohmichi96508472015-03-23 01:43:42 +0000163 s_name = data_utils.rand_name('service')
164 s_type = data_utils.rand_name('type')
165 s_description = data_utils.rand_name('description')
Felipe Monteiro63444d62017-04-29 20:44:19 +0100166 service2 = self._create_service(s_name=s_name, s_type=s_type,
167 s_description=s_description)
Attila Fazekasf7f34f92013-08-01 17:01:44 +0200168 # Updating endpoint with new values
Masayuki Igawa259c1132013-10-31 17:48:44 +0900169 region2 = data_utils.rand_name('region')
Dolph Mathews064e9652014-07-11 10:54:38 -0500170 url2 = data_utils.rand_url()
rajalakshmi-ganesanab426722013-02-08 15:49:15 +0530171 interface2 = 'internal'
Yaroslav Lobankov2b459ec2015-11-09 15:01:48 +0300172 endpoint = self.client.update_endpoint(endpoint_for_update['id'],
173 service_id=service2['id'],
174 interface=interface2,
175 url=url2, region=region2,
176 enabled=False)['endpoint']
Attila Fazekasf7f34f92013-08-01 17:01:44 +0200177 # Asserting if the attributes of endpoint are updated
Pranav Salunke9b3029c2014-05-25 00:01:05 +0530178 self.assertEqual(service2['id'], endpoint['service_id'])
rajalakshmi-ganesanab426722013-02-08 15:49:15 +0530179 self.assertEqual(interface2, endpoint['interface'])
180 self.assertEqual(url2, endpoint['url'])
181 self.assertEqual(region2, endpoint['region'])
Ken'ichi Ohmichi73cb70b2015-04-17 02:31:12 +0000182 self.assertEqual(False, endpoint['enabled'])