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 | |
| 16 | import json |
rajalakshmi-ganesan | ab42672 | 2013-02-08 15:49:15 +0530 | [diff] [blame] | 17 | |
Haiwei Xu | aad85db | 2014-03-05 05:17:39 +0900 | [diff] [blame] | 18 | from tempest.common import rest_client |
Matthew Treinish | 684d899 | 2014-01-30 16:27:40 +0000 | [diff] [blame] | 19 | from tempest import config |
| 20 | |
| 21 | CONF = config.CONF |
rajalakshmi-ganesan | ab42672 | 2013-02-08 15:49:15 +0530 | [diff] [blame] | 22 | |
| 23 | |
Haiwei Xu | aad85db | 2014-03-05 05:17:39 +0900 | [diff] [blame] | 24 | class EndPointClientJSON(rest_client.RestClient): |
rajalakshmi-ganesan | ab42672 | 2013-02-08 15:49:15 +0530 | [diff] [blame] | 25 | |
Andrea Frittoli | 8bbdb16 | 2014-01-06 11:06:13 +0000 | [diff] [blame] | 26 | def __init__(self, auth_provider): |
| 27 | super(EndPointClientJSON, self).__init__(auth_provider) |
Matthew Treinish | 684d899 | 2014-01-30 16:27:40 +0000 | [diff] [blame] | 28 | self.service = CONF.identity.catalog_type |
rajalakshmi-ganesan | ab42672 | 2013-02-08 15:49:15 +0530 | [diff] [blame] | 29 | self.endpoint_url = 'adminURL' |
Andrea Frittoli | 8bbdb16 | 2014-01-06 11:06:13 +0000 | [diff] [blame] | 30 | self.api_version = "v3" |
rajalakshmi-ganesan | ab42672 | 2013-02-08 15:49:15 +0530 | [diff] [blame] | 31 | |
| 32 | def list_endpoints(self): |
| 33 | """GET endpoints.""" |
| 34 | resp, body = self.get('endpoints') |
David Kranz | 2aaf531 | 2014-08-29 09:22:10 -0400 | [diff] [blame] | 35 | self.expected_success(200, resp.status) |
rajalakshmi-ganesan | ab42672 | 2013-02-08 15:49:15 +0530 | [diff] [blame] | 36 | body = json.loads(body) |
| 37 | return resp, body['endpoints'] |
| 38 | |
| 39 | def create_endpoint(self, service_id, interface, url, **kwargs): |
Brant Knudson | 3a9bdf9 | 2014-02-27 17:09:50 -0600 | [diff] [blame] | 40 | """Create endpoint. |
| 41 | |
| 42 | Normally this function wouldn't allow setting values that are not |
| 43 | allowed for 'enabled'. Use `force_enabled` to set a non-boolean. |
| 44 | |
| 45 | """ |
rajalakshmi-ganesan | ab42672 | 2013-02-08 15:49:15 +0530 | [diff] [blame] | 46 | region = kwargs.get('region', None) |
Brant Knudson | 3a9bdf9 | 2014-02-27 17:09:50 -0600 | [diff] [blame] | 47 | if 'force_enabled' in kwargs: |
| 48 | enabled = kwargs.get('force_enabled', None) |
| 49 | else: |
| 50 | enabled = kwargs.get('enabled', None) |
rajalakshmi-ganesan | ab42672 | 2013-02-08 15:49:15 +0530 | [diff] [blame] | 51 | post_body = { |
| 52 | 'service_id': service_id, |
| 53 | 'interface': interface, |
| 54 | 'url': url, |
| 55 | 'region': region, |
| 56 | 'enabled': enabled |
| 57 | } |
| 58 | post_body = json.dumps({'endpoint': post_body}) |
Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 59 | resp, body = self.post('endpoints', post_body) |
David Kranz | 2aaf531 | 2014-08-29 09:22:10 -0400 | [diff] [blame] | 60 | self.expected_success(201, resp.status) |
rajalakshmi-ganesan | ab42672 | 2013-02-08 15:49:15 +0530 | [diff] [blame] | 61 | body = json.loads(body) |
| 62 | return resp, body['endpoint'] |
| 63 | |
| 64 | def update_endpoint(self, endpoint_id, service_id=None, interface=None, |
Brant Knudson | 3a9bdf9 | 2014-02-27 17:09:50 -0600 | [diff] [blame] | 65 | url=None, region=None, enabled=None, **kwargs): |
| 66 | """Updates an endpoint with given parameters. |
| 67 | |
| 68 | Normally this function wouldn't allow setting values that are not |
| 69 | allowed for 'enabled'. Use `force_enabled` to set a non-boolean. |
| 70 | |
| 71 | """ |
rajalakshmi-ganesan | ab42672 | 2013-02-08 15:49:15 +0530 | [diff] [blame] | 72 | post_body = {} |
| 73 | if service_id is not None: |
| 74 | post_body['service_id'] = service_id |
| 75 | if interface is not None: |
| 76 | post_body['interface'] = interface |
| 77 | if url is not None: |
| 78 | post_body['url'] = url |
| 79 | if region is not None: |
| 80 | post_body['region'] = region |
Brant Knudson | 3a9bdf9 | 2014-02-27 17:09:50 -0600 | [diff] [blame] | 81 | if 'force_enabled' in kwargs: |
| 82 | post_body['enabled'] = kwargs['force_enabled'] |
| 83 | elif enabled is not None: |
rajalakshmi-ganesan | ab42672 | 2013-02-08 15:49:15 +0530 | [diff] [blame] | 84 | post_body['enabled'] = enabled |
| 85 | post_body = json.dumps({'endpoint': post_body}) |
Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 86 | resp, body = self.patch('endpoints/%s' % endpoint_id, post_body) |
David Kranz | 2aaf531 | 2014-08-29 09:22:10 -0400 | [diff] [blame] | 87 | self.expected_success(200, resp.status) |
rajalakshmi-ganesan | ab42672 | 2013-02-08 15:49:15 +0530 | [diff] [blame] | 88 | body = json.loads(body) |
| 89 | return resp, body['endpoint'] |
| 90 | |
| 91 | def delete_endpoint(self, endpoint_id): |
| 92 | """Delete endpoint.""" |
| 93 | resp_header, resp_body = self.delete('endpoints/%s' % endpoint_id) |
David Kranz | 2aaf531 | 2014-08-29 09:22:10 -0400 | [diff] [blame] | 94 | self.expected_success(204, resp_header.status) |
rajalakshmi-ganesan | ab42672 | 2013-02-08 15:49:15 +0530 | [diff] [blame] | 95 | return resp_header, resp_body |