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
This commit is contained in:
Chandan Kumar 2017-12-13 15:14:10 +05:30 committed by Masahito Muroi
parent 4e83dde906
commit 1f2e722e04
19 changed files with 77 additions and 148 deletions

View File

@ -0,0 +1,5 @@
===============================================
Tempest Integration of blazar
===============================================
This directory contains Tempest tests to cover the blazar project

View File

@ -14,13 +14,12 @@
# under the License. # under the License.
from oslo_config import cfg from oslo_config import cfg
from tempest import config
service_available_group = cfg.OptGroup(name="service_available", service_available_group = cfg.OptGroup(name="service_available",
title="Available OpenStack Services") title="Available OpenStack Services")
ServiceAvailableGroup = [ service_option = [
cfg.BoolOpt("climate", cfg.BoolOpt("climate",
default=True, default=True,
help="Whether or not climate is expected to be available. " help="Whether or not climate is expected to be available. "
@ -48,27 +47,3 @@ ResourceReservationGroup = [
default=300, default=300,
help="Timeout in seconds to wait for a lease to finish.") 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()

View File

@ -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)
]

View File

@ -1,4 +1,4 @@
# Copyright 2014 Intel Corporation # Copyright 2017 NTT
# All Rights Reserved. # All Rights Reserved.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may # Licensed under the Apache License, Version 2.0 (the "License"); you may
@ -15,13 +15,8 @@
import json import json
from oslo_log import log as logging
from tempest import config_resource_reservation as config
from tempest.lib.common import rest_client from tempest.lib.common import rest_client
CONF = config.CONF
LOG = logging.getLogger(__name__)
class ResourceReservationV1Client(rest_client.RestClient): class ResourceReservationV1Client(rest_client.RestClient):
"""Client class for accessing the resource reservation API.""" """Client class for accessing the resource reservation API."""

View File

View File

@ -16,11 +16,13 @@
from oslo_log import log from oslo_log import log
from tempest import clients as tempestclients from tempest import clients as tempestclients
from tempest import config_resource_reservation as config from tempest import config
from tempest import exceptions from tempest import exceptions
from tempest.lib.common.utils import test_utils 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 CONF = config.CONF
@ -37,7 +39,8 @@ class ResourceReservationScenarioTest(manager.ScenarioTest):
super(ResourceReservationScenarioTest, cls).setup_clients() super(ResourceReservationScenarioTest, cls).setup_clients()
if not (CONF.service_available.climate or if not (CONF.service_available.climate or
CONF.service_available.blazar): 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() cred_provider = cls._get_credentials_provider()
creds = cred_provider.get_credentials('admin') creds = cred_provider.get_credentials('admin')

View File

@ -16,11 +16,14 @@ import datetime
import time import time
from oslo_log import log as logging from oslo_log import log as logging
from six.moves import range
from tempest.common import waiters from tempest.common import waiters
from tempest import config from tempest import config
from tempest.lib import decorators from tempest.lib import decorators
from tempest.lib import exceptions 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 CONF = config.CONF
@ -144,7 +147,7 @@ class TestHostReservationScenario(rrs.ResourceReservationScenarioTest):
return aggr return aggr
def wait_until_aggregated(self, aggregate_name, host_name): def wait_until_aggregated(self, aggregate_name, host_name):
for i in xrange(self.MAX_RETRY): for i in range(self.MAX_RETRY):
try: try:
aggr = self.fetch_aggregate_by_name(aggregate_name) aggr = self.fetch_aggregate_by_name(aggregate_name)
self.assertTrue(host_name in aggr['hosts']) self.assertTrue(host_name in aggr['hosts'])

View File

@ -22,9 +22,11 @@ from tempest.common import waiters
from tempest import config from tempest import config
from tempest import exceptions from tempest import exceptions
from tempest.lib import decorators from tempest.lib import decorators
from tempest.scenario import resource_reservation_scenario as rrs
from tempest import test from tempest import test
from blazar_tempest_plugin.tests.scenario import (
resource_reservation_scenario as rrs)
CONF = config.CONF CONF = config.CONF
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)

View File

@ -14,7 +14,8 @@
from multiprocessing.pool import ThreadPool 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): class TestReservationConcurrencyScenario(rrs.ResourceReservationScenarioTest):

View File

@ -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"

View File

@ -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)

View File

@ -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')

View File

@ -45,21 +45,8 @@
export PROJECTS="openstack/blazar $PROJECTS" export PROJECTS="openstack/blazar $PROJECTS"
export PROJECTS="openstack/blazar-nova $PROJECTS" export PROJECTS="openstack/blazar-nova $PROJECTS"
export PROJECTS="openstack/python-blazarclient $PROJECTS" export PROJECTS="openstack/python-blazarclient $PROJECTS"
# Construct a regex to limiting scope of tempest export DEVSTACK_GATE_TEMPEST_ALL_PLUGINS=1
r="^(?:tempest\.cli\.simple_read_only\.test_.*reservation.*)" export DEVSTACK_GATE_TEMPEST_REGEX="blazar_tempest_plugin.tests"
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
cp devstack-gate/devstack-vm-gate-wrap.sh ./safe-devstack-vm-gate-wrap.sh cp devstack-gate/devstack-vm-gate-wrap.sh ./safe-devstack-vm-gate-wrap.sh
./safe-devstack-vm-gate-wrap.sh ./safe-devstack-vm-gate-wrap.sh
executable: /bin/bash executable: /bin/bash

View File

@ -24,6 +24,7 @@ setup-hooks = pbr.hooks.setup_hook
[files] [files]
packages = packages =
blazar blazar
blazar_tempest_plugin
[entry_points] [entry_points]
console_scripts = console_scripts =
@ -58,6 +59,9 @@ oslo.config.opts =
wsgi_scripts = wsgi_scripts =
blazar-api-wsgi = blazar.api.wsgi_app:init_app blazar-api-wsgi = blazar.api.wsgi_app:init_app
tempest.test_plugins =
blazar_tests = blazar_tempest_plugin.plugin:BlazarTempestPlugin
[build_sphinx] [build_sphinx]
all_files = 1 all_files = 1
build-dir = doc/build build-dir = doc/build