blob: df9b234a17725220841aeeea488a723e02f639b1 [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
harika-vakadia92dd742013-02-19 20:41:22 +053016from lxml import etree
17
18from tempest.common.rest_client import RestClientXML
Matthew Treinish684d8992014-01-30 16:27:40 +000019from tempest import config
harika-vakadia92dd742013-02-19 20:41:22 +053020from tempest.services.compute.xml.common import Document
21from tempest.services.compute.xml.common import Element
22from tempest.services.compute.xml.common import xml_to_json
23
Matthew Treinish684d8992014-01-30 16:27:40 +000024CONF = config.CONF
harika-vakadia92dd742013-02-19 20:41:22 +053025
26XMLNS = "http://docs.openstack.org/identity/api/v3"
27
28
29class ServiceClientXML(RestClientXML):
30
Andrea Frittoli8bbdb162014-01-06 11:06:13 +000031 def __init__(self, auth_provider):
32 super(ServiceClientXML, self).__init__(auth_provider)
Matthew Treinish684d8992014-01-30 16:27:40 +000033 self.service = CONF.identity.catalog_type
harika-vakadia92dd742013-02-19 20:41:22 +053034 self.endpoint_url = 'adminURL'
Andrea Frittoli8bbdb162014-01-06 11:06:13 +000035 self.api_version = "v3"
harika-vakadia92dd742013-02-19 20:41:22 +053036
37 def _parse_array(self, node):
38 array = []
39 for child in node.getchildren():
40 array.append(xml_to_json(child))
41 return array
42
43 def _parse_body(self, body):
44 data = xml_to_json(body)
45 return data
46
harika-vakadia92dd742013-02-19 20:41:22 +053047 def update_service(self, service_id, **kwargs):
48 """Updates a service_id."""
49 resp, body = self.get_service(service_id)
50 name = kwargs.get('name', body['name'])
51 description = kwargs.get('description', body['description'])
52 type = kwargs.get('type', body['type'])
53 update_service = Element("service",
54 xmlns=XMLNS,
55 id=service_id,
56 name=name,
57 description=description,
58 type=type)
59 resp, body = self.patch('services/%s' % service_id,
60 str(Document(update_service)),
61 self.headers)
62 body = self._parse_body(etree.fromstring(body))
63 return resp, body
64
65 def get_service(self, service_id):
66 """Get Service."""
67 url = 'services/%s' % service_id
68 resp, body = self.get(url, self.headers)
69 body = self._parse_body(etree.fromstring(body))
70 return resp, body