From 1f2e722e0471b69d7adceeb373beef6c010a98c7 Mon Sep 17 00:00:00 2001 From: Chandan Kumar Date: Wed, 13 Dec 2017 15:14:10 +0530 Subject: [PATCH] Refactored blazar tempest plugin * In order to complete the tempest plugin split goal, we need to refactor the blazar tempest plugin so that we can easily consume. * use six.moves import range instead xrange to avoid flake8 error Change-Id: I88f2a961d770d6deebd9af567d6407e677c102ae --- blazar_tempest_plugin/README.rst | 5 ++ .../__init__.py | 0 .../config.py | 27 +---------- blazar_tempest_plugin/plugin.py | 47 +++++++++++++++++++ blazar_tempest_plugin/services/__init__.py | 0 .../services/reservation/__init__.py | 0 .../reservation/reservation_client.py | 7 +-- blazar_tempest_plugin/tests/__init__.py | 0 .../tests/scenario/__init__.py | 0 .../tests}/scenario/manager_freeze.py | 0 .../scenario/resource_reservation_scenario.py | 11 +++-- .../tests}/scenario/test_host_reservation.py | 7 ++- .../scenario/test_instance_reservation.py | 4 +- .../scenario/test_reservation_concurrency.py | 3 +- contrib/tempest/README.rst | 23 --------- contrib/tempest/tempest/cli/blazarclient.py | 25 ---------- .../test_resource_reservation.py | 45 ------------------ .../legacy/blazar-devstack-dsvm/run.yaml | 17 +------ setup.cfg | 4 ++ 19 files changed, 77 insertions(+), 148 deletions(-) create mode 100644 blazar_tempest_plugin/README.rst rename {contrib/tempest/tempest/cli/simple_read_only => blazar_tempest_plugin}/__init__.py (100%) rename contrib/tempest/tempest/config_resource_reservation.py => blazar_tempest_plugin/config.py (71%) create mode 100644 blazar_tempest_plugin/plugin.py create mode 100644 blazar_tempest_plugin/services/__init__.py create mode 100644 blazar_tempest_plugin/services/reservation/__init__.py rename contrib/tempest/tempest/resource_reservation_client_manager.py => blazar_tempest_plugin/services/reservation/reservation_client.py (93%) create mode 100644 blazar_tempest_plugin/tests/__init__.py create mode 100644 blazar_tempest_plugin/tests/scenario/__init__.py rename {contrib/tempest/tempest => blazar_tempest_plugin/tests}/scenario/manager_freeze.py (100%) rename {contrib/tempest/tempest => blazar_tempest_plugin/tests}/scenario/resource_reservation_scenario.py (94%) rename {contrib/tempest/tempest => blazar_tempest_plugin/tests}/scenario/test_host_reservation.py (98%) rename {contrib/tempest/tempest => blazar_tempest_plugin/tests}/scenario/test_instance_reservation.py (98%) rename {contrib/tempest/tempest => blazar_tempest_plugin/tests}/scenario/test_reservation_concurrency.py (94%) delete mode 100644 contrib/tempest/README.rst delete mode 100644 contrib/tempest/tempest/cli/blazarclient.py delete mode 100644 contrib/tempest/tempest/cli/simple_read_only/test_resource_reservation.py diff --git a/blazar_tempest_plugin/README.rst b/blazar_tempest_plugin/README.rst new file mode 100644 index 00000000..c5a039b3 --- /dev/null +++ b/blazar_tempest_plugin/README.rst @@ -0,0 +1,5 @@ +=============================================== +Tempest Integration of blazar +=============================================== + +This directory contains Tempest tests to cover the blazar project diff --git a/contrib/tempest/tempest/cli/simple_read_only/__init__.py b/blazar_tempest_plugin/__init__.py similarity index 100% rename from contrib/tempest/tempest/cli/simple_read_only/__init__.py rename to blazar_tempest_plugin/__init__.py diff --git a/contrib/tempest/tempest/config_resource_reservation.py b/blazar_tempest_plugin/config.py similarity index 71% rename from contrib/tempest/tempest/config_resource_reservation.py rename to blazar_tempest_plugin/config.py index 83c88b0b..671560f9 100644 --- a/contrib/tempest/tempest/config_resource_reservation.py +++ b/blazar_tempest_plugin/config.py @@ -14,13 +14,12 @@ # under the License. from oslo_config import cfg -from tempest import config service_available_group = cfg.OptGroup(name="service_available", title="Available OpenStack Services") -ServiceAvailableGroup = [ +service_option = [ cfg.BoolOpt("climate", default=True, help="Whether or not climate is expected to be available. " @@ -48,27 +47,3 @@ ResourceReservationGroup = [ default=300, help="Timeout in seconds to wait for a lease to finish.") ] - - -class TempestConfigPrivateBlazar(config.TempestConfigPrivate): - """Blazar's config wrap over standard config.""" - - def __init__(self, parse_conf=True): - config.register_opt_group(cfg.CONF, service_available_group, - ServiceAvailableGroup) - config.register_opt_group(cfg.CONF, resource_reservation_group, - ResourceReservationGroup) - self.resource_reservation = cfg.CONF.resource_reservation - - -class TempestBlazarLazyConfig(object): - _config = None - - def __getattr__(self, attr): - if not self._config: - self._config = TempestConfigPrivateBlazar() - - return getattr(self._config, attr) - - -CONF = TempestBlazarLazyConfig() diff --git a/blazar_tempest_plugin/plugin.py b/blazar_tempest_plugin/plugin.py new file mode 100644 index 00000000..42f798f6 --- /dev/null +++ b/blazar_tempest_plugin/plugin.py @@ -0,0 +1,47 @@ +# Copyright 2015 +# 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 blazar_tempest_plugin import config as blazar_config + + +class BlazarTempestPlugin(plugins.TempestPlugin): + def load_tests(self): + base_path = os.path.split(os.path.dirname( + os.path.abspath(__file__)))[0] + test_dir = "blazar_tempest_plugin/tests" + full_test_dir = os.path.join(base_path, test_dir) + return full_test_dir, base_path + + def register_opts(self, conf): + config.register_opt_group(conf, + blazar_config.service_available_group, + blazar_config.service_option) + config.register_opt_group(conf, + blazar_config.resource_reservation_group, + blazar_config.ResourceReservationGroup) + + def get_opt_lists(self): + return [ + (blazar_config.service_available_group.name, + blazar_config.service_option), + (blazar_config.resource_reservation_group.name, + blazar_config.ResourceReservationGroup) + ] diff --git a/blazar_tempest_plugin/services/__init__.py b/blazar_tempest_plugin/services/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/blazar_tempest_plugin/services/reservation/__init__.py b/blazar_tempest_plugin/services/reservation/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/contrib/tempest/tempest/resource_reservation_client_manager.py b/blazar_tempest_plugin/services/reservation/reservation_client.py similarity index 93% rename from contrib/tempest/tempest/resource_reservation_client_manager.py rename to blazar_tempest_plugin/services/reservation/reservation_client.py index 1d6a8638..4a9c2107 100644 --- a/contrib/tempest/tempest/resource_reservation_client_manager.py +++ b/blazar_tempest_plugin/services/reservation/reservation_client.py @@ -1,4 +1,4 @@ -# Copyright 2014 Intel Corporation +# Copyright 2017 NTT # All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); you may @@ -15,13 +15,8 @@ import json -from oslo_log import log as logging -from tempest import config_resource_reservation as config from tempest.lib.common import rest_client -CONF = config.CONF -LOG = logging.getLogger(__name__) - class ResourceReservationV1Client(rest_client.RestClient): """Client class for accessing the resource reservation API.""" diff --git a/blazar_tempest_plugin/tests/__init__.py b/blazar_tempest_plugin/tests/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/blazar_tempest_plugin/tests/scenario/__init__.py b/blazar_tempest_plugin/tests/scenario/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/contrib/tempest/tempest/scenario/manager_freeze.py b/blazar_tempest_plugin/tests/scenario/manager_freeze.py similarity index 100% rename from contrib/tempest/tempest/scenario/manager_freeze.py rename to blazar_tempest_plugin/tests/scenario/manager_freeze.py diff --git a/contrib/tempest/tempest/scenario/resource_reservation_scenario.py b/blazar_tempest_plugin/tests/scenario/resource_reservation_scenario.py similarity index 94% rename from contrib/tempest/tempest/scenario/resource_reservation_scenario.py rename to blazar_tempest_plugin/tests/scenario/resource_reservation_scenario.py index 0a503f62..aab5c1a9 100644 --- a/contrib/tempest/tempest/scenario/resource_reservation_scenario.py +++ b/blazar_tempest_plugin/tests/scenario/resource_reservation_scenario.py @@ -16,11 +16,13 @@ from oslo_log import log from tempest import clients as tempestclients -from tempest import config_resource_reservation as config +from tempest import config from tempest import exceptions from tempest.lib.common.utils import test_utils -from tempest import resource_reservation_client_manager as clients -from tempest.scenario import manager_freeze as manager + +from blazar_tempest_plugin.services.reservation import ( + reservation_client as clients) +from blazar_tempest_plugin.tests.scenario import manager_freeze as manager CONF = config.CONF @@ -37,7 +39,8 @@ class ResourceReservationScenarioTest(manager.ScenarioTest): super(ResourceReservationScenarioTest, cls).setup_clients() if not (CONF.service_available.climate or CONF.service_available.blazar): - raise cls.skipException("Resource reservation support is required") + raise cls.skipException("Resource reservation support is" + "required") cred_provider = cls._get_credentials_provider() creds = cred_provider.get_credentials('admin') diff --git a/contrib/tempest/tempest/scenario/test_host_reservation.py b/blazar_tempest_plugin/tests/scenario/test_host_reservation.py similarity index 98% rename from contrib/tempest/tempest/scenario/test_host_reservation.py rename to blazar_tempest_plugin/tests/scenario/test_host_reservation.py index 4eb4b8ef..2560df0a 100644 --- a/contrib/tempest/tempest/scenario/test_host_reservation.py +++ b/blazar_tempest_plugin/tests/scenario/test_host_reservation.py @@ -16,11 +16,14 @@ import datetime import time from oslo_log import log as logging +from six.moves import range from tempest.common import waiters from tempest import config from tempest.lib import decorators from tempest.lib import exceptions -from tempest.scenario import resource_reservation_scenario as rrs + +from blazar_tempest_plugin.tests.scenario import ( + resource_reservation_scenario as rrs) CONF = config.CONF @@ -144,7 +147,7 @@ class TestHostReservationScenario(rrs.ResourceReservationScenarioTest): return aggr def wait_until_aggregated(self, aggregate_name, host_name): - for i in xrange(self.MAX_RETRY): + for i in range(self.MAX_RETRY): try: aggr = self.fetch_aggregate_by_name(aggregate_name) self.assertTrue(host_name in aggr['hosts']) diff --git a/contrib/tempest/tempest/scenario/test_instance_reservation.py b/blazar_tempest_plugin/tests/scenario/test_instance_reservation.py similarity index 98% rename from contrib/tempest/tempest/scenario/test_instance_reservation.py rename to blazar_tempest_plugin/tests/scenario/test_instance_reservation.py index 17c26865..15b9a4c2 100644 --- a/contrib/tempest/tempest/scenario/test_instance_reservation.py +++ b/blazar_tempest_plugin/tests/scenario/test_instance_reservation.py @@ -22,9 +22,11 @@ from tempest.common import waiters from tempest import config from tempest import exceptions from tempest.lib import decorators -from tempest.scenario import resource_reservation_scenario as rrs from tempest import test +from blazar_tempest_plugin.tests.scenario import ( + resource_reservation_scenario as rrs) + CONF = config.CONF LOG = logging.getLogger(__name__) diff --git a/contrib/tempest/tempest/scenario/test_reservation_concurrency.py b/blazar_tempest_plugin/tests/scenario/test_reservation_concurrency.py similarity index 94% rename from contrib/tempest/tempest/scenario/test_reservation_concurrency.py rename to blazar_tempest_plugin/tests/scenario/test_reservation_concurrency.py index 136a877b..aa589306 100644 --- a/contrib/tempest/tempest/scenario/test_reservation_concurrency.py +++ b/blazar_tempest_plugin/tests/scenario/test_reservation_concurrency.py @@ -14,7 +14,8 @@ from multiprocessing.pool import ThreadPool -from tempest.scenario import resource_reservation_scenario as rrs +from blazar_tempest_plugin.tests.scenario import ( + resource_reservation_scenario as rrs) class TestReservationConcurrencyScenario(rrs.ResourceReservationScenarioTest): diff --git a/contrib/tempest/README.rst b/contrib/tempest/README.rst deleted file mode 100644 index 90ff0204..00000000 --- a/contrib/tempest/README.rst +++ /dev/null @@ -1,23 +0,0 @@ -This directory contains the files necessary for tempest to cover Blazar project. - -To install: - -$ TEMPEST_DIR=/path/to/tempest -$ BLAZAR_DIR=/path/to/blazar -$ cp -R ${BLAZAR_DIR}/contrib/tempest/tempest/* ${TEMPEST_DIR}/tempest/ - -For example: -$ cp -R /opt/stack/blazar/contrib/tempest/tempest/* /opt/stack/tempest/tempest/ - -To run all the blazar tests, add the following to the tox.ini file located at TEMPEST_DIR: - -[testenv:blazar] -sitepackages = True -commands = - bash tools/pretty_tox.sh '(^tempest\.(api|scenario|thirdparty|cli)\.test_.*reservation) {posargs}' - -Then, inside the TEMPEST_DIR, run: -$ tox -eblazar - -To debug tests with pdb or ipdb debuggers, run the following: -$ python -m testtools.run tempest."modules_to_your_test_file"."test_file_name"."your_test_suite_name" \ No newline at end of file diff --git a/contrib/tempest/tempest/cli/blazarclient.py b/contrib/tempest/tempest/cli/blazarclient.py deleted file mode 100644 index 5a89b682..00000000 --- a/contrib/tempest/tempest/cli/blazarclient.py +++ /dev/null @@ -1,25 +0,0 @@ -# Copyright 2014 Intel 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. - - -from tempest import cli - - -class ClientTestBase(cli.ClientTestBase): - - def blazar(self, action, flags='', params='', admin=True, fail_ok=False): - """Executes blazar command for the given action.""" - return self.cmd_with_auth( - 'blazar', action, flags, params, admin, fail_ok) diff --git a/contrib/tempest/tempest/cli/simple_read_only/test_resource_reservation.py b/contrib/tempest/tempest/cli/simple_read_only/test_resource_reservation.py deleted file mode 100644 index bb7f09b0..00000000 --- a/contrib/tempest/tempest/cli/simple_read_only/test_resource_reservation.py +++ /dev/null @@ -1,45 +0,0 @@ -# Copyright 2014 Intel 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. - -from tempest.cli import blazarclient -from tempest import config_resource_reservation as config - - -CONF = config.CONF - - -class SimpleReadOnlyBlazarClientTest(blazarclient.ClientTestBase): - """Basic, read-only tests for Blazar CLI client. - - Basic smoke test for the Blazar CLI commands which do not require - creating or modifying leases. - """ - - @classmethod - def setUpClass(cls): - if (not CONF.service_available.blazar): - msg = ("Skipping all Blazar cli tests because it is " - "not available") - raise cls.skipException(msg) - super(SimpleReadOnlyBlazarClientTest, cls).setUpClass() - - def test_blazar_lease_list(self): - self.blazar('lease-list') - - def test_blazar_host_list(self): - self.blazar('host-list') - - def test_blazar_version(self): - self.blazar('', flags='--version') diff --git a/playbooks/legacy/blazar-devstack-dsvm/run.yaml b/playbooks/legacy/blazar-devstack-dsvm/run.yaml index 416aa40f..5f237460 100644 --- a/playbooks/legacy/blazar-devstack-dsvm/run.yaml +++ b/playbooks/legacy/blazar-devstack-dsvm/run.yaml @@ -45,21 +45,8 @@ export PROJECTS="openstack/blazar $PROJECTS" export PROJECTS="openstack/blazar-nova $PROJECTS" export PROJECTS="openstack/python-blazarclient $PROJECTS" - # Construct a regex to limiting scope of tempest - r="^(?:tempest\.cli\.simple_read_only\.test_.*reservation.*)" - r="$r|^(?:tempest\.scenario\.test_.*reservation.*)" - export DEVSTACK_GATE_TEMPEST_REGEX="$r" - function pre_test_hook { - # Install blazar tempest integration - BLAZAR_TEMPEST_DIR=/opt/stack/new/blazar/contrib/tempest - # Copying Tempest test suites - # This will be removed once blazar tempest starts to use TempestPlugin - if [ -e $BLAZAR_TEMPEST_DIR ] ; then - TEMPEST_DIR=${TEMPEST_DIR:-/opt/stack/new/tempest} - cp -R $BLAZAR_TEMPEST_DIR/tempest/* $TEMPEST_DIR/tempest - fi - } - export -f pre_test_hook + export DEVSTACK_GATE_TEMPEST_ALL_PLUGINS=1 + export DEVSTACK_GATE_TEMPEST_REGEX="blazar_tempest_plugin.tests" cp devstack-gate/devstack-vm-gate-wrap.sh ./safe-devstack-vm-gate-wrap.sh ./safe-devstack-vm-gate-wrap.sh executable: /bin/bash diff --git a/setup.cfg b/setup.cfg index 9ff40204..203ac73a 100644 --- a/setup.cfg +++ b/setup.cfg @@ -24,6 +24,7 @@ setup-hooks = pbr.hooks.setup_hook [files] packages = blazar + blazar_tempest_plugin [entry_points] console_scripts = @@ -58,6 +59,9 @@ oslo.config.opts = wsgi_scripts = blazar-api-wsgi = blazar.api.wsgi_app:init_app +tempest.test_plugins = + blazar_tests = blazar_tempest_plugin.plugin:BlazarTempestPlugin + [build_sphinx] all_files = 1 build-dir = doc/build