From d57f3cf582d9c6310b85dddea428c1a39e441cd8 Mon Sep 17 00:00:00 2001 From: ivan-zhu Date: Wed, 6 Nov 2013 16:59:52 +0800 Subject: [PATCH] add tests for certificates this adds both positive and negative tests for create and show certificate Change-Id: I6486838e7cfad322980f95e6ae80ff8947d14b95 --- tempest/api/compute/base.py | 1 + tempest/api/compute/certificates/__init__.py | 0 .../compute/certificates/test_certificates.py | 40 ++++++++++++++++++ tempest/clients.py | 6 +++ .../compute/json/certificates_client.py | 42 +++++++++++++++++++ .../compute/xml/certificates_client.py | 40 ++++++++++++++++++ 6 files changed, 129 insertions(+) create mode 100644 tempest/api/compute/certificates/__init__.py create mode 100644 tempest/api/compute/certificates/test_certificates.py create mode 100644 tempest/services/compute/json/certificates_client.py create mode 100644 tempest/services/compute/xml/certificates_client.py diff --git a/tempest/api/compute/base.py b/tempest/api/compute/base.py index 5679a45d87..9bf897edc7 100644 --- a/tempest/api/compute/base.py +++ b/tempest/api/compute/base.py @@ -190,6 +190,7 @@ class BaseV2ComputeTest(BaseComputeTest): cls.services_client = cls.os.services_client cls.hypervisor_client = cls.os.hypervisor_client cls.servers_client_v3_auth = cls.os.servers_client_v3_auth + cls.certificates_client = cls.os.certificates_client class BaseV2ComputeAdminTest(BaseV2ComputeTest): diff --git a/tempest/api/compute/certificates/__init__.py b/tempest/api/compute/certificates/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tempest/api/compute/certificates/test_certificates.py b/tempest/api/compute/certificates/test_certificates.py new file mode 100644 index 0000000000..4be1cffb66 --- /dev/null +++ b/tempest/api/compute/certificates/test_certificates.py @@ -0,0 +1,40 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# Copyright 2012 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.api.compute import base +from tempest.test import attr + + +class CertificatesTestJSON(base.BaseV2ComputeTest): + _interface = 'json' + + @attr(type='gate') + def test_create_and_get_root_certificate(self): + # create certificates + resp, create_body = self.certificates_client.create_certificate() + self.assertEqual(200, resp.status) + self.assertIn('data', create_body) + self.assertIn('private_key', create_body) + # get the root certificate + resp, body = self.certificates_client.get_certificate('root') + self.assertEqual(200, resp.status) + self.assertIn('data', body) + self.assertIn('private_key', body) + + +class CertificatesTestXML(CertificatesTestJSON): + _interface = 'xml' diff --git a/tempest/clients.py b/tempest/clients.py index dd104a7368..97afd9ae23 100644 --- a/tempest/clients.py +++ b/tempest/clients.py @@ -23,6 +23,8 @@ from tempest.services.compute.json.aggregates_client import \ AggregatesClientJSON from tempest.services.compute.json.availability_zone_client import \ AvailabilityZoneClientJSON +from tempest.services.compute.json.certificates_client import \ + CertificatesClientJSON from tempest.services.compute.json.extensions_client import \ ExtensionsClientJSON from tempest.services.compute.json.fixed_ips_client import FixedIPsClientJSON @@ -49,6 +51,8 @@ from tempest.services.compute.json.volumes_extensions_client import \ from tempest.services.compute.xml.aggregates_client import AggregatesClientXML from tempest.services.compute.xml.availability_zone_client import \ AvailabilityZoneClientXML +from tempest.services.compute.xml.certificates_client import \ + CertificatesClientXML from tempest.services.compute.xml.extensions_client import ExtensionsClientXML from tempest.services.compute.xml.fixed_ips_client import FixedIPsClientXML from tempest.services.compute.xml.flavors_client import FlavorsClientXML @@ -166,6 +170,7 @@ class Manager(object): self.servers_client_v3_auth = None if interface == 'xml': + self.certificates_client = CertificatesClientXML(*client_args) self.servers_client = ServersClientXML(*client_args) self.limits_client = LimitsClientXML(*client_args) self.images_client = ImagesClientXML(*client_args) @@ -204,6 +209,7 @@ class Manager(object): *client_args_v3_auth) elif interface == 'json': + self.certificates_client = CertificatesClientJSON(*client_args) self.servers_client = ServersClientJSON(*client_args) self.limits_client = LimitsClientJSON(*client_args) self.images_client = ImagesClientJSON(*client_args) diff --git a/tempest/services/compute/json/certificates_client.py b/tempest/services/compute/json/certificates_client.py new file mode 100644 index 0000000000..9fdce176fc --- /dev/null +++ b/tempest/services/compute/json/certificates_client.py @@ -0,0 +1,42 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# Copyright 2013 IBM Corp +# 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 tempest.common.rest_client import RestClient + + +class CertificatesClientJSON(RestClient): + + def __init__(self, config, username, password, auth_url, tenant_name=None): + super(CertificatesClientJSON, self).__init__(config, username, + password, + auth_url, tenant_name) + self.service = self.config.compute.catalog_type + + def get_certificate(self, id): + url = "os-certificates/%s" % (id) + resp, body = self.get(url) + body = json.loads(body) + return resp, body['certificate'] + + def create_certificate(self): + """create certificates.""" + url = "os-certificates" + resp, body = self.post(url, None, self.headers) + body = json.loads(body) + return resp, body['certificate'] diff --git a/tempest/services/compute/xml/certificates_client.py b/tempest/services/compute/xml/certificates_client.py new file mode 100644 index 0000000000..752335220d --- /dev/null +++ b/tempest/services/compute/xml/certificates_client.py @@ -0,0 +1,40 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# Copyright 2013 IBM Corp +# 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.rest_client import RestClientXML + + +class CertificatesClientXML(RestClientXML): + + def __init__(self, config, username, password, auth_url, tenant_name=None): + super(CertificatesClientXML, self).__init__(config, username, password, + auth_url, tenant_name) + self.service = self.config.compute.catalog_type + + def get_certificate(self, id): + url = "os-certificates/%s" % (id) + resp, body = self.get(url, self.headers) + body = self._parse_resp(body) + return resp, body + + def create_certificate(self): + """create certificates.""" + url = "os-certificates" + resp, body = self.post(url, None, self.headers) + body = self._parse_resp(body) + return resp, body