| 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') | 
| rajalakshmi-ganesan | ab42672 | 2013-02-08 15:49:15 +0530 | [diff] [blame] | 71 | 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 Fazekas | f7f34f9 | 2013-08-01 17:01:44 +0200 | [diff] [blame] | 82 | # Asserting Create Endpoint response body | 
| rajalakshmi-ganesan | ab42672 | 2013-02-08 15:49:15 +0530 | [diff] [blame] | 83 | self.assertEqual(resp['status'], '201') | 
|  | 84 | self.assertEqual(region, endpoint['region']) | 
|  | 85 | self.assertEqual(url, endpoint['url']) | 
| Attila Fazekas | f7f34f9 | 2013-08-01 17:01:44 +0200 | [diff] [blame] | 86 | # Checking if created endpoint is present in the list of endpoints | 
| rajalakshmi-ganesan | ab42672 | 2013-02-08 15:49:15 +0530 | [diff] [blame] | 87 | 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 Fazekas | f7f34f9 | 2013-08-01 17:01:44 +0200 | [diff] [blame] | 97 | # Deleting the endpoint created in this method | 
| rajalakshmi-ganesan | ab42672 | 2013-02-08 15:49:15 +0530 | [diff] [blame] | 98 | resp_header, resp_body =\ | 
|  | 99 | self.client.delete_endpoint(endpoint['id']) | 
|  | 100 | self.assertEqual(resp_header['status'], '204') | 
|  | 101 | self.assertEqual(resp_body, '') | 
| Attila Fazekas | f7f34f9 | 2013-08-01 17:01:44 +0200 | [diff] [blame] | 102 | # Checking whether endpoint is deleted successfully | 
| rajalakshmi-ganesan | ab42672 | 2013-02-08 15:49:15 +0530 | [diff] [blame] | 103 | 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 Lauria | ea29495 | 2013-05-15 08:52:04 -0400 | [diff] [blame] | 110 | @attr(type='smoke') | 
| rajalakshmi-ganesan | ab42672 | 2013-02-08 15:49:15 +0530 | [diff] [blame] | 111 | def test_update_endpoint(self): | 
| Attila Fazekas | f7f34f9 | 2013-08-01 17:01:44 +0200 | [diff] [blame] | 112 | # Creating an endpoint so as to check update endpoint | 
|  | 113 | # with new values | 
| rajalakshmi-ganesan | ab42672 | 2013-02-08 15:49:15 +0530 | [diff] [blame] | 114 | 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 Fazekas | f7f34f9 | 2013-08-01 17:01:44 +0200 | [diff] [blame] | 121 | # Creating service so as update endpoint with new service ID | 
| rajalakshmi-ganesan | ab42672 | 2013-02-08 15:49:15 +0530 | [diff] [blame] | 122 | 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 Fazekas | f7f34f9 | 2013-08-01 17:01:44 +0200 | [diff] [blame] | 129 | # Updating endpoint with new values | 
| rajalakshmi-ganesan | ab42672 | 2013-02-08 15:49:15 +0530 | [diff] [blame] | 130 | 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 Fazekas | f7f34f9 | 2013-08-01 17:01:44 +0200 | [diff] [blame] | 139 | # Asserting if the attributes of endpoint are updated | 
| rajalakshmi-ganesan | ab42672 | 2013-02-08 15:49:15 +0530 | [diff] [blame] | 140 | 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 |  | 
|  | 148 | class EndPointsTestXML(EndPointsTestJSON): | 
|  | 149 | _interface = 'xml' |