blob: 9d143ed65cab7dd5f98d68479f6025f997032b99 [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')
Giulio Fidente92f77192013-08-26 17:13:28 +020071 def test_create_list_delete_endpoint(self):
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053072 region = rand_name('region')
73 url = rand_name('url')
74 interface = 'public'
Giulio Fidente92f77192013-08-26 17:13:28 +020075 resp, endpoint =\
76 self.client.create_endpoint(self.service_id, interface, url,
77 region=region, enabled=True)
78 # Asserting Create Endpoint response body
79 self.assertEqual(resp['status'], '201')
80 self.assertIn('id', endpoint)
81 self.assertEqual(region, endpoint['region'])
82 self.assertEqual(url, endpoint['url'])
83 # Checking if created endpoint is present in the list of endpoints
84 resp, fetched_endpoints = self.client.list_endpoints()
85 fetched_endpoints_id = [e['id'] for e in fetched_endpoints]
86 self.assertIn(endpoint['id'], fetched_endpoints_id)
87 # Deleting the endpoint created in this method
88 resp, body = self.client.delete_endpoint(endpoint['id'])
89 self.assertEqual(resp['status'], '204')
90 self.assertEqual(body, '')
91 # Checking whether endpoint is deleted successfully
92 resp, fetched_endpoints = self.client.list_endpoints()
93 fetched_endpoints_id = [e['id'] for e in fetched_endpoints]
94 self.assertNotIn(endpoint['id'], fetched_endpoints_id)
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053095
Giampaolo Lauriaea294952013-05-15 08:52:04 -040096 @attr(type='smoke')
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053097 def test_update_endpoint(self):
Attila Fazekasf7f34f92013-08-01 17:01:44 +020098 # Creating an endpoint so as to check update endpoint
99 # with new values
rajalakshmi-ganesanab426722013-02-08 15:49:15 +0530100 region1 = rand_name('region')
101 url1 = rand_name('url')
102 interface1 = 'public'
103 resp, endpoint_for_update =\
104 self.client.create_endpoint(self.service_id, interface1,
105 url1, region=region1,
106 enabled=True)
Attila Fazekasf7f34f92013-08-01 17:01:44 +0200107 # Creating service so as update endpoint with new service ID
rajalakshmi-ganesanab426722013-02-08 15:49:15 +0530108 s_name = rand_name('service-')
109 s_type = rand_name('type--')
110 s_description = rand_name('description-')
111 resp, self.service2 =\
112 self.identity_client.create_service(s_name, s_type,
113 description=s_description)
114 self.service_ids.append(self.service2['id'])
Attila Fazekasf7f34f92013-08-01 17:01:44 +0200115 # Updating endpoint with new values
rajalakshmi-ganesanab426722013-02-08 15:49:15 +0530116 region2 = rand_name('region')
117 url2 = rand_name('url')
118 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'])
130 self.assertEqual('False', str(endpoint['enabled']))
131 self.addCleanup(self.client.delete_endpoint, endpoint_for_update['id'])
132
133
134class EndPointsTestXML(EndPointsTestJSON):
135 _interface = 'xml'