blob: 2997775915bf4bf5da10a10b81ad178709763f4d [file] [log] [blame]
harika-vakadia92dd742013-02-19 20:41:22 +05301# 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
16from urlparse import urlparse
17
18from lxml import etree
19
20from tempest.common.rest_client import RestClientXML
Matthew Treinish684d8992014-01-30 16:27:40 +000021from tempest import config
harika-vakadia92dd742013-02-19 20:41:22 +053022from tempest.services.compute.xml.common import Document
23from tempest.services.compute.xml.common import Element
24from tempest.services.compute.xml.common import xml_to_json
25
Matthew Treinish684d8992014-01-30 16:27:40 +000026CONF = config.CONF
harika-vakadia92dd742013-02-19 20:41:22 +053027
28XMLNS = "http://docs.openstack.org/identity/api/v3"
29
30
31class ServiceClientXML(RestClientXML):
32
Matthew Treinish684d8992014-01-30 16:27:40 +000033 def __init__(self, username, password, auth_url, tenant_name=None):
34 super(ServiceClientXML, self).__init__(username, password,
harika-vakadia92dd742013-02-19 20:41:22 +053035 auth_url, tenant_name)
Matthew Treinish684d8992014-01-30 16:27:40 +000036 self.service = CONF.identity.catalog_type
harika-vakadia92dd742013-02-19 20:41:22 +053037 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