blob: 429e2e3dc6c047924253aafdcbab6ef0e55676f3 [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
Masayuki Igawadf154682014-03-19 18:32:00 +090018from tempest import test
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.identity_client = cls.client
27 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')
Yaroslav Lobankov61db2d92015-11-11 16:51:23 +030036 cls.service_data = (
37 cls.service_client.create_service(name=s_name, type=s_type,
38 description=s_description))
John Warrenf96750d2015-08-13 13:44:59 +000039 cls.service_data = cls.service_data['service']
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053040 cls.service_id = cls.service_data['id']
41 cls.service_ids.append(cls.service_id)
Attila Fazekasf7f34f92013-08-01 17:01:44 +020042 # Create endpoints so as to use for LIST and GET test cases
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053043 cls.setup_endpoints = list()
44 for i in range(2):
Masayuki Igawa259c1132013-10-31 17:48:44 +090045 region = data_utils.rand_name('region')
Dolph Mathews064e9652014-07-11 10:54:38 -050046 url = data_utils.rand_url()
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053047 interface = 'public'
Yaroslav Lobankov2b459ec2015-11-09 15:01:48 +030048 endpoint = cls.client.create_endpoint(service_id=cls.service_id,
49 interface=interface,
50 url=url, region=region,
51 enabled=True)['endpoint']
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053052 cls.setup_endpoints.append(endpoint)
53
54 @classmethod
Andrea Frittoli7688e742014-09-15 12:38:22 +010055 def resource_cleanup(cls):
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053056 for e in cls.setup_endpoints:
57 cls.client.delete_endpoint(e['id'])
58 for s in cls.service_ids:
Matthew Treinishdb2c5972014-01-31 22:18:59 +000059 cls.service_client.delete_service(s)
Andrea Frittoli7688e742014-09-15 12:38:22 +010060 super(EndPointsTestJSON, cls).resource_cleanup()
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053061
Chris Hoge7579c1a2015-02-26 14:12:15 -080062 @test.idempotent_id('c19ecf90-240e-4e23-9966-21cee3f6a618')
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053063 def test_list_endpoints(self):
64 # Get a list of endpoints
John Warren47f504b2015-08-11 20:25:05 +000065 fetched_endpoints = self.client.list_endpoints()['endpoints']
Chang Bo Guof099f802013-09-13 19:01:46 -070066 # Asserting LIST endpoints
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053067 missing_endpoints =\
68 [e for e in self.setup_endpoints if e not in fetched_endpoints]
69 self.assertEqual(0, len(missing_endpoints),
70 "Failed to find endpoint %s in fetched list" %
71 ', '.join(str(e) for e in missing_endpoints))
72
Chris Hoge7579c1a2015-02-26 14:12:15 -080073 @test.idempotent_id('0e2446d2-c1fd-461b-a729-b9e73e3e3b37')
Giulio Fidente92f77192013-08-26 17:13:28 +020074 def test_create_list_delete_endpoint(self):
Masayuki Igawa259c1132013-10-31 17:48:44 +090075 region = data_utils.rand_name('region')
Dolph Mathews064e9652014-07-11 10:54:38 -050076 url = data_utils.rand_url()
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053077 interface = 'public'
Yaroslav Lobankov2b459ec2015-11-09 15:01:48 +030078 endpoint = self.client.create_endpoint(service_id=self.service_id,
79 interface=interface,
80 url=url, region=region,
81 enabled=True)['endpoint']
Giulio Fidente92f77192013-08-26 17:13:28 +020082 # Asserting Create Endpoint response body
Giulio Fidente92f77192013-08-26 17:13:28 +020083 self.assertIn('id', endpoint)
84 self.assertEqual(region, endpoint['region'])
85 self.assertEqual(url, endpoint['url'])
86 # Checking if created endpoint is present in the list of endpoints
John Warren47f504b2015-08-11 20:25:05 +000087 fetched_endpoints = self.client.list_endpoints()['endpoints']
Giulio Fidente92f77192013-08-26 17:13:28 +020088 fetched_endpoints_id = [e['id'] for e in fetched_endpoints]
89 self.assertIn(endpoint['id'], fetched_endpoints_id)
90 # Deleting the endpoint created in this method
ghanshyama2016372014-10-24 11:15:01 +090091 self.client.delete_endpoint(endpoint['id'])
Giulio Fidente92f77192013-08-26 17:13:28 +020092 # Checking whether endpoint is deleted successfully
John Warren47f504b2015-08-11 20:25:05 +000093 fetched_endpoints = self.client.list_endpoints()['endpoints']
Giulio Fidente92f77192013-08-26 17:13:28 +020094 fetched_endpoints_id = [e['id'] for e in fetched_endpoints]
95 self.assertNotIn(endpoint['id'], fetched_endpoints_id)
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053096
Masayuki Igawadf154682014-03-19 18:32:00 +090097 @test.attr(type='smoke')
Chris Hoge7579c1a2015-02-26 14:12:15 -080098 @test.idempotent_id('37e8f15e-ee7c-4657-a1e7-f6b61e375eff')
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053099 def test_update_endpoint(self):
Attila Fazekasf7f34f92013-08-01 17:01:44 +0200100 # Creating an endpoint so as to check update endpoint
101 # with new values
Masayuki Igawa259c1132013-10-31 17:48:44 +0900102 region1 = data_utils.rand_name('region')
Dolph Mathews064e9652014-07-11 10:54:38 -0500103 url1 = data_utils.rand_url()
rajalakshmi-ganesanab426722013-02-08 15:49:15 +0530104 interface1 = 'public'
Yaroslav Lobankov2b459ec2015-11-09 15:01:48 +0300105 endpoint_for_update = (
106 self.client.create_endpoint(service_id=self.service_id,
107 interface=interface1,
108 url=url1, region=region1,
109 enabled=True)['endpoint'])
Brant Knudson3a9bdf92014-02-27 17:09:50 -0600110 self.addCleanup(self.client.delete_endpoint, endpoint_for_update['id'])
Attila Fazekasf7f34f92013-08-01 17:01:44 +0200111 # Creating service so as update endpoint with new service ID
Ken'ichi Ohmichi96508472015-03-23 01:43:42 +0000112 s_name = data_utils.rand_name('service')
113 s_type = data_utils.rand_name('type')
114 s_description = data_utils.rand_name('description')
Yaroslav Lobankov61db2d92015-11-11 16:51:23 +0300115 service2 = (
116 self.service_client.create_service(name=s_name, type=s_type,
117 description=s_description))
John Warrenf96750d2015-08-13 13:44:59 +0000118 service2 = service2['service']
Pranav Salunke9b3029c2014-05-25 00:01:05 +0530119 self.service_ids.append(service2['id'])
Attila Fazekasf7f34f92013-08-01 17:01:44 +0200120 # Updating endpoint with new values
Masayuki Igawa259c1132013-10-31 17:48:44 +0900121 region2 = data_utils.rand_name('region')
Dolph Mathews064e9652014-07-11 10:54:38 -0500122 url2 = data_utils.rand_url()
rajalakshmi-ganesanab426722013-02-08 15:49:15 +0530123 interface2 = 'internal'
Yaroslav Lobankov2b459ec2015-11-09 15:01:48 +0300124 endpoint = self.client.update_endpoint(endpoint_for_update['id'],
125 service_id=service2['id'],
126 interface=interface2,
127 url=url2, region=region2,
128 enabled=False)['endpoint']
Attila Fazekasf7f34f92013-08-01 17:01:44 +0200129 # Asserting if the attributes of endpoint are updated
Pranav Salunke9b3029c2014-05-25 00:01:05 +0530130 self.assertEqual(service2['id'], endpoint['service_id'])
rajalakshmi-ganesanab426722013-02-08 15:49:15 +0530131 self.assertEqual(interface2, endpoint['interface'])
132 self.assertEqual(url2, endpoint['url'])
133 self.assertEqual(region2, endpoint['region'])
Ken'ichi Ohmichi73cb70b2015-04-17 02:31:12 +0000134 self.assertEqual(False, endpoint['enabled'])