rajalakshmi-ganesan | ab42672 | 2013-02-08 15:49:15 +0530 | [diff] [blame] | 1 | # 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 Dague | 1937d09 | 2013-05-17 16:36:38 -0400 | [diff] [blame] | 16 | from tempest.api.identity import base |
Masayuki Igawa | 259c113 | 2013-10-31 17:48:44 +0900 | [diff] [blame] | 17 | from tempest.common.utils import data_utils |
rajalakshmi-ganesan | ab42672 | 2013-02-08 15:49:15 +0530 | [diff] [blame] | 18 | from tempest.test import attr |
rajalakshmi-ganesan | ab42672 | 2013-02-08 15:49:15 +0530 | [diff] [blame] | 19 | |
| 20 | |
Matthew Treinish | db2c597 | 2014-01-31 22:18:59 +0000 | [diff] [blame^] | 21 | class EndPointsTestJSON(base.BaseIdentityV3AdminTest): |
rajalakshmi-ganesan | ab42672 | 2013-02-08 15:49:15 +0530 | [diff] [blame] | 22 | _interface = 'json' |
| 23 | |
| 24 | @classmethod |
| 25 | def setUpClass(cls): |
| 26 | super(EndPointsTestJSON, cls).setUpClass() |
| 27 | cls.identity_client = cls.client |
| 28 | cls.client = cls.endpoints_client |
| 29 | cls.service_ids = list() |
Masayuki Igawa | 259c113 | 2013-10-31 17:48:44 +0900 | [diff] [blame] | 30 | s_name = data_utils.rand_name('service-') |
| 31 | s_type = data_utils.rand_name('type--') |
| 32 | s_description = data_utils.rand_name('description-') |
rajalakshmi-ganesan | ab42672 | 2013-02-08 15:49:15 +0530 | [diff] [blame] | 33 | resp, cls.service_data =\ |
Matthew Treinish | db2c597 | 2014-01-31 22:18:59 +0000 | [diff] [blame^] | 34 | cls.service_client.create_service(s_name, s_type, |
| 35 | description=s_description) |
rajalakshmi-ganesan | ab42672 | 2013-02-08 15:49:15 +0530 | [diff] [blame] | 36 | cls.service_id = cls.service_data['id'] |
| 37 | cls.service_ids.append(cls.service_id) |
Attila Fazekas | f7f34f9 | 2013-08-01 17:01:44 +0200 | [diff] [blame] | 38 | # Create endpoints so as to use for LIST and GET test cases |
rajalakshmi-ganesan | ab42672 | 2013-02-08 15:49:15 +0530 | [diff] [blame] | 39 | cls.setup_endpoints = list() |
| 40 | for i in range(2): |
Masayuki Igawa | 259c113 | 2013-10-31 17:48:44 +0900 | [diff] [blame] | 41 | region = data_utils.rand_name('region') |
| 42 | url = data_utils.rand_name('url') |
rajalakshmi-ganesan | ab42672 | 2013-02-08 15:49:15 +0530 | [diff] [blame] | 43 | interface = 'public' |
| 44 | resp, endpoint = cls.client.create_endpoint( |
| 45 | cls.service_id, interface, url, region=region, enabled=True) |
| 46 | cls.setup_endpoints.append(endpoint) |
| 47 | |
| 48 | @classmethod |
| 49 | def tearDownClass(cls): |
| 50 | for e in cls.setup_endpoints: |
| 51 | cls.client.delete_endpoint(e['id']) |
| 52 | for s in cls.service_ids: |
Matthew Treinish | db2c597 | 2014-01-31 22:18:59 +0000 | [diff] [blame^] | 53 | cls.service_client.delete_service(s) |
Attila Fazekas | f86fa31 | 2013-07-30 19:56:39 +0200 | [diff] [blame] | 54 | super(EndPointsTestJSON, cls).tearDownClass() |
rajalakshmi-ganesan | ab42672 | 2013-02-08 15:49:15 +0530 | [diff] [blame] | 55 | |
Giampaolo Lauria | ea29495 | 2013-05-15 08:52:04 -0400 | [diff] [blame] | 56 | @attr(type='gate') |
rajalakshmi-ganesan | ab42672 | 2013-02-08 15:49:15 +0530 | [diff] [blame] | 57 | def test_list_endpoints(self): |
| 58 | # Get a list of endpoints |
| 59 | resp, fetched_endpoints = self.client.list_endpoints() |
Chang Bo Guo | f099f80 | 2013-09-13 19:01:46 -0700 | [diff] [blame] | 60 | # Asserting LIST endpoints |
rajalakshmi-ganesan | ab42672 | 2013-02-08 15:49:15 +0530 | [diff] [blame] | 61 | self.assertEqual(resp['status'], '200') |
| 62 | missing_endpoints =\ |
| 63 | [e for e in self.setup_endpoints if e not in fetched_endpoints] |
| 64 | self.assertEqual(0, len(missing_endpoints), |
| 65 | "Failed to find endpoint %s in fetched list" % |
| 66 | ', '.join(str(e) for e in missing_endpoints)) |
| 67 | |
Giampaolo Lauria | ea29495 | 2013-05-15 08:52:04 -0400 | [diff] [blame] | 68 | @attr(type='gate') |
Giulio Fidente | 92f7719 | 2013-08-26 17:13:28 +0200 | [diff] [blame] | 69 | def test_create_list_delete_endpoint(self): |
Masayuki Igawa | 259c113 | 2013-10-31 17:48:44 +0900 | [diff] [blame] | 70 | region = data_utils.rand_name('region') |
| 71 | url = data_utils.rand_name('url') |
rajalakshmi-ganesan | ab42672 | 2013-02-08 15:49:15 +0530 | [diff] [blame] | 72 | interface = 'public' |
Giulio Fidente | 92f7719 | 2013-08-26 17:13:28 +0200 | [diff] [blame] | 73 | resp, endpoint =\ |
| 74 | self.client.create_endpoint(self.service_id, interface, url, |
| 75 | region=region, enabled=True) |
| 76 | # Asserting Create Endpoint response body |
| 77 | self.assertEqual(resp['status'], '201') |
| 78 | self.assertIn('id', endpoint) |
| 79 | self.assertEqual(region, endpoint['region']) |
| 80 | self.assertEqual(url, endpoint['url']) |
| 81 | # Checking if created endpoint is present in the list of endpoints |
| 82 | resp, fetched_endpoints = self.client.list_endpoints() |
| 83 | fetched_endpoints_id = [e['id'] for e in fetched_endpoints] |
| 84 | self.assertIn(endpoint['id'], fetched_endpoints_id) |
| 85 | # Deleting the endpoint created in this method |
| 86 | resp, body = self.client.delete_endpoint(endpoint['id']) |
| 87 | self.assertEqual(resp['status'], '204') |
| 88 | self.assertEqual(body, '') |
| 89 | # Checking whether endpoint is deleted successfully |
| 90 | resp, fetched_endpoints = self.client.list_endpoints() |
| 91 | fetched_endpoints_id = [e['id'] for e in fetched_endpoints] |
| 92 | self.assertNotIn(endpoint['id'], fetched_endpoints_id) |
rajalakshmi-ganesan | ab42672 | 2013-02-08 15:49:15 +0530 | [diff] [blame] | 93 | |
Giampaolo Lauria | ea29495 | 2013-05-15 08:52:04 -0400 | [diff] [blame] | 94 | @attr(type='smoke') |
rajalakshmi-ganesan | ab42672 | 2013-02-08 15:49:15 +0530 | [diff] [blame] | 95 | def test_update_endpoint(self): |
Attila Fazekas | f7f34f9 | 2013-08-01 17:01:44 +0200 | [diff] [blame] | 96 | # Creating an endpoint so as to check update endpoint |
| 97 | # with new values |
Masayuki Igawa | 259c113 | 2013-10-31 17:48:44 +0900 | [diff] [blame] | 98 | region1 = data_utils.rand_name('region') |
| 99 | url1 = data_utils.rand_name('url') |
rajalakshmi-ganesan | ab42672 | 2013-02-08 15:49:15 +0530 | [diff] [blame] | 100 | interface1 = 'public' |
| 101 | resp, endpoint_for_update =\ |
| 102 | self.client.create_endpoint(self.service_id, interface1, |
| 103 | url1, region=region1, |
| 104 | enabled=True) |
Attila Fazekas | f7f34f9 | 2013-08-01 17:01:44 +0200 | [diff] [blame] | 105 | # Creating service so as update endpoint with new service ID |
Masayuki Igawa | 259c113 | 2013-10-31 17:48:44 +0900 | [diff] [blame] | 106 | s_name = data_utils.rand_name('service-') |
| 107 | s_type = data_utils.rand_name('type--') |
| 108 | s_description = data_utils.rand_name('description-') |
rajalakshmi-ganesan | ab42672 | 2013-02-08 15:49:15 +0530 | [diff] [blame] | 109 | resp, self.service2 =\ |
Matthew Treinish | db2c597 | 2014-01-31 22:18:59 +0000 | [diff] [blame^] | 110 | self.service_client.create_service(s_name, s_type, |
| 111 | description=s_description) |
rajalakshmi-ganesan | ab42672 | 2013-02-08 15:49:15 +0530 | [diff] [blame] | 112 | self.service_ids.append(self.service2['id']) |
Attila Fazekas | f7f34f9 | 2013-08-01 17:01:44 +0200 | [diff] [blame] | 113 | # Updating endpoint with new values |
Masayuki Igawa | 259c113 | 2013-10-31 17:48:44 +0900 | [diff] [blame] | 114 | region2 = data_utils.rand_name('region') |
| 115 | url2 = data_utils.rand_name('url') |
rajalakshmi-ganesan | ab42672 | 2013-02-08 15:49:15 +0530 | [diff] [blame] | 116 | interface2 = 'internal' |
| 117 | resp, endpoint = \ |
| 118 | self.client.update_endpoint(endpoint_for_update['id'], |
| 119 | service_id=self.service2['id'], |
| 120 | interface=interface2, url=url2, |
| 121 | region=region2, enabled=False) |
| 122 | self.assertEqual(resp['status'], '200') |
Attila Fazekas | f7f34f9 | 2013-08-01 17:01:44 +0200 | [diff] [blame] | 123 | # Asserting if the attributes of endpoint are updated |
rajalakshmi-ganesan | ab42672 | 2013-02-08 15:49:15 +0530 | [diff] [blame] | 124 | self.assertEqual(self.service2['id'], endpoint['service_id']) |
| 125 | self.assertEqual(interface2, endpoint['interface']) |
| 126 | self.assertEqual(url2, endpoint['url']) |
| 127 | self.assertEqual(region2, endpoint['region']) |
| 128 | self.assertEqual('False', str(endpoint['enabled'])) |
| 129 | self.addCleanup(self.client.delete_endpoint, endpoint_for_update['id']) |
| 130 | |
| 131 | |
| 132 | class EndPointsTestXML(EndPointsTestJSON): |
| 133 | _interface = 'xml' |