Merge "Update service test case - V3"
diff --git a/tempest/clients.py b/tempest/clients.py
index 2934f81..7b1e5cc 100644
--- a/tempest/clients.py
+++ b/tempest/clients.py
@@ -66,9 +66,13 @@
EndPointClientJSON
from tempest.services.identity.v3.json.identity_client import \
IdentityV3ClientJSON
+from tempest.services.identity.v3.json.service_client import \
+ ServiceClientJSON
from tempest.services.identity.v3.xml.endpoints_client import EndPointClientXML
from tempest.services.identity.v3.xml.identity_client import \
IdentityV3ClientXML
+from tempest.services.identity.v3.xml.service_client import \
+ ServiceClientXML
from tempest.services.identity.xml.identity_client import IdentityClientXML
from tempest.services.identity.xml.identity_client import TokenClientXML
from tempest.services.image.v1.json.image_client import ImageClientJSON
@@ -192,6 +196,11 @@
"xml": AvailabilityZoneClientXML,
}
+SERVICE_CLIENT = {
+ "json": ServiceClientJSON,
+ "xml": ServiceClientXML,
+}
+
class Manager(object):
@@ -260,6 +269,7 @@
self.fixed_ips_client = FIXED_IPS_CLIENT[interface](*client_args)
self.availability_zone_client = \
AVAILABILITY_ZONE_CLIENT[interface](*client_args)
+ self.service_client = SERVICE_CLIENT[interface](*client_args)
except KeyError:
msg = "Unsupported interface type `%s'" % interface
raise exceptions.InvalidConfiguration(msg)
diff --git a/tempest/services/identity/v3/json/service_client.py b/tempest/services/identity/v3/json/service_client.py
new file mode 100644
index 0000000..dde572e
--- /dev/null
+++ b/tempest/services/identity/v3/json/service_client.py
@@ -0,0 +1,63 @@
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
+
+# Copyright 2013 OpenStack Foundation
+# All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+import json
+from urlparse import urlparse
+
+from tempest.common.rest_client import RestClient
+
+
+class ServiceClientJSON(RestClient):
+
+ def __init__(self, config, username, password, auth_url, tenant_name=None):
+ super(ServiceClientJSON, self).__init__(config, username, password,
+ auth_url, tenant_name)
+ self.service = self.config.identity.catalog_type
+ self.endpoint_url = 'adminURL'
+
+ def request(self, method, url, headers=None, body=None, wait=None):
+ """Overriding the existing HTTP request in super class rest_client."""
+ self._set_auth()
+ self.base_url = self.base_url.replace(urlparse(self.base_url).path,
+ "/v3")
+ return super(ServiceClientJSON, self).request(method, url,
+ headers=headers,
+ body=body)
+
+ def update_service(self, service_id, **kwargs):
+ """Updates a service."""
+ resp, body = self.get_service(service_id)
+ name = kwargs.get('name', body['name'])
+ type = kwargs.get('type', body['type'])
+ desc = kwargs.get('description', body['description'])
+ patch_body = {
+ 'description': desc,
+ 'type': type,
+ 'name': name
+ }
+ patch_body = json.dumps({'service': patch_body})
+ resp, body = self.patch('services/%s' % service_id,
+ patch_body, self.headers)
+ body = json.loads(body)
+ return resp, body['service']
+
+ def get_service(self, service_id):
+ """Get Service."""
+ url = 'services/%s' % service_id
+ resp, body = self.get(url)
+ body = json.loads(body)
+ return resp, body['service']
diff --git a/tempest/services/identity/v3/xml/service_client.py b/tempest/services/identity/v3/xml/service_client.py
new file mode 100644
index 0000000..306245b
--- /dev/null
+++ b/tempest/services/identity/v3/xml/service_client.py
@@ -0,0 +1,81 @@
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
+#
+# Copyright 2013 OpenStack Foundation
+# All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+from urlparse import urlparse
+
+from lxml import etree
+
+from tempest.common.rest_client import RestClientXML
+from tempest.services.compute.xml.common import Document
+from tempest.services.compute.xml.common import Element
+from tempest.services.compute.xml.common import xml_to_json
+
+
+XMLNS = "http://docs.openstack.org/identity/api/v3"
+
+
+class ServiceClientXML(RestClientXML):
+
+ def __init__(self, config, username, password, auth_url, tenant_name=None):
+ super(ServiceClientXML, self).__init__(config, username, password,
+ auth_url, tenant_name)
+ self.service = self.config.identity.catalog_type
+ self.endpoint_url = 'adminURL'
+
+ def _parse_array(self, node):
+ array = []
+ for child in node.getchildren():
+ array.append(xml_to_json(child))
+ return array
+
+ def _parse_body(self, body):
+ data = xml_to_json(body)
+ return data
+
+ def request(self, method, url, headers=None, body=None, wait=None):
+ """Overriding the existing HTTP request in super class rest_client."""
+ self._set_auth()
+ self.base_url = self.base_url.replace(urlparse(self.base_url).path,
+ "/v3")
+ return super(ServiceClientXML, self).request(method, url,
+ headers=headers,
+ body=body)
+
+ def update_service(self, service_id, **kwargs):
+ """Updates a service_id."""
+ resp, body = self.get_service(service_id)
+ name = kwargs.get('name', body['name'])
+ description = kwargs.get('description', body['description'])
+ type = kwargs.get('type', body['type'])
+ update_service = Element("service",
+ xmlns=XMLNS,
+ id=service_id,
+ name=name,
+ description=description,
+ type=type)
+ resp, body = self.patch('services/%s' % service_id,
+ str(Document(update_service)),
+ self.headers)
+ body = self._parse_body(etree.fromstring(body))
+ return resp, body
+
+ def get_service(self, service_id):
+ """Get Service."""
+ url = 'services/%s' % service_id
+ resp, body = self.get(url, self.headers)
+ body = self._parse_body(etree.fromstring(body))
+ return resp, body
diff --git a/tempest/tests/identity/admin/v3/test_services.py b/tempest/tests/identity/admin/v3/test_services.py
new file mode 100644
index 0000000..fef3bca
--- /dev/null
+++ b/tempest/tests/identity/admin/v3/test_services.py
@@ -0,0 +1,56 @@
+#vim: tabstop=4 shiftwidth=4 softtabstop=4
+
+# Copyright 2013 OpenStack Foundation
+# All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+
+from tempest.common.utils.data_utils import rand_name
+from tempest.tests.identity import base
+
+
+class ServicesTestJSON(base.BaseIdentityAdminTest):
+ _interface = 'json'
+
+ def test_update_service(self):
+ # Update description attribute of service
+ name = rand_name('service-')
+ type = rand_name('type--')
+ description = rand_name('description-')
+ resp, body = self.client.create_service(
+ name, type, description=description)
+ self.assertEqual('200', resp['status'])
+ #Deleting the service created in this method
+ self.addCleanup(self.client.delete_service, body['id'])
+
+ s_id = body['id']
+ resp1_desc = body['description']
+
+ s_desc2 = rand_name('desc2-')
+ resp, body = self.service_client.update_service(
+ s_id, description=s_desc2)
+ resp2_desc = body['description']
+ self.assertEqual('200', resp['status'])
+ self.assertNotEqual(resp1_desc, resp2_desc)
+
+ #Get service
+ resp, body = self.client.get_service(s_id)
+ resp3_desc = body['description']
+
+ self.assertNotEqual(resp1_desc, resp3_desc)
+ self.assertEqual(resp2_desc, resp3_desc)
+
+
+class ServicesTestXML(ServicesTestJSON):
+ _interface = 'xml'
diff --git a/tempest/tests/identity/base.py b/tempest/tests/identity/base.py
index 718b74f..6980425 100644
--- a/tempest/tests/identity/base.py
+++ b/tempest/tests/identity/base.py
@@ -30,6 +30,7 @@
cls.token_client = os.token_client
cls.endpoints_client = os.endpoints_client
cls.v3_client = os.identity_v3_client
+ cls.service_client = os.service_client
if not cls.client.has_admin_extensions():
raise cls.skipException("Admin extensions disabled")