blob: d98fb719072bfaa184cc27df3c4d5a87cb6155c2 [file] [log] [blame]
rajalakshmi-ganesanab426722013-02-08 15:49:15 +05301# vim: tabstop=4 shiftwidth=4 softtabstop=4
2
3# Copyright 2013 OpenStack Foundation
4# All Rights Reserved.
5#
6# Licensed under the Apache License, Version 2.0 (the "License"); you may
7# not use this file except in compliance with the License. You may obtain
8# a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15# License for the specific language governing permissions and limitations
16# under the License.
17
Sean Dague1937d092013-05-17 16:36:38 -040018from tempest.api.identity import base
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053019from tempest.common.utils.data_utils import rand_name
20from tempest.test import attr
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053021
22
23class EndPointsTestJSON(base.BaseIdentityAdminTest):
24 _interface = 'json'
25
26 @classmethod
27 def setUpClass(cls):
28 super(EndPointsTestJSON, cls).setUpClass()
29 cls.identity_client = cls.client
30 cls.client = cls.endpoints_client
31 cls.service_ids = list()
32 s_name = rand_name('service-')
33 s_type = rand_name('type--')
34 s_description = rand_name('description-')
35 resp, cls.service_data =\
36 cls.identity_client.create_service(s_name, s_type,
37 description=s_description)
38 cls.service_id = cls.service_data['id']
39 cls.service_ids.append(cls.service_id)
Attila Fazekasf7f34f92013-08-01 17:01:44 +020040 # Create endpoints so as to use for LIST and GET test cases
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053041 cls.setup_endpoints = list()
42 for i in range(2):
43 region = rand_name('region')
44 url = rand_name('url')
45 interface = 'public'
46 resp, endpoint = cls.client.create_endpoint(
47 cls.service_id, interface, url, region=region, enabled=True)
48 cls.setup_endpoints.append(endpoint)
49
50 @classmethod
51 def tearDownClass(cls):
52 for e in cls.setup_endpoints:
53 cls.client.delete_endpoint(e['id'])
54 for s in cls.service_ids:
55 cls.identity_client.delete_service(s)
Attila Fazekasf86fa312013-07-30 19:56:39 +020056 super(EndPointsTestJSON, cls).tearDownClass()
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053057
Giampaolo Lauriaea294952013-05-15 08:52:04 -040058 @attr(type='gate')
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053059 def test_list_endpoints(self):
60 # Get a list of endpoints
61 resp, fetched_endpoints = self.client.list_endpoints()
Attila Fazekasf7f34f92013-08-01 17:01:44 +020062 # Asserting LIST Endpoint
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053063 self.assertEqual(resp['status'], '200')
64 missing_endpoints =\
65 [e for e in self.setup_endpoints if e not in fetched_endpoints]
66 self.assertEqual(0, len(missing_endpoints),
67 "Failed to find endpoint %s in fetched list" %
68 ', '.join(str(e) for e in missing_endpoints))
69
Giampaolo Lauriaea294952013-05-15 08:52:04 -040070 @attr(type='gate')
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053071 def test_create_delete_endpoint(self):
72 region = rand_name('region')
73 url = rand_name('url')
74 interface = 'public'
75 create_flag = False
76 matched = False
77 try:
78 resp, endpoint =\
79 self.client.create_endpoint(self.service_id, interface, url,
80 region=region, enabled=True)
81 create_flag = True
Attila Fazekasf7f34f92013-08-01 17:01:44 +020082 # Asserting Create Endpoint response body
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053083 self.assertEqual(resp['status'], '201')
84 self.assertEqual(region, endpoint['region'])
85 self.assertEqual(url, endpoint['url'])
Attila Fazekasf7f34f92013-08-01 17:01:44 +020086 # Checking if created endpoint is present in the list of endpoints
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053087 resp, fetched_endpoints = self.client.list_endpoints()
88 for e in fetched_endpoints:
89 if endpoint['id'] == e['id']:
90 matched = True
91 if not matched:
92 self.fail("Created endpoint does not appear in the list"
93 " of endpoints")
94 finally:
95 if create_flag:
96 matched = False
Attila Fazekasf7f34f92013-08-01 17:01:44 +020097 # Deleting the endpoint created in this method
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053098 resp_header, resp_body =\
99 self.client.delete_endpoint(endpoint['id'])
100 self.assertEqual(resp_header['status'], '204')
101 self.assertEqual(resp_body, '')
Attila Fazekasf7f34f92013-08-01 17:01:44 +0200102 # Checking whether endpoint is deleted successfully
rajalakshmi-ganesanab426722013-02-08 15:49:15 +0530103 resp, fetched_endpoints = self.client.list_endpoints()
104 for e in fetched_endpoints:
105 if endpoint['id'] == e['id']:
106 matched = True
107 if matched:
108 self.fail("Delete endpoint is not successful")
109
Giampaolo Lauriaea294952013-05-15 08:52:04 -0400110 @attr(type='smoke')
rajalakshmi-ganesanab426722013-02-08 15:49:15 +0530111 def test_update_endpoint(self):
Attila Fazekasf7f34f92013-08-01 17:01:44 +0200112 # Creating an endpoint so as to check update endpoint
113 # with new values
rajalakshmi-ganesanab426722013-02-08 15:49:15 +0530114 region1 = rand_name('region')
115 url1 = rand_name('url')
116 interface1 = 'public'
117 resp, endpoint_for_update =\
118 self.client.create_endpoint(self.service_id, interface1,
119 url1, region=region1,
120 enabled=True)
Attila Fazekasf7f34f92013-08-01 17:01:44 +0200121 # Creating service so as update endpoint with new service ID
rajalakshmi-ganesanab426722013-02-08 15:49:15 +0530122 s_name = rand_name('service-')
123 s_type = rand_name('type--')
124 s_description = rand_name('description-')
125 resp, self.service2 =\
126 self.identity_client.create_service(s_name, s_type,
127 description=s_description)
128 self.service_ids.append(self.service2['id'])
Attila Fazekasf7f34f92013-08-01 17:01:44 +0200129 # Updating endpoint with new values
rajalakshmi-ganesanab426722013-02-08 15:49:15 +0530130 region2 = rand_name('region')
131 url2 = rand_name('url')
132 interface2 = 'internal'
133 resp, endpoint = \
134 self.client.update_endpoint(endpoint_for_update['id'],
135 service_id=self.service2['id'],
136 interface=interface2, url=url2,
137 region=region2, enabled=False)
138 self.assertEqual(resp['status'], '200')
Attila Fazekasf7f34f92013-08-01 17:01:44 +0200139 # Asserting if the attributes of endpoint are updated
rajalakshmi-ganesanab426722013-02-08 15:49:15 +0530140 self.assertEqual(self.service2['id'], endpoint['service_id'])
141 self.assertEqual(interface2, endpoint['interface'])
142 self.assertEqual(url2, endpoint['url'])
143 self.assertEqual(region2, endpoint['region'])
144 self.assertEqual('False', str(endpoint['enabled']))
145 self.addCleanup(self.client.delete_endpoint, endpoint_for_update['id'])
146
147
148class EndPointsTestXML(EndPointsTestJSON):
149 _interface = 'xml'