blob: eed0eb5513392be0b7c8ece277f8fb754ed06300 [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
Andrea Frittoli7688e742014-09-15 12:38:22 +010025 def resource_setup(cls):
26 super(EndPointsTestJSON, cls).resource_setup()
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053027 cls.identity_client = cls.client
28 cls.client = cls.endpoints_client
29 cls.service_ids = list()
Masayuki Igawa259c1132013-10-31 17:48:44 +090030 s_name = data_utils.rand_name('service-')
31 s_type = data_utils.rand_name('type--')
32 s_description = data_utils.rand_name('description-')
David Kranzd8ccb792014-12-29 11:32:05 -050033 cls.service_data =\
Matthew Treinishdb2c5972014-01-31 22:18:59 +000034 cls.service_client.create_service(s_name, s_type,
35 description=s_description)
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053036 cls.service_id = cls.service_data['id']
37 cls.service_ids.append(cls.service_id)
Attila Fazekasf7f34f92013-08-01 17:01:44 +020038 # Create endpoints so as to use for LIST and GET test cases
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053039 cls.setup_endpoints = list()
40 for i in range(2):
Masayuki Igawa259c1132013-10-31 17:48:44 +090041 region = data_utils.rand_name('region')
Dolph Mathews064e9652014-07-11 10:54:38 -050042 url = data_utils.rand_url()
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053043 interface = 'public'
David Kranzd8ccb792014-12-29 11:32:05 -050044 endpoint = cls.client.create_endpoint(
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053045 cls.service_id, interface, url, region=region, enabled=True)
46 cls.setup_endpoints.append(endpoint)
47
48 @classmethod
Andrea Frittoli7688e742014-09-15 12:38:22 +010049 def resource_cleanup(cls):
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053050 for e in cls.setup_endpoints:
51 cls.client.delete_endpoint(e['id'])
52 for s in cls.service_ids:
Matthew Treinishdb2c5972014-01-31 22:18:59 +000053 cls.service_client.delete_service(s)
Andrea Frittoli7688e742014-09-15 12:38:22 +010054 super(EndPointsTestJSON, cls).resource_cleanup()
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053055
Masayuki Igawadf154682014-03-19 18:32:00 +090056 @test.attr(type='gate')
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053057 def test_list_endpoints(self):
58 # Get a list of endpoints
David Kranzd8ccb792014-12-29 11:32:05 -050059 fetched_endpoints = self.client.list_endpoints()
Chang Bo Guof099f802013-09-13 19:01:46 -070060 # Asserting LIST endpoints
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053061 missing_endpoints =\
62 [e for e in self.setup_endpoints if e not in fetched_endpoints]
63 self.assertEqual(0, len(missing_endpoints),
64 "Failed to find endpoint %s in fetched list" %
65 ', '.join(str(e) for e in missing_endpoints))
66
Masayuki Igawadf154682014-03-19 18:32:00 +090067 @test.attr(type='gate')
Giulio Fidente92f77192013-08-26 17:13:28 +020068 def test_create_list_delete_endpoint(self):
Masayuki Igawa259c1132013-10-31 17:48:44 +090069 region = data_utils.rand_name('region')
Dolph Mathews064e9652014-07-11 10:54:38 -050070 url = data_utils.rand_url()
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053071 interface = 'public'
David Kranzd8ccb792014-12-29 11:32:05 -050072 endpoint =\
Giulio Fidente92f77192013-08-26 17:13:28 +020073 self.client.create_endpoint(self.service_id, interface, url,
74 region=region, enabled=True)
75 # Asserting Create Endpoint response body
Giulio Fidente92f77192013-08-26 17:13:28 +020076 self.assertIn('id', endpoint)
77 self.assertEqual(region, endpoint['region'])
78 self.assertEqual(url, endpoint['url'])
79 # Checking if created endpoint is present in the list of endpoints
David Kranzd8ccb792014-12-29 11:32:05 -050080 fetched_endpoints = self.client.list_endpoints()
Giulio Fidente92f77192013-08-26 17:13:28 +020081 fetched_endpoints_id = [e['id'] for e in fetched_endpoints]
82 self.assertIn(endpoint['id'], fetched_endpoints_id)
83 # Deleting the endpoint created in this method
ghanshyama2016372014-10-24 11:15:01 +090084 self.client.delete_endpoint(endpoint['id'])
Giulio Fidente92f77192013-08-26 17:13:28 +020085 # Checking whether endpoint is deleted successfully
David Kranzd8ccb792014-12-29 11:32:05 -050086 fetched_endpoints = self.client.list_endpoints()
Giulio Fidente92f77192013-08-26 17:13:28 +020087 fetched_endpoints_id = [e['id'] for e in fetched_endpoints]
88 self.assertNotIn(endpoint['id'], fetched_endpoints_id)
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053089
Masayuki Igawadf154682014-03-19 18:32:00 +090090 @test.attr(type='smoke')
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053091 def test_update_endpoint(self):
Attila Fazekasf7f34f92013-08-01 17:01:44 +020092 # Creating an endpoint so as to check update endpoint
93 # with new values
Masayuki Igawa259c1132013-10-31 17:48:44 +090094 region1 = data_utils.rand_name('region')
Dolph Mathews064e9652014-07-11 10:54:38 -050095 url1 = data_utils.rand_url()
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053096 interface1 = 'public'
David Kranzd8ccb792014-12-29 11:32:05 -050097 endpoint_for_update =\
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053098 self.client.create_endpoint(self.service_id, interface1,
99 url1, region=region1,
100 enabled=True)
Brant Knudson3a9bdf92014-02-27 17:09:50 -0600101 self.addCleanup(self.client.delete_endpoint, endpoint_for_update['id'])
Attila Fazekasf7f34f92013-08-01 17:01:44 +0200102 # Creating service so as update endpoint with new service ID
Masayuki Igawa259c1132013-10-31 17:48:44 +0900103 s_name = data_utils.rand_name('service-')
104 s_type = data_utils.rand_name('type--')
105 s_description = data_utils.rand_name('description-')
David Kranzd8ccb792014-12-29 11:32:05 -0500106 service2 =\
Matthew Treinishdb2c5972014-01-31 22:18:59 +0000107 self.service_client.create_service(s_name, s_type,
108 description=s_description)
Pranav Salunke9b3029c2014-05-25 00:01:05 +0530109 self.service_ids.append(service2['id'])
Attila Fazekasf7f34f92013-08-01 17:01:44 +0200110 # Updating endpoint with new values
Masayuki Igawa259c1132013-10-31 17:48:44 +0900111 region2 = data_utils.rand_name('region')
Dolph Mathews064e9652014-07-11 10:54:38 -0500112 url2 = data_utils.rand_url()
rajalakshmi-ganesanab426722013-02-08 15:49:15 +0530113 interface2 = 'internal'
David Kranzd8ccb792014-12-29 11:32:05 -0500114 endpoint = \
rajalakshmi-ganesanab426722013-02-08 15:49:15 +0530115 self.client.update_endpoint(endpoint_for_update['id'],
Pranav Salunke9b3029c2014-05-25 00:01:05 +0530116 service_id=service2['id'],
rajalakshmi-ganesanab426722013-02-08 15:49:15 +0530117 interface=interface2, url=url2,
118 region=region2, enabled=False)
Attila Fazekasf7f34f92013-08-01 17:01:44 +0200119 # Asserting if the attributes of endpoint are updated
Pranav Salunke9b3029c2014-05-25 00:01:05 +0530120 self.assertEqual(service2['id'], endpoint['service_id'])
rajalakshmi-ganesanab426722013-02-08 15:49:15 +0530121 self.assertEqual(interface2, endpoint['interface'])
122 self.assertEqual(url2, endpoint['url'])
123 self.assertEqual(region2, endpoint['region'])
Brant Knudson33402992014-02-27 13:31:37 -0600124 self.assertEqual('false', str(endpoint['enabled']).lower())