blob: a32eedeb487d7414f364649b6922b919b62a5037 [file] [log] [blame]
rajalakshmi-ganesanab426722013-02-08 15:49:15 +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.
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053015
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053016from lxml import etree
17
Mate Lakat23a58a32013-08-23 02:06:22 +010018from tempest.common import http
vponomaryov960eeb42014-02-22 18:25:25 +020019from tempest.common import rest_client
Matthew Treinish684d8992014-01-30 16:27:40 +000020from tempest import config
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053021from tempest.services.compute.xml.common import Document
22from tempest.services.compute.xml.common import Element
23from tempest.services.compute.xml.common import xml_to_json
24
Matthew Treinish684d8992014-01-30 16:27:40 +000025CONF = config.CONF
26
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053027XMLNS = "http://docs.openstack.org/identity/api/v3"
28
29
vponomaryov960eeb42014-02-22 18:25:25 +020030class EndPointClientXML(rest_client.RestClient):
31 TYPE = "xml"
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053032
Andrea Frittoli8bbdb162014-01-06 11:06:13 +000033 def __init__(self, auth_provider):
34 super(EndPointClientXML, self).__init__(auth_provider)
Matthew Treinish684d8992014-01-30 16:27:40 +000035 self.service = CONF.identity.catalog_type
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053036 self.endpoint_url = 'adminURL'
Andrea Frittoli8bbdb162014-01-06 11:06:13 +000037 self.api_version = "v3"
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053038
39 def _parse_array(self, node):
40 array = []
41 for child in node.getchildren():
42 tag_list = child.tag.split('}', 1)
43 if tag_list[1] == "endpoint":
44 array.append(xml_to_json(child))
45 return array
46
47 def _parse_body(self, body):
48 json = xml_to_json(body)
49 return json
50
51 def request(self, method, url, headers=None, body=None, wait=None):
52 """Overriding the existing HTTP request in super class RestClient."""
Matthew Treinish684d8992014-01-30 16:27:40 +000053 dscv = CONF.identity.disable_ssl_certificate_validation
Mate Lakat23a58a32013-08-23 02:06:22 +010054 self.http_obj = http.ClosingHttp(
55 disable_ssl_certificate_validation=dscv)
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053056 return super(EndPointClientXML, self).request(method, url,
57 headers=headers,
58 body=body)
59
60 def list_endpoints(self):
61 """Get the list of endpoints."""
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +020062 resp, body = self.get("endpoints")
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053063 body = self._parse_array(etree.fromstring(body))
64 return resp, body
65
66 def create_endpoint(self, service_id, interface, url, **kwargs):
67 """Create endpoint."""
68 region = kwargs.get('region', None)
69 enabled = kwargs.get('enabled', None)
70 create_endpoint = Element("endpoint",
71 xmlns=XMLNS,
72 service_id=service_id,
73 interface=interface,
74 url=url, region=region,
75 enabled=enabled)
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +020076 resp, body = self.post('endpoints', str(Document(create_endpoint)))
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053077 body = self._parse_body(etree.fromstring(body))
78 return resp, body
79
80 def update_endpoint(self, endpoint_id, service_id=None, interface=None,
81 url=None, region=None, enabled=None):
82 """Updates an endpoint with given parameters."""
83 doc = Document()
84 endpoint = Element("endpoint")
85 doc.append(endpoint)
86
87 if service_id:
88 endpoint.add_attr("service_id", service_id)
89 if interface:
90 endpoint.add_attr("interface", interface)
91 if url:
92 endpoint.add_attr("url", url)
93 if region:
94 endpoint.add_attr("region", region)
95 if enabled is not None:
96 endpoint.add_attr("enabled", enabled)
Valeriy Ponomaryov88686d82014-02-16 12:24:51 +020097 resp, body = self.patch('endpoints/%s' % str(endpoint_id), str(doc))
rajalakshmi-ganesanab426722013-02-08 15:49:15 +053098 body = self._parse_body(etree.fromstring(body))
99 return resp, body
100
101 def delete_endpoint(self, endpoint_id):
102 """Delete endpoint."""
103 resp_header, resp_body = self.delete('endpoints/%s' % endpoint_id)
104 return resp_header, resp_body