blob: 306245b12e44b43fb3d1a4b0408dd89fe3469900 [file] [log] [blame]
harika-vakadia92dd742013-02-19 20:41:22 +05301# 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
18from urlparse import urlparse
19
20from lxml import etree
21
22from tempest.common.rest_client import RestClientXML
23from tempest.services.compute.xml.common import Document
24from tempest.services.compute.xml.common import Element
25from tempest.services.compute.xml.common import xml_to_json
26
27
28XMLNS = "http://docs.openstack.org/identity/api/v3"
29
30
31class ServiceClientXML(RestClientXML):
32
33 def __init__(self, config, username, password, auth_url, tenant_name=None):
34 super(ServiceClientXML, self).__init__(config, username, password,
35 auth_url, tenant_name)
36 self.service = self.config.identity.catalog_type
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