blob: 9a0b3e41b8b997613a5ed56f18a922f7c7a84538 [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
Fei Long Wangd39431f2015-05-14 11:30:48 +120017from tempest.common.utils import data_utils
Ken'ichi Ohmichieeabdd22017-01-27 17:46:00 -080018from tempest.lib import decorators
Masayuki Igawadf154682014-03-19 18:32:00 +090019from tempest import test
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053020
21
Matthew Treinishdb2c5972014-01-31 22:18:59 +000022class EndPointsTestJSON(base.BaseIdentityV3AdminTest):
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053023
24 @classmethod
Rohan Kanadeb645e172015-02-05 17:38:59 +053025 def setup_clients(cls):
26 super(EndPointsTestJSON, cls).setup_clients()
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053027 cls.client = cls.endpoints_client
Rohan Kanadeb645e172015-02-05 17:38:59 +053028
29 @classmethod
30 def resource_setup(cls):
31 super(EndPointsTestJSON, cls).resource_setup()
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053032 cls.service_ids = list()
Ken'ichi Ohmichi96508472015-03-23 01:43:42 +000033 s_name = data_utils.rand_name('service')
34 s_type = data_utils.rand_name('type')
35 s_description = data_utils.rand_name('description')
zhufl95a32812017-03-01 17:52:21 +080036 service_data = (
Yaroslav Lobankov69d90562015-12-18 12:06:40 +030037 cls.services_client.create_service(name=s_name, type=s_type,
38 description=s_description))
zhufl95a32812017-03-01 17:52:21 +080039 cls.service_id = service_data['service']['id']
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053040 cls.service_ids.append(cls.service_id)
Attila Fazekasf7f34f92013-08-01 17:01:44 +020041 # Create endpoints so as to use for LIST and GET test cases
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053042 cls.setup_endpoints = list()
zhufl8e9a0732017-01-26 16:15:21 +080043 for _ in range(2):
Masayuki Igawa259c1132013-10-31 17:48:44 +090044 region = data_utils.rand_name('region')
Dolph Mathews064e9652014-07-11 10:54:38 -050045 url = data_utils.rand_url()
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053046 interface = 'public'
Yaroslav Lobankov2b459ec2015-11-09 15:01:48 +030047 endpoint = cls.client.create_endpoint(service_id=cls.service_id,
48 interface=interface,
49 url=url, region=region,
50 enabled=True)['endpoint']
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053051 cls.setup_endpoints.append(endpoint)
52
53 @classmethod
Andrea Frittoli7688e742014-09-15 12:38:22 +010054 def resource_cleanup(cls):
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053055 for e in cls.setup_endpoints:
56 cls.client.delete_endpoint(e['id'])
57 for s in cls.service_ids:
Yaroslav Lobankov69d90562015-12-18 12:06:40 +030058 cls.services_client.delete_service(s)
Andrea Frittoli7688e742014-09-15 12:38:22 +010059 super(EndPointsTestJSON, cls).resource_cleanup()
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053060
Ken'ichi Ohmichieeabdd22017-01-27 17:46:00 -080061 @decorators.idempotent_id('c19ecf90-240e-4e23-9966-21cee3f6a618')
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053062 def test_list_endpoints(self):
63 # Get a list of endpoints
John Warren47f504b2015-08-11 20:25:05 +000064 fetched_endpoints = self.client.list_endpoints()['endpoints']
Chang Bo Guof099f802013-09-13 19:01:46 -070065 # Asserting LIST endpoints
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053066 missing_endpoints =\
67 [e for e in self.setup_endpoints if e not in fetched_endpoints]
68 self.assertEqual(0, len(missing_endpoints),
69 "Failed to find endpoint %s in fetched list" %
70 ', '.join(str(e) for e in missing_endpoints))
71
Ken'ichi Ohmichieeabdd22017-01-27 17:46:00 -080072 @decorators.idempotent_id('0e2446d2-c1fd-461b-a729-b9e73e3e3b37')
apetrov5ae389f2016-01-21 16:16:13 +010073 def test_create_list_show_delete_endpoint(self):
Masayuki Igawa259c1132013-10-31 17:48:44 +090074 region = data_utils.rand_name('region')
Dolph Mathews064e9652014-07-11 10:54:38 -050075 url = data_utils.rand_url()
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053076 interface = 'public'
Yaroslav Lobankov2b459ec2015-11-09 15:01:48 +030077 endpoint = self.client.create_endpoint(service_id=self.service_id,
78 interface=interface,
79 url=url, region=region,
80 enabled=True)['endpoint']
apetrov5ae389f2016-01-21 16:16:13 +010081
Ghanshyam8aa8dcb2016-02-10 15:11:01 +090082 self.setup_endpoints.append(endpoint)
Giulio Fidente92f77192013-08-26 17:13:28 +020083 # Asserting Create Endpoint response body
Giulio Fidente92f77192013-08-26 17:13:28 +020084 self.assertIn('id', endpoint)
85 self.assertEqual(region, endpoint['region'])
86 self.assertEqual(url, endpoint['url'])
apetrov5ae389f2016-01-21 16:16:13 +010087
Giulio Fidente92f77192013-08-26 17:13:28 +020088 # Checking if created endpoint is present in the list of endpoints
John Warren47f504b2015-08-11 20:25:05 +000089 fetched_endpoints = self.client.list_endpoints()['endpoints']
Giulio Fidente92f77192013-08-26 17:13:28 +020090 fetched_endpoints_id = [e['id'] for e in fetched_endpoints]
91 self.assertIn(endpoint['id'], fetched_endpoints_id)
apetrov5ae389f2016-01-21 16:16:13 +010092
93 # Show endpoint
94 fetched_endpoint = (
95 self.client.show_endpoint(endpoint['id'])['endpoint'])
96 # Asserting if the attributes of endpoint are the same
97 self.assertEqual(self.service_id, fetched_endpoint['service_id'])
98 self.assertEqual(interface, fetched_endpoint['interface'])
99 self.assertEqual(url, fetched_endpoint['url'])
100 self.assertEqual(region, fetched_endpoint['region'])
101 self.assertEqual(True, fetched_endpoint['enabled'])
102
Giulio Fidente92f77192013-08-26 17:13:28 +0200103 # Deleting the endpoint created in this method
ghanshyama2016372014-10-24 11:15:01 +0900104 self.client.delete_endpoint(endpoint['id'])
Ghanshyam8aa8dcb2016-02-10 15:11:01 +0900105 self.setup_endpoints.remove(endpoint)
apetrov5ae389f2016-01-21 16:16:13 +0100106
Giulio Fidente92f77192013-08-26 17:13:28 +0200107 # Checking whether endpoint is deleted successfully
John Warren47f504b2015-08-11 20:25:05 +0000108 fetched_endpoints = self.client.list_endpoints()['endpoints']
Giulio Fidente92f77192013-08-26 17:13:28 +0200109 fetched_endpoints_id = [e['id'] for e in fetched_endpoints]
110 self.assertNotIn(endpoint['id'], fetched_endpoints_id)
rajalakshmi-ganesanab426722013-02-08 15:49:15 +0530111
Masayuki Igawadf154682014-03-19 18:32:00 +0900112 @test.attr(type='smoke')
Ken'ichi Ohmichieeabdd22017-01-27 17:46:00 -0800113 @decorators.idempotent_id('37e8f15e-ee7c-4657-a1e7-f6b61e375eff')
rajalakshmi-ganesanab426722013-02-08 15:49:15 +0530114 def test_update_endpoint(self):
Attila Fazekasf7f34f92013-08-01 17:01:44 +0200115 # Creating an endpoint so as to check update endpoint
116 # with new values
Masayuki Igawa259c1132013-10-31 17:48:44 +0900117 region1 = data_utils.rand_name('region')
Dolph Mathews064e9652014-07-11 10:54:38 -0500118 url1 = data_utils.rand_url()
rajalakshmi-ganesanab426722013-02-08 15:49:15 +0530119 interface1 = 'public'
Yaroslav Lobankov2b459ec2015-11-09 15:01:48 +0300120 endpoint_for_update = (
121 self.client.create_endpoint(service_id=self.service_id,
122 interface=interface1,
123 url=url1, region=region1,
124 enabled=True)['endpoint'])
Brant Knudson3a9bdf92014-02-27 17:09:50 -0600125 self.addCleanup(self.client.delete_endpoint, endpoint_for_update['id'])
Attila Fazekasf7f34f92013-08-01 17:01:44 +0200126 # Creating service so as update endpoint with new service ID
Ken'ichi Ohmichi96508472015-03-23 01:43:42 +0000127 s_name = data_utils.rand_name('service')
128 s_type = data_utils.rand_name('type')
129 s_description = data_utils.rand_name('description')
Yaroslav Lobankov61db2d92015-11-11 16:51:23 +0300130 service2 = (
Yaroslav Lobankov69d90562015-12-18 12:06:40 +0300131 self.services_client.create_service(name=s_name, type=s_type,
132 description=s_description))
John Warrenf96750d2015-08-13 13:44:59 +0000133 service2 = service2['service']
Pranav Salunke9b3029c2014-05-25 00:01:05 +0530134 self.service_ids.append(service2['id'])
Attila Fazekasf7f34f92013-08-01 17:01:44 +0200135 # Updating endpoint with new values
Masayuki Igawa259c1132013-10-31 17:48:44 +0900136 region2 = data_utils.rand_name('region')
Dolph Mathews064e9652014-07-11 10:54:38 -0500137 url2 = data_utils.rand_url()
rajalakshmi-ganesanab426722013-02-08 15:49:15 +0530138 interface2 = 'internal'
Yaroslav Lobankov2b459ec2015-11-09 15:01:48 +0300139 endpoint = self.client.update_endpoint(endpoint_for_update['id'],
140 service_id=service2['id'],
141 interface=interface2,
142 url=url2, region=region2,
143 enabled=False)['endpoint']
Attila Fazekasf7f34f92013-08-01 17:01:44 +0200144 # Asserting if the attributes of endpoint are updated
Pranav Salunke9b3029c2014-05-25 00:01:05 +0530145 self.assertEqual(service2['id'], endpoint['service_id'])
rajalakshmi-ganesanab426722013-02-08 15:49:15 +0530146 self.assertEqual(interface2, endpoint['interface'])
147 self.assertEqual(url2, endpoint['url'])
148 self.assertEqual(region2, endpoint['region'])
Ken'ichi Ohmichi73cb70b2015-04-17 02:31:12 +0000149 self.assertEqual(False, endpoint['enabled'])