blob: dd3b5767498533b51895a004d6a6c07fd18061ba [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
Masayuki Igawa259c1132013-10-31 17:48:44 +090017from 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 _interface = 'json'
23
24 @classmethod
Masayuki Igawadf154682014-03-19 18:32:00 +090025 @test.safe_setup
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053026 def setUpClass(cls):
27 super(EndPointsTestJSON, cls).setUpClass()
28 cls.identity_client = cls.client
29 cls.client = cls.endpoints_client
30 cls.service_ids = list()
Masayuki Igawa259c1132013-10-31 17:48:44 +090031 s_name = data_utils.rand_name('service-')
32 s_type = data_utils.rand_name('type--')
33 s_description = data_utils.rand_name('description-')
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053034 resp, cls.service_data =\
Matthew Treinishdb2c5972014-01-31 22:18:59 +000035 cls.service_client.create_service(s_name, s_type,
36 description=s_description)
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053037 cls.service_id = cls.service_data['id']
38 cls.service_ids.append(cls.service_id)
Attila Fazekasf7f34f92013-08-01 17:01:44 +020039 # Create endpoints so as to use for LIST and GET test cases
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053040 cls.setup_endpoints = list()
41 for i in range(2):
Masayuki Igawa259c1132013-10-31 17:48:44 +090042 region = data_utils.rand_name('region')
43 url = data_utils.rand_name('url')
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053044 interface = 'public'
45 resp, endpoint = cls.client.create_endpoint(
46 cls.service_id, interface, url, region=region, enabled=True)
47 cls.setup_endpoints.append(endpoint)
48
49 @classmethod
50 def tearDownClass(cls):
51 for e in cls.setup_endpoints:
52 cls.client.delete_endpoint(e['id'])
53 for s in cls.service_ids:
Matthew Treinishdb2c5972014-01-31 22:18:59 +000054 cls.service_client.delete_service(s)
Attila Fazekasf86fa312013-07-30 19:56:39 +020055 super(EndPointsTestJSON, cls).tearDownClass()
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053056
Masayuki Igawadf154682014-03-19 18:32:00 +090057 @test.attr(type='gate')
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053058 def test_list_endpoints(self):
59 # Get a list of endpoints
60 resp, fetched_endpoints = self.client.list_endpoints()
Chang Bo Guof099f802013-09-13 19:01:46 -070061 # Asserting LIST endpoints
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053062 self.assertEqual(resp['status'], '200')
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
Masayuki Igawadf154682014-03-19 18:32:00 +090069 @test.attr(type='gate')
Giulio Fidente92f77192013-08-26 17:13:28 +020070 def test_create_list_delete_endpoint(self):
Masayuki Igawa259c1132013-10-31 17:48:44 +090071 region = data_utils.rand_name('region')
72 url = data_utils.rand_name('url')
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053073 interface = 'public'
Giulio Fidente92f77192013-08-26 17:13:28 +020074 resp, endpoint =\
75 self.client.create_endpoint(self.service_id, interface, url,
76 region=region, enabled=True)
77 # Asserting Create Endpoint response body
78 self.assertEqual(resp['status'], '201')
79 self.assertIn('id', endpoint)
80 self.assertEqual(region, endpoint['region'])
81 self.assertEqual(url, endpoint['url'])
82 # Checking if created endpoint is present in the list of endpoints
83 resp, fetched_endpoints = self.client.list_endpoints()
84 fetched_endpoints_id = [e['id'] for e in fetched_endpoints]
85 self.assertIn(endpoint['id'], fetched_endpoints_id)
86 # Deleting the endpoint created in this method
87 resp, body = self.client.delete_endpoint(endpoint['id'])
88 self.assertEqual(resp['status'], '204')
89 self.assertEqual(body, '')
90 # Checking whether endpoint is deleted successfully
91 resp, fetched_endpoints = self.client.list_endpoints()
92 fetched_endpoints_id = [e['id'] for e in fetched_endpoints]
93 self.assertNotIn(endpoint['id'], fetched_endpoints_id)
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053094
Masayuki Igawadf154682014-03-19 18:32:00 +090095 @test.attr(type='smoke')
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053096 def test_update_endpoint(self):
Attila Fazekasf7f34f92013-08-01 17:01:44 +020097 # Creating an endpoint so as to check update endpoint
98 # with new values
Masayuki Igawa259c1132013-10-31 17:48:44 +090099 region1 = data_utils.rand_name('region')
100 url1 = data_utils.rand_name('url')
rajalakshmi-ganesanab426722013-02-08 15:49:15 +0530101 interface1 = 'public'
102 resp, endpoint_for_update =\
103 self.client.create_endpoint(self.service_id, interface1,
104 url1, region=region1,
105 enabled=True)
Brant Knudson3a9bdf92014-02-27 17:09:50 -0600106 self.addCleanup(self.client.delete_endpoint, endpoint_for_update['id'])
Attila Fazekasf7f34f92013-08-01 17:01:44 +0200107 # Creating service so as update endpoint with new service ID
Masayuki Igawa259c1132013-10-31 17:48:44 +0900108 s_name = data_utils.rand_name('service-')
109 s_type = data_utils.rand_name('type--')
110 s_description = data_utils.rand_name('description-')
rajalakshmi-ganesanab426722013-02-08 15:49:15 +0530111 resp, self.service2 =\
Matthew Treinishdb2c5972014-01-31 22:18:59 +0000112 self.service_client.create_service(s_name, s_type,
113 description=s_description)
rajalakshmi-ganesanab426722013-02-08 15:49:15 +0530114 self.service_ids.append(self.service2['id'])
Attila Fazekasf7f34f92013-08-01 17:01:44 +0200115 # Updating endpoint with new values
Masayuki Igawa259c1132013-10-31 17:48:44 +0900116 region2 = data_utils.rand_name('region')
117 url2 = data_utils.rand_name('url')
rajalakshmi-ganesanab426722013-02-08 15:49:15 +0530118 interface2 = 'internal'
119 resp, endpoint = \
120 self.client.update_endpoint(endpoint_for_update['id'],
121 service_id=self.service2['id'],
122 interface=interface2, url=url2,
123 region=region2, enabled=False)
124 self.assertEqual(resp['status'], '200')
Attila Fazekasf7f34f92013-08-01 17:01:44 +0200125 # Asserting if the attributes of endpoint are updated
rajalakshmi-ganesanab426722013-02-08 15:49:15 +0530126 self.assertEqual(self.service2['id'], endpoint['service_id'])
127 self.assertEqual(interface2, endpoint['interface'])
128 self.assertEqual(url2, endpoint['url'])
129 self.assertEqual(region2, endpoint['region'])
Brant Knudson33402992014-02-27 13:31:37 -0600130 self.assertEqual('false', str(endpoint['enabled']).lower())
rajalakshmi-ganesanab426722013-02-08 15:49:15 +0530131
132
133class EndPointsTestXML(EndPointsTestJSON):
134 _interface = 'xml'