harika-vakadi | a92dd74 | 2013-02-19 20:41:22 +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 | from urlparse import urlparse |
| 17 | |
| 18 | from lxml import etree |
| 19 | |
| 20 | from tempest.common.rest_client import RestClientXML |
Matthew Treinish | 684d899 | 2014-01-30 16:27:40 +0000 | [diff] [blame] | 21 | from tempest import config |
harika-vakadi | a92dd74 | 2013-02-19 20:41:22 +0530 | [diff] [blame] | 22 | from tempest.services.compute.xml.common import Document |
| 23 | from tempest.services.compute.xml.common import Element |
| 24 | from tempest.services.compute.xml.common import xml_to_json |
| 25 | |
Matthew Treinish | 684d899 | 2014-01-30 16:27:40 +0000 | [diff] [blame] | 26 | CONF = config.CONF |
harika-vakadi | a92dd74 | 2013-02-19 20:41:22 +0530 | [diff] [blame] | 27 | |
| 28 | XMLNS = "http://docs.openstack.org/identity/api/v3" |
| 29 | |
| 30 | |
| 31 | class ServiceClientXML(RestClientXML): |
| 32 | |
Matthew Treinish | 684d899 | 2014-01-30 16:27:40 +0000 | [diff] [blame] | 33 | def __init__(self, username, password, auth_url, tenant_name=None): |
| 34 | super(ServiceClientXML, self).__init__(username, password, |
harika-vakadi | a92dd74 | 2013-02-19 20:41:22 +0530 | [diff] [blame] | 35 | auth_url, tenant_name) |
Matthew Treinish | 684d899 | 2014-01-30 16:27:40 +0000 | [diff] [blame] | 36 | self.service = CONF.identity.catalog_type |
harika-vakadi | a92dd74 | 2013-02-19 20:41:22 +0530 | [diff] [blame] | 37 | self.endpoint_url = 'adminURL' |
| 38 | |
| 39 | def _parse_array(self, node): |
| 40 | array = [] |
| 41 | for child in node.getchildren(): |
| 42 | array.append(xml_to_json(child)) |
| 43 | return array |
| 44 | |
| 45 | def _parse_body(self, body): |
| 46 | data = xml_to_json(body) |
| 47 | return data |
| 48 | |
| 49 | def request(self, method, url, headers=None, body=None, wait=None): |
| 50 | """Overriding the existing HTTP request in super class rest_client.""" |
| 51 | self._set_auth() |
| 52 | self.base_url = self.base_url.replace(urlparse(self.base_url).path, |
| 53 | "/v3") |
| 54 | return super(ServiceClientXML, self).request(method, url, |
| 55 | headers=headers, |
| 56 | body=body) |
| 57 | |
| 58 | def update_service(self, service_id, **kwargs): |
| 59 | """Updates a service_id.""" |
| 60 | resp, body = self.get_service(service_id) |
| 61 | name = kwargs.get('name', body['name']) |
| 62 | description = kwargs.get('description', body['description']) |
| 63 | type = kwargs.get('type', body['type']) |
| 64 | update_service = Element("service", |
| 65 | xmlns=XMLNS, |
| 66 | id=service_id, |
| 67 | name=name, |
| 68 | description=description, |
| 69 | type=type) |
| 70 | resp, body = self.patch('services/%s' % service_id, |
| 71 | str(Document(update_service)), |
| 72 | self.headers) |
| 73 | body = self._parse_body(etree.fromstring(body)) |
| 74 | return resp, body |
| 75 | |
| 76 | def get_service(self, service_id): |
| 77 | """Get Service.""" |
| 78 | url = 'services/%s' % service_id |
| 79 | resp, body = self.get(url, self.headers) |
| 80 | body = self._parse_body(etree.fromstring(body)) |
| 81 | return resp, body |