From 25fb29e5c89acabf23b0df71130fdf738a2556a5 Mon Sep 17 00:00:00 2001 From: Kiall Mac Innes Date: Thu, 7 Apr 2016 08:07:04 +0100 Subject: [PATCH] Initial layout of Designate tempest plugin See https://review.openstack.org/283511 for history. Change-Id: I7733e8786d6b525a7c9a8d4f12add329cd030d9d Partially-Implements: blueprint designate-tempest-plugin --- .gitignore | 54 ++++++ LICENSE | 176 ++++++++++++++++++ README.rst | 28 +++ designate_tempest_plugin/__init__.py | 0 designate_tempest_plugin/clients.py | 37 ++++ designate_tempest_plugin/common/__init__.py | 0 designate_tempest_plugin/common/waiters.py | 83 +++++++++ designate_tempest_plugin/config.py | 34 ++++ designate_tempest_plugin/data_utils.py | 39 ++++ designate_tempest_plugin/plugin.py | 66 +++++++ designate_tempest_plugin/services/__init__.py | 0 .../services/dns/__init__.py | 0 .../services/dns/json/__init__.py | 0 .../services/dns/json/base.py | 119 ++++++++++++ .../services/dns/v2/__init__.py | 0 .../services/dns/v2/json/__init__.py | 0 .../services/dns/v2/json/base.py | 21 +++ .../services/dns/v2/json/zones_client.py | 74 ++++++++ designate_tempest_plugin/tests/__init__.py | 0 .../tests/api/__init__.py | 0 .../tests/api/v2/__init__.py | 0 designate_tempest_plugin/tests/api/v2/base.py | 31 +++ .../tests/api/v2/test_zones.py | 100 ++++++++++ .../tests/scenario/__init__.py | 0 requirements.txt | 5 + setup.cfg | 44 +++++ setup.py | 29 +++ test-requirements.txt | 6 + tools/pretty_flake8.py | 91 +++++++++ tools/pretty_flake8.sh | 6 + tools/pretty_tox.sh | 6 + tox.ini | 75 ++++++++ 32 files changed, 1124 insertions(+) create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 README.rst create mode 100644 designate_tempest_plugin/__init__.py create mode 100644 designate_tempest_plugin/clients.py create mode 100644 designate_tempest_plugin/common/__init__.py create mode 100644 designate_tempest_plugin/common/waiters.py create mode 100644 designate_tempest_plugin/config.py create mode 100644 designate_tempest_plugin/data_utils.py create mode 100644 designate_tempest_plugin/plugin.py create mode 100644 designate_tempest_plugin/services/__init__.py create mode 100644 designate_tempest_plugin/services/dns/__init__.py create mode 100644 designate_tempest_plugin/services/dns/json/__init__.py create mode 100644 designate_tempest_plugin/services/dns/json/base.py create mode 100644 designate_tempest_plugin/services/dns/v2/__init__.py create mode 100644 designate_tempest_plugin/services/dns/v2/json/__init__.py create mode 100644 designate_tempest_plugin/services/dns/v2/json/base.py create mode 100644 designate_tempest_plugin/services/dns/v2/json/zones_client.py create mode 100644 designate_tempest_plugin/tests/__init__.py create mode 100644 designate_tempest_plugin/tests/api/__init__.py create mode 100644 designate_tempest_plugin/tests/api/v2/__init__.py create mode 100644 designate_tempest_plugin/tests/api/v2/base.py create mode 100644 designate_tempest_plugin/tests/api/v2/test_zones.py create mode 100644 designate_tempest_plugin/tests/scenario/__init__.py create mode 100644 requirements.txt create mode 100644 setup.cfg create mode 100644 setup.py create mode 100644 test-requirements.txt create mode 100755 tools/pretty_flake8.py create mode 100755 tools/pretty_flake8.sh create mode 100755 tools/pretty_tox.sh create mode 100644 tox.ini diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..8ae2b422 --- /dev/null +++ b/.gitignore @@ -0,0 +1,54 @@ + +# Python related files + +*.dat +*.egg +*.egg-info +*.pyc +.eggs +TAGS +build + +# Test related files + +*.log +.coverage +.coverage.* +.testrepository/* +.tox +.venv +cover +flake8_results.html +functionaltests/.testrepository/ +functionaltests/tempest.log +htmlcov/ +venv + +# Files created by releasenotes build +releasenotes/build + +# Editors + +*.sublime-workspace +*.swp + +# Misc + +*.DS_Store +*.idea +*.ipynb +*.orig +*.sqlite +*.sqlite3 +/.ipynb_checkpoints/* +/bind9 +/dnsmasq +AUTHORS +ChangeLog +contrib/vagrant/.vagrant/ +designate/versioninfo +dist +doc/build/* +doc/source/api/* +etc/designate/*.conf +var/* diff --git a/LICENSE b/LICENSE new file mode 100644 index 00000000..68c771a0 --- /dev/null +++ b/LICENSE @@ -0,0 +1,176 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + diff --git a/README.rst b/README.rst new file mode 100644 index 00000000..87f4736c --- /dev/null +++ b/README.rst @@ -0,0 +1,28 @@ +================================ +Tempest Integration of Designate +================================ + +This directory contains Tempest tests to cover the designate project, as well +as a plugin to automatically load these tests into tempest. + +See the tempest plugin docs for information on using it: +http://docs.openstack.org/developer/tempest/plugin.html#using-plugins + +See the designate docs for information on writing new tests etc: +http://docs.openstack.org/developer/designate/tempest.html + +Running the tests +----------------- + +To run all tests from this plugin, install designate into your environment +and from the tempest repo, run:: + + $ tox -e all-plugin -- designate + +To run a single test case, run with the test case name, for example:: + + $ tox -e all-plugin -- designate_tempest_plugin.tests.api.v2.test_zones.ZonesAdminTest.test_get_other_tenant_zone + +To run all tempest tests including this plugin, run:: + + $ tox -e all-plugin diff --git a/designate_tempest_plugin/__init__.py b/designate_tempest_plugin/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/designate_tempest_plugin/clients.py b/designate_tempest_plugin/clients.py new file mode 100644 index 00000000..79d6cba3 --- /dev/null +++ b/designate_tempest_plugin/clients.py @@ -0,0 +1,37 @@ +# Copyright 2016 Hewlett Packard Enterprise Development Company, L.P. +# +# 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 import clients +from tempest import config + +from designate_tempest_plugin.services.dns.v2.json.zones_client import \ + ZonesClient + + +CONF = config.CONF + + +class Manager(clients.Manager): + def __init__(self, credentials=None, service=None): + super(Manager, self).__init__(credentials, service) + + params = { + 'service': CONF.dns.catalog_type, + 'region': CONF.identity.region, + 'endpoint_type': CONF.dns.endpoint_type, + 'build_interval': CONF.dns.build_interval, + 'build_timeout': CONF.dns.build_timeout + } + params.update(self.default_params) + + self.zones_client = ZonesClient(self.auth_provider, **params) diff --git a/designate_tempest_plugin/common/__init__.py b/designate_tempest_plugin/common/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/designate_tempest_plugin/common/waiters.py b/designate_tempest_plugin/common/waiters.py new file mode 100644 index 00000000..a75870b2 --- /dev/null +++ b/designate_tempest_plugin/common/waiters.py @@ -0,0 +1,83 @@ +# Copyright 2016 Hewlett Packard Enterprise Development Company, L.P. +# +# 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 time + +from oslo_log import log as logging +from tempest.lib.common.utils import misc as misc_utils +from tempest.lib import exceptions as lib_exc + +LOG = logging.getLogger(__name__) + + +def wait_for_zone_404(client, zone_id): + """Waits for a zone to 404.""" + LOG.info('Waiting for zone %s to 404', zone_id) + start = int(time.time()) + + while True: + time.sleep(client.build_interval) + + try: + _, zone = client.show_zone(zone_id) + except lib_exc.NotFound: + LOG.info('Zone %s is 404ing', zone_id) + return + + if int(time.time()) - start >= client.build_timeout: + message = ('Zone %(zone_id)s failed to 404 within the required ' + 'time (%(timeout)s s). Current status: ' + '%(status_curr)s' % + {'zone_id': zone_id, + 'status_curr': zone['status'], + 'timeout': client.build_timeout}) + + caller = misc_utils.find_test_caller() + + if caller: + message = '(%s) %s' % (caller, message) + + raise lib_exc.TimeoutException(message) + + +def wait_for_zone_status(client, zone_id, status): + """Waits for a zone to reach given status.""" + LOG.info('Waiting for zone %s to reach %s', zone_id, status) + + _, zone = client.show_zone(zone_id) + start = int(time.time()) + + while zone['status'] != status: + time.sleep(client.build_interval) + _, zone = client.show_zone(zone_id) + status_curr = zone['status'] + if status_curr == status: + LOG.info('Zone %s reached %s', zone_id, status) + return + + if int(time.time()) - start >= client.build_timeout: + message = ('Zone %(zone_id)s failed to reach status=%(status)s ' + 'within the required time (%(timeout)s s). Current ' + 'status: %(status_curr)s' % + {'zone_id': zone_id, + 'status': status, + 'status_curr': status_curr, + 'timeout': client.build_timeout}) + + caller = misc_utils.find_test_caller() + + if caller: + message = '(%s) %s' % (caller, message) + + raise lib_exc.TimeoutException(message) diff --git a/designate_tempest_plugin/config.py b/designate_tempest_plugin/config.py new file mode 100644 index 00000000..40941499 --- /dev/null +++ b/designate_tempest_plugin/config.py @@ -0,0 +1,34 @@ +# Copyright 2016 Hewlett Packard Enterprise Development Company, L.P. +# +# 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 oslo_config import cfg + +dns_group = cfg.OptGroup(name='dns', + title='DNS service options') + +DnsGroup = [ + cfg.StrOpt('endpoint_type', + default='publicURL', + choices=['public', 'admin', 'internal', + 'publicURL', 'adminURL', 'internalURL'], + help="The endpoint type to use for the DNS service"), + cfg.StrOpt('catalog_type', + default='dns', + help="Catalog type of the DNS service"), + cfg.IntOpt('build_interval', + default=1, + help="Time in seconds between build status checks."), + cfg.IntOpt('build_timeout', + default=60, + help="Timeout in seconds to wait for an resource to build."), +] diff --git a/designate_tempest_plugin/data_utils.py b/designate_tempest_plugin/data_utils.py new file mode 100644 index 00000000..73207d57 --- /dev/null +++ b/designate_tempest_plugin/data_utils.py @@ -0,0 +1,39 @@ +# Copyright 2016 Hewlett Packard Enterprise Development Company, L.P. +# +# 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.lib.common.utils import data_utils + + +def rand_zone_name(): + """Generate a random zone name + :return: a random zone name e.g. example.org. + :rtype: string + """ + return '%s.com.' % data_utils.rand_name() + + +def rand_email(domain=None): + """Generate a random zone name + :return: a random zone name e.g. example.org. + :rtype: string + """ + domain = domain or rand_zone_name() + return 'example@%s' % domain.rstrip('.') + + +def rand_ttl(start=1, end=86400): + """Generate a random TTL value + :return: a random ttl e.g. 165 + :rtype: string + """ + return data_utils.rand_int_id(start, end) diff --git a/designate_tempest_plugin/plugin.py b/designate_tempest_plugin/plugin.py new file mode 100644 index 00000000..20f19c16 --- /dev/null +++ b/designate_tempest_plugin/plugin.py @@ -0,0 +1,66 @@ +# Copyright 2016 NEC Corporation. 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 os + +from tempest import config +from tempest.test_discover import plugins + +from designate_tempest_plugin import config as project_config + + +class DesignateTempestPlugin(plugins.TempestPlugin): + """ + A DesignateTempestPlugin class provides the basic hooks for an external + plugin to provide tempest the necessary information to run the plugin. + """ + def load_tests(self): + """ + Method to return the information necessary to load the tests in the + plugin. + + :return: a tuple with the first value being the test_dir and the second + being the top_level + :return type: tuple + """ + base_path = os.path.split(os.path.dirname( + os.path.abspath(__file__)))[0] + test_dir = "designate_tempest_plugin/tests" + full_test_dir = os.path.join(base_path, test_dir) + return full_test_dir, base_path + + def register_opts(self, conf): + """ + Add additional configuration options to tempest. + + This method will be run for the plugin during the register_opts() + function in tempest.config + + Parameters: + conf (ConfigOpts): The conf object that can be used to register + additional options on. + """ + config.register_opt_group(conf, project_config.dns_group, + project_config.DnsGroup) + + def get_opt_lists(self): + """ + Get a list of options for sample config generation + + Return option_list: A list of tuples with the group name + and options in that group. + Return type: list + """ + return [(project_config.dns_group.name, + project_config.DnsGroup)] diff --git a/designate_tempest_plugin/services/__init__.py b/designate_tempest_plugin/services/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/designate_tempest_plugin/services/dns/__init__.py b/designate_tempest_plugin/services/dns/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/designate_tempest_plugin/services/dns/json/__init__.py b/designate_tempest_plugin/services/dns/json/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/designate_tempest_plugin/services/dns/json/base.py b/designate_tempest_plugin/services/dns/json/base.py new file mode 100644 index 00000000..f2574d6e --- /dev/null +++ b/designate_tempest_plugin/services/dns/json/base.py @@ -0,0 +1,119 @@ +# Copyright 2016 Hewlett Packard Enterprise Development Company, L.P. +# +# 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 functools + +from oslo_log import log as logging +from oslo_serialization import jsonutils as json +from tempest.lib.common import rest_client +from six.moves.urllib import parse as urllib + + +LOG = logging.getLogger(__name__) + + +def handle_errors(f): + """A decorator that allows to ignore certain types of errors.""" + + @functools.wraps(f) + def wrapper(*args, **kwargs): + param_name = 'ignore_errors' + ignored_errors = kwargs.get(param_name, tuple()) + + if param_name in kwargs: + del kwargs[param_name] + + try: + return f(*args, **kwargs) + except ignored_errors as e: + # Silently ignore errors as requested + LOG.debug('Ignoring exception of type %s, as requested', type(e)) + + return wrapper + + +class DnsClientBase(rest_client.RestClient): + """Base Tempest REST client for Designate API""" + + uri_prefix = '' + + def serialize(self, object_dict): + return json.dumps(object_dict) + + def deserialize(self, object_str): + return json.loads(object_str) + + def _get_uri(self, resource_name, uuid=None, params=None): + """Get URI for a specific resource or object. + :param resource_name: The name of the REST resource, e.g., 'zones'. + :param uuid: The unique identifier of an object in UUID format. + :param params: A Python dict that represents the query paramaters to + include in the request URI. + :returns: Relative URI for the resource or object. + """ + uri_pattern = '{pref}/{res}{uuid}{params}' + + uuid = '/%s' % uuid if uuid else '' + params = '?%s' % urllib.urlencode(params) if params else '' + + return uri_pattern.format(pref=self.uri_prefix, + res=resource_name, + uuid=uuid, + params=params) + + def _create_request(self, resource, object_dict, params=None): + """Create an object of the specified type. + :param resource: The name of the REST resource, e.g., 'zones'. + :param object_dict: A Python dict that represents an object of the + specified type. + :param params: A Python dict that represents the query paramaters to + include in the request URI. + :returns: A tuple with the server response and the deserialized created + object. + """ + body = self.serialize(object_dict) + uri = self._get_uri(resource, params=params) + + resp, body = self.post(uri, body=body) + self.expected_success([201, 202], resp['status']) + + return resp, self.deserialize(body) + + def _show_request(self, resource, uuid, params=None): + """Gets a specific object of the specified type. + :param uuid: Unique identifier of the object in UUID format. + :param params: A Python dict that represents the query paramaters to + include in the request URI. + :returns: Serialized object as a dictionary. + """ + uri = self._get_uri(resource, uuid=uuid, params=params) + + resp, body = self.get(uri) + + self.expected_success(200, resp['status']) + + return resp, self.deserialize(body) + + def _delete_request(self, resource, uuid, params=None): + """Delete specified object. + :param resource: The name of the REST resource, e.g., 'zones'. + :param uuid: The unique identifier of an object in UUID format. + :param params: A Python dict that represents the query paramaters to + include in the request URI. + :returns: A tuple with the server response and the response body. + """ + uri = self._get_uri(resource, uuid=uuid, params=params) + + resp, body = self.delete(uri) + self.expected_success([202, 204], resp['status']) + return resp, self.deserialize(body) diff --git a/designate_tempest_plugin/services/dns/v2/__init__.py b/designate_tempest_plugin/services/dns/v2/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/designate_tempest_plugin/services/dns/v2/json/__init__.py b/designate_tempest_plugin/services/dns/v2/json/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/designate_tempest_plugin/services/dns/v2/json/base.py b/designate_tempest_plugin/services/dns/v2/json/base.py new file mode 100644 index 00000000..a679fd61 --- /dev/null +++ b/designate_tempest_plugin/services/dns/v2/json/base.py @@ -0,0 +1,21 @@ +# Copyright 2016 Hewlett Packard Enterprise Development Company, L.P. +# +# 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 designate_tempest_plugin.services.dns.json import base + +handle_errors = base.handle_errors + + +class DnsClientV2Base(base.DnsClientBase): + """Base API V2 Tempest REST client for Designate API""" + uri_prefix = 'v2' diff --git a/designate_tempest_plugin/services/dns/v2/json/zones_client.py b/designate_tempest_plugin/services/dns/v2/json/zones_client.py new file mode 100644 index 00000000..6f5cb95e --- /dev/null +++ b/designate_tempest_plugin/services/dns/v2/json/zones_client.py @@ -0,0 +1,74 @@ +# Copyright 2016 Hewlett Packard Enterprise Development Company, L.P. +# +# 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.lib.common.utils import data_utils + +from designate_tempest_plugin import data_utils as dns_data_utils +from designate_tempest_plugin.common import waiters +from designate_tempest_plugin.services.dns.v2.json import base + + +class ZonesClient(base.DnsClientV2Base): + """API V2 Tempest REST client for Designate API""" + + @base.handle_errors + def create_zone(self, name=None, email=None, ttl=None, description=None, + wait_until=False, params=None): + """Create a zone with the specified parameters. + + :param name: The name of the zone. + Default: Random Value + :param email: The email for the zone. + Default: Random Value + :param ttl: The ttl for the zone. + Default: Random Value + :param description: A description of the zone. + Default: Random Value + :param wait_until: Block until the zone reaches the desiered status + :param params: A Python dict that represents the query paramaters to + include in the request URI. + :return: A tuple with the server response and the created zone. + """ + zone = { + 'name': name or dns_data_utils.rand_zone_name(), + 'email': email or dns_data_utils.rand_email(), + 'ttl': ttl or dns_data_utils.rand_ttl(), + 'description': description or data_utils.rand_name('test-zone'), + } + + resp, body = self._create_request('zones', zone, params=params) + + if wait_until: + waiters.wait_for_zone_status(self, body['id'], wait_until) + + return resp, body + + @base.handle_errors + def show_zone(self, uuid, params=None): + """Gets a specific zone. + :param uuid: Unique identifier of the zone in UUID format. + :param params: A Python dict that represents the query paramaters to + include in the request URI. + :return: Serialized zone as a dictionary. + """ + return self._show_request('zones', uuid, params=params) + + @base.handle_errors + def delete_zone(self, uuid, params=None): + """Deletes a zone having the specified UUID. + :param uuid: The unique identifier of the zone. + :param params: A Python dict that represents the query paramaters to + include in the request URI. + :return: A tuple with the server response and the response body. + """ + return self._delete_request('zones', uuid, params=params) diff --git a/designate_tempest_plugin/tests/__init__.py b/designate_tempest_plugin/tests/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/designate_tempest_plugin/tests/api/__init__.py b/designate_tempest_plugin/tests/api/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/designate_tempest_plugin/tests/api/v2/__init__.py b/designate_tempest_plugin/tests/api/v2/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/designate_tempest_plugin/tests/api/v2/base.py b/designate_tempest_plugin/tests/api/v2/base.py new file mode 100644 index 00000000..d05d9d09 --- /dev/null +++ b/designate_tempest_plugin/tests/api/v2/base.py @@ -0,0 +1,31 @@ +# Copyright 2016 Hewlett Packard Enterprise Development Company, L.P. +# +# 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 import test + +from designate_tempest_plugin import clients + + +class BaseDnsTest(test.BaseTestCase): + """Base class for DNS API v2 tests.""" + + # Use the Designate Client Manager + client_manager = clients.Manager + + # NOTE(andreaf) credentials holds a list of the credentials to be allocated + # at class setup time. Credential types can be 'primary', 'alt', 'admin' or + # a list of roles - the first element of the list being a label, and the + # rest the actual roles. + # NOTE(kiall) primary will result in a manager @ cls.os, alt will have + # cls.os_alt, and admin will have cls.os_adm. + credentials = ['primary'] diff --git a/designate_tempest_plugin/tests/api/v2/test_zones.py b/designate_tempest_plugin/tests/api/v2/test_zones.py new file mode 100644 index 00000000..345ff60a --- /dev/null +++ b/designate_tempest_plugin/tests/api/v2/test_zones.py @@ -0,0 +1,100 @@ +# Copyright 2016 Hewlett Packard Enterprise Development Company, L.P. +# +# 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 six +from oslo_log import log as logging +from tempest import test +from tempest.lib import exceptions as lib_exc + +from designate_tempest_plugin.tests.api.v2 import base +from designate_tempest_plugin.common import waiters + +LOG = logging.getLogger(__name__) + + +class BaseZonesTest(base.BaseDnsTest): + def _assertExpected(self, expected, actual): + for key, value in six.iteritems(expected): + if key not in ('created_at', 'updated_at', 'version', 'links', + 'status', 'action'): + self.assertIn(key, actual) + self.assertEqual(value, actual[key], key) + + +class ZonesTest(BaseZonesTest): + @classmethod + def setup_clients(cls): + super(ZonesTest, cls).setup_clients() + + cls.client = cls.os.zones_client + + @test.attr(type='smoke') + @test.idempotent_id('9d2e20fc-e56f-4a62-9c61-9752a9ec615c') + def test_create_zone(self): + LOG.info('Create a zone') + _, zone = self.client.create_zone() + self.addCleanup(self.client.delete_zone, zone['id']) + + LOG.info('Ensure we respond with CREATE+PENDING') + self.assertEqual('CREATE', zone['action']) + self.assertEqual('PENDING', zone['status']) + + waiters.wait_for_zone_status( + self.client, zone['id'], 'ACTIVE') + + LOG.info('Re-Fetch the zone') + _, body = self.client.show_zone(zone['id']) + + LOG.info('Ensure the fetched response matches the created zone') + self._assertExpected(zone, body) + + @test.attr(type='smoke') + @test.idempotent_id('a4791906-6cd6-4d27-9f15-32273db8bb3d') + def test_delete_zone(self): + LOG.info('Create a zone') + _, zone = self.client.create_zone(wait_until='ACTIVE') + self.addCleanup(self.client.delete_zone, zone['id'], + ignore_errors=lib_exc.NotFound) + + LOG.info('Delete the zone') + _, body = self.client.delete_zone(zone['id']) + + LOG.info('Ensure we respond with DELETE+PENDING') + self.assertEqual('DELETE', body['action']) + self.assertEqual('PENDING', body['status']) + + waiters.wait_for_zone_404(self.client, zone['id']) + + +class ZonesAdminTest(BaseZonesTest): + credentials = ['primary', 'admin'] + + @classmethod + def setup_clients(cls): + super(ZonesAdminTest, cls).setup_clients() + + cls.client = cls.os.zones_client + cls.admin_client = cls.os_adm.zones_client + + @test.idempotent_id('6477f92d-70ba-46eb-bd6c-fc50c405e222') + def test_get_other_tenant_zone(self): + LOG.info('Create a zone as a user') + _, zone = self.client.create_zone() + self.addCleanup(self.client.delete_zone, zone['id']) + + LOG.info('Fetch the zone as an admin') + _, body = self.admin_client.show_zone( + zone['id'], params={'all_projects': True}) + + LOG.info('Ensure the fetched response matches the created zone') + self._assertExpected(zone, body) diff --git a/designate_tempest_plugin/tests/scenario/__init__.py b/designate_tempest_plugin/tests/scenario/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 00000000..090a185a --- /dev/null +++ b/requirements.txt @@ -0,0 +1,5 @@ +# The order of packages is significant, because pip processes them in the order +# of appearance. Changing the order has an impact on the overall integration +# process, which may cause wedges in the gate later. + +tempest>=10.0.0 # Apache-2.0 diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 00000000..6960fa29 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,44 @@ +[metadata] +name = designate-tempest-plugin +summary = OpenStack DNS As A Service (Designate) Functional Tests +description-file = + README.rst +author = OpenStack +author-email = openstack-dev@lists.openstack.org +home-page = http://docs.openstack.org/developer/designate/ +classifier = + Environment :: OpenStack + Environment :: No Input/Output (Daemon) + Intended Audience :: Information Technology + Intended Audience :: System Administrators + License :: OSI Approved :: Apache Software License + Operating System :: POSIX :: Linux + Programming Language :: Python + Programming Language :: Python :: 2 + Programming Language :: Python :: 2.7 + Topic :: Internet :: Name Service (DNS) + +[global] +setup-hooks = + pbr.hooks.setup_hook + +[files] +packages = + designate_tempest_plugin + +[entry_points] +tempest.test_plugins = + designate = designate_tempest_plugin.plugin:DesignateTempestPlugin + +[build_sphinx] +all_files = 1 +build-dir = doc/build +source-dir = doc/source + +[egg_info] +tag_build = +tag_date = 0 +tag_svn_revision = 0 + +[wheel] +universal = 1 diff --git a/setup.py b/setup.py new file mode 100644 index 00000000..782bb21f --- /dev/null +++ b/setup.py @@ -0,0 +1,29 @@ +# Copyright (c) 2013 Hewlett-Packard Development Company, L.P. +# +# 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. + +# THIS FILE IS MANAGED BY THE GLOBAL REQUIREMENTS REPO - DO NOT EDIT +import setuptools + +# In python < 2.7.4, a lazy loading of package `pbr` will break +# setuptools if some other modules registered functions in `atexit`. +# solution from: http://bugs.python.org/issue15881#msg170215 +try: + import multiprocessing # noqa +except ImportError: + pass + +setuptools.setup( + setup_requires=['pbr>=1.8'], + pbr=True) diff --git a/test-requirements.txt b/test-requirements.txt new file mode 100644 index 00000000..57b09996 --- /dev/null +++ b/test-requirements.txt @@ -0,0 +1,6 @@ +# The order of packages is significant, because pip processes them in the order +# of appearance. Changing the order has an impact on the overall integration +# process, which may cause wedges in the gate later. + +# Hacking already pins down pep8, pyflakes and flake8 +hacking<0.10,>=0.9.2 diff --git a/tools/pretty_flake8.py b/tools/pretty_flake8.py new file mode 100755 index 00000000..2688cccf --- /dev/null +++ b/tools/pretty_flake8.py @@ -0,0 +1,91 @@ +# Copyright 2015 Hewlett-Packard Development Company, L.P. +# +# 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 __future__ import print_function + +import re +import sys +import linecache + +from prettytable import PrettyTable + +PEP8_LINE = r'^((?P.*):(?P\d*):(?P\d*):) ' \ + '(?P(?P\w\d{1,3})(?P.*$))' + +HTML = True + + +def main(): + + raw_errors = [] + + max_filename_len = 0 + for line in sys.stdin: + m = re.match(PEP8_LINE, line) + if m: + m = m.groupdict() + raw_errors.append(m) + if len(m['file']) > max_filename_len: + max_filename_len = len(m['file']) + else: + print(line) + + if len(raw_errors) > 0: + + print('Flake8 Results') + + ct = PrettyTable([ + "File", + "Line", + "Column", + "Error Code", + "Error Message", + "Code" + ]) + + ct.align["File"] = "l" + ct.align["Error Message"] = "l" + ct.align["Code"] = "l" + + for line in raw_errors: + ct.add_row(format_dict(line)) + + print(ct) + + with open('flake8_results.html', 'w') as f: + f.write('%s' % ct.get_html_string(attributes = {"cellspacing": 0})) # noqa + + +def format_dict(raw): + output = [] + if raw['file'].startswith('./'): + output.append(raw['file'][2:]) + else: + output.append(raw['file']) + + output.append(raw['line']) + output.append(raw['col']) + output.append(raw['error_code']) + + output.append(raw['error_desc'].lstrip()) + + code_string = linecache.getline( + output[0], + int(raw['line'])).lstrip().rstrip() + + output.append(code_string) + + return output + +if __name__ == '__main__': + main() diff --git a/tools/pretty_flake8.sh b/tools/pretty_flake8.sh new file mode 100755 index 00000000..b552383a --- /dev/null +++ b/tools/pretty_flake8.sh @@ -0,0 +1,6 @@ +#!/bin/sh + +TESTARGS=$1 + +exec 3>&1 +status=$(exec 4>&1 >&3; ( flake8 ; echo $? >&4 ) | python tools/pretty_flake8.py) && exit $status diff --git a/tools/pretty_tox.sh b/tools/pretty_tox.sh new file mode 100755 index 00000000..0fc36053 --- /dev/null +++ b/tools/pretty_tox.sh @@ -0,0 +1,6 @@ +#! /bin/sh + +TESTRARGS=$1 + +exec 3>&1 +status=$(exec 4>&1 >&3; ( python setup.py testr --slowest --testr-args="--subunit $TESTRARGS"; echo $? >&4 ) | subunit-trace -f) && exit $status diff --git a/tox.ini b/tox.ini new file mode 100644 index 00000000..cdbccbb1 --- /dev/null +++ b/tox.ini @@ -0,0 +1,75 @@ +[tox] +minversion = 1.6 +envlist = py34,py27,flake8 +skipsdist = True + +[testenv] +usedevelop = True +install_command = pip install {opts} {packages} +deps = -r{toxinidir}/requirements.txt + -r{toxinidir}/test-requirements.txt +setenv = + PYTHONDONTWRITEBYTECODE=1 +whitelist_externals = sh + find + rm +commands = + find . -type f -name "*.pyc" -delete + sh tools/pretty_tox.sh '{posargs}' +passenv = http_proxy + HTTP_PROXY + https_proxy + HTTPS_PROXY + no_proxy + NO_PROXY + OS_DEBUG + OS_LOG_CAPTURE + OS_STDERR_CAPTURE + OS_STDOUT_CAPTURE + +[testenv:pep8] +basepython = python2.7 +commands = sh tools/pretty_flake8.sh + +[testenv:bashate] +deps = bashate +whitelist_externals = bash +commands = bash -c "find {toxinidir}/devstack \ + -not \( -type d -name .?\* -prune \) \ + -not \( -type d -name doc -prune \) \ + -type f \ + -not -name \*~ \ + -not -name \*.md \ + \( \ + -name \*.sh -or \ + -name \*rc -or \ + -name functions\* -or \ + -wholename \*/lib/\* \ + \) \ + -print0 | xargs -0 bashate -v" + +[testenv:pip-check-reqs] +# do not install test-requirements as that will pollute the virtualenv for +# determining missing packages +# this also means that pip-missing-reqs must be installed separately, outside +# of the requirements.txt files +deps = pip-check-reqs + -r{toxinidir}/requirements.txt +commands=pip-missing-reqs -d --ignore-file=designate/tests/* designate + +[testenv:venv] +commands = {posargs} + +[flake8] +# ignored flake8 codes: +# H302 import only modules +# H306 imports not in alphabetical order +# H402 one line docstring needs punctuation +# H404 multi line docstring should start with a summary +# H405 multi line docstring summary not separated with an empty line +# H904 Wrap long lines in parentheses instead of a backslash +# E126 continuation line over-indented for hanging indent +# E128 continuation line under-indented for visual indent + +ignore = H302,H306,H402,H404,H405,H904,E126,E128 +exclude = .venv,.git,.tox,dist,doc,*openstack/common*,*openstack/deprecated*,*lib/python*,*egg,build,tools,.ropeproject