rajalakshmi-ganesan | ab42672 | 2013-02-08 15:49:15 +0530 | [diff] [blame] | 1 | # 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 Dague | 1937d09 | 2013-05-17 16:36:38 -0400 | [diff] [blame] | 18 | from tempest.api.identity import base |
rajalakshmi-ganesan | ab42672 | 2013-02-08 15:49:15 +0530 | [diff] [blame] | 19 | from tempest.common.utils.data_utils import rand_name |
| 20 | from tempest.test import attr |
rajalakshmi-ganesan | ab42672 | 2013-02-08 15:49:15 +0530 | [diff] [blame] | 21 | |
| 22 | |
| 23 | class 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 Fazekas | f7f34f9 | 2013-08-01 17:01:44 +0200 | [diff] [blame] | 40 | # Create endpoints so as to use for LIST and GET test cases |
rajalakshmi-ganesan | ab42672 | 2013-02-08 15:49:15 +0530 | [diff] [blame] | 41 | 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 Fazekas | f86fa31 | 2013-07-30 19:56:39 +0200 | [diff] [blame] | 56 | super(EndPointsTestJSON, cls).tearDownClass() |
rajalakshmi-ganesan | ab42672 | 2013-02-08 15:49:15 +0530 | [diff] [blame] | 57 | |
Giampaolo Lauria | ea29495 | 2013-05-15 08:52:04 -0400 | [diff] [blame] | 58 | @attr(type='gate') |
rajalakshmi-ganesan | ab42672 | 2013-02-08 15:49:15 +0530 | [diff] [blame] | 59 | def test_list_endpoints(self): |
| 60 | # Get a list of endpoints |
| 61 | resp, fetched_endpoints = self.client.list_endpoints() |
Attila Fazekas | f7f34f9 | 2013-08-01 17:01:44 +0200 | [diff] [blame] | 62 | # Asserting LIST Endpoint |
rajalakshmi-ganesan | ab42672 | 2013-02-08 15:49:15 +0530 | [diff] [blame] | 63 | 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 Lauria | ea29495 | 2013-05-15 08:52:04 -0400 | [diff] [blame] | 70 | @attr(type='gate') |
Giulio Fidente | 92f7719 | 2013-08-26 17:13:28 +0200 | [diff] [blame^] | 71 | def test_create_list_delete_endpoint(self): |
rajalakshmi-ganesan | ab42672 | 2013-02-08 15:49:15 +0530 | [diff] [blame] | 72 | region = rand_name('region') |
| 73 | url = rand_name('url') |
| 74 | interface = 'public' |
Giulio Fidente | 92f7719 | 2013-08-26 17:13:28 +0200 | [diff] [blame^] | 75 | 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-ganesan | ab42672 | 2013-02-08 15:49:15 +0530 | [diff] [blame] | 95 | |
Giampaolo Lauria | ea29495 | 2013-05-15 08:52:04 -0400 | [diff] [blame] | 96 | @attr(type='smoke') |
rajalakshmi-ganesan | ab42672 | 2013-02-08 15:49:15 +0530 | [diff] [blame] | 97 | def test_update_endpoint(self): |
Attila Fazekas | f7f34f9 | 2013-08-01 17:01:44 +0200 | [diff] [blame] | 98 | # Creating an endpoint so as to check update endpoint |
| 99 | # with new values |
rajalakshmi-ganesan | ab42672 | 2013-02-08 15:49:15 +0530 | [diff] [blame] | 100 | 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 Fazekas | f7f34f9 | 2013-08-01 17:01:44 +0200 | [diff] [blame] | 107 | # Creating service so as update endpoint with new service ID |
rajalakshmi-ganesan | ab42672 | 2013-02-08 15:49:15 +0530 | [diff] [blame] | 108 | 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 Fazekas | f7f34f9 | 2013-08-01 17:01:44 +0200 | [diff] [blame] | 115 | # Updating endpoint with new values |
rajalakshmi-ganesan | ab42672 | 2013-02-08 15:49:15 +0530 | [diff] [blame] | 116 | 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 Fazekas | f7f34f9 | 2013-08-01 17:01:44 +0200 | [diff] [blame] | 125 | # Asserting if the attributes of endpoint are updated |
rajalakshmi-ganesan | ab42672 | 2013-02-08 15:49:15 +0530 | [diff] [blame] | 126 | 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 | |
| 134 | class EndPointsTestXML(EndPointsTestJSON): |
| 135 | _interface = 'xml' |