Merge "Move rally.benchmark.context.base module"
This commit is contained in:
commit
46cfe04416
@ -263,17 +263,17 @@ In the example below, the **"users" context** specifies that the *"NovaServers.b
|
||||
Developer's view
|
||||
^^^^^^^^^^^^^^^^
|
||||
|
||||
From the developer's view, contexts management is implemented via **Context classes**. Each context type that can be specified in the task configuration file corresponds to a certain subclass of the base [https://github.com/openstack/rally/blob/master/rally/benchmark/context/base.py **Context**] class, located in the [https://github.com/openstack/rally/tree/master/rally/benchmark/context **rally.benchmark.context**] module. Every context class should implement a fairly simple **interface**:
|
||||
From the developer's view, contexts management is implemented via **Context classes**. Each context type that can be specified in the task configuration file corresponds to a certain subclass of the base [https://github.com/openstack/rally/blob/master/rally/benchmark/context.py **Context**] class. Every context class should implement a fairly simple **interface**:
|
||||
|
||||
.. parsed-literal::
|
||||
|
||||
from rally.benchmark.context import base
|
||||
from rally.benchmark import context
|
||||
from rally import consts
|
||||
|
||||
@base.context(name="your_context", *# Corresponds to the context field name in task configuration files*
|
||||
order=100500, *# a number specifying the priority with which the context should be set up*
|
||||
hidden=False) *# True if the context cannot be configured through the input task file*
|
||||
class YourContext(base.Context):
|
||||
@context.context(name="your_context", *# Corresponds to the context field name in task configuration files*
|
||||
order=100500, *# a number specifying the priority with which the context should be set up*
|
||||
hidden=False) *# True if the context cannot be configured through the input task file*
|
||||
class YourContext(context.Context):
|
||||
*"""Yet another context class."""*
|
||||
|
||||
*# The schema of the context configuration format*
|
||||
@ -320,4 +320,4 @@ Consequently, the algorithm of initiating the contexts can be roughly seen as fo
|
||||
The *hidden* attribute defines whether the context should be a *hidden* one. **Hidden contexts** cannot be configured by end-users through the task configuration file as shown above, but should be specified by a benchmark scenario developer through a special *@base.scenario(context={...})* decorator. Hidden contexts are typically needed to satisfy some specific benchmark scenario-specific needs, which don't require the end-user's attention. For example, the hidden **"cleanup" context** (:mod:`rally.plugins.openstack.context.cleanup.context`) is used to make generic cleanup after running benchmark. So user can't change
|
||||
it configuration via task and break his cloud.
|
||||
|
||||
If you want to dive deeper, also see the context manager (:mod:`rally.benchmark.context.base`) class that actually implements the algorithm described above.
|
||||
If you want to dive deeper, also see the context manager (:mod:`rally.benchmark.context`) class that actually implements the algorithm described above.
|
||||
|
@ -111,7 +111,7 @@ Inherit a class for your plugin from the base *Context* class. Then, implement t
|
||||
|
||||
.. code-block:: none
|
||||
|
||||
from rally.benchmark.context import base
|
||||
from rally.benchmark import context
|
||||
from rally.common import log as logging
|
||||
from rally import consts
|
||||
from rally import osclients
|
||||
@ -119,13 +119,13 @@ Inherit a class for your plugin from the base *Context* class. Then, implement t
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@base.context(name="create_flavor", order=1000)
|
||||
class CreateFlavorContext(base.Context):
|
||||
@context.context(name="create_flavor", order=1000)
|
||||
class CreateFlavorContext(context.Context):
|
||||
"""This sample create flavor with specified options before task starts and
|
||||
delete it after task completion.
|
||||
|
||||
To create your own context plugin, inherit it from
|
||||
rally.benchmark.context.base.Context
|
||||
rally.benchmark.context.Context
|
||||
"""
|
||||
|
||||
CONFIG_SCHEMA = {
|
||||
|
@ -66,13 +66,13 @@ class Context(functional.FunctionalMixin):
|
||||
"""
|
||||
CONFIG_SCHEMA = {}
|
||||
|
||||
def __init__(self, context):
|
||||
self.config = context.get("config", {}).get(self.get_name(), {})
|
||||
def __init__(self, ctx):
|
||||
self.config = ctx.get("config", {}).get(self.get_name(), {})
|
||||
if hasattr(self, "DEFAULT_CONFIG"):
|
||||
for key, value in self.DEFAULT_CONFIG.items():
|
||||
self.config.setdefault(key, value)
|
||||
self.context = context
|
||||
self.task = context["task"]
|
||||
self.context = ctx
|
||||
self.task = self.context["task"]
|
||||
|
||||
def __lt__(self, other):
|
||||
return self.get_order() < other.get_order()
|
||||
@ -100,9 +100,9 @@ class Context(functional.FunctionalMixin):
|
||||
@staticmethod
|
||||
def get_by_name(name):
|
||||
"""Return Context class by name."""
|
||||
for context in utils.itersubclasses(Context):
|
||||
if name == context.get_name():
|
||||
return context
|
||||
for ctx in utils.itersubclasses(Context):
|
||||
if name == ctx.get_name():
|
||||
return ctx
|
||||
raise exceptions.NoSuchContext(name=name)
|
||||
|
||||
@abc.abstractmethod
|
||||
@ -128,8 +128,8 @@ class ContextManager(object):
|
||||
self.context_obj = context_obj
|
||||
|
||||
@staticmethod
|
||||
def validate(context, non_hidden=False):
|
||||
for name, config in six.iteritems(context):
|
||||
def validate(ctx, non_hidden=False):
|
||||
for name, config in six.iteritems(ctx):
|
||||
Context.get_by_name(name).validate(config, non_hidden=non_hidden)
|
||||
|
||||
def _get_sorted_context_lst(self):
|
@ -21,7 +21,7 @@ import traceback
|
||||
import jsonschema
|
||||
import six
|
||||
|
||||
from rally.benchmark.context import base as base_ctx
|
||||
from rally.benchmark import context
|
||||
from rally.benchmark import runner
|
||||
from rally.benchmark.scenarios import base as base_scenario
|
||||
from rally.benchmark import sla
|
||||
@ -132,8 +132,8 @@ class BenchmarkEngine(object):
|
||||
for pos, kw in enumerate(values):
|
||||
try:
|
||||
runner.ScenarioRunner.validate(kw.get("runner", {}))
|
||||
base_ctx.ContextManager.validate(kw.get("context", {}),
|
||||
non_hidden=True)
|
||||
context.ContextManager.validate(kw.get("context", {}),
|
||||
non_hidden=True)
|
||||
sla.SLA.validate(kw.get("sla", {}))
|
||||
except (exceptions.RallyException,
|
||||
jsonschema.ValidationError) as e:
|
||||
@ -154,12 +154,12 @@ class BenchmarkEngine(object):
|
||||
"config": kwargs, "reason": six.text_type(e)}
|
||||
raise exceptions.InvalidBenchmarkConfig(**kw)
|
||||
|
||||
def _get_user_ctx_for_validation(self, context):
|
||||
def _get_user_ctx_for_validation(self, ctx):
|
||||
if self.existing_users:
|
||||
context["config"] = {"existing_users": self.existing_users}
|
||||
user_context = existingusers_ctx.ExistingUsers(context)
|
||||
ctx["config"] = {"existing_users": self.existing_users}
|
||||
user_context = existingusers_ctx.ExistingUsers(ctx)
|
||||
else:
|
||||
user_context = users_ctx.UserGenerator(context)
|
||||
user_context = users_ctx.UserGenerator(ctx)
|
||||
|
||||
return user_context
|
||||
|
||||
@ -167,7 +167,7 @@ class BenchmarkEngine(object):
|
||||
def _validate_config_semantic(self, config):
|
||||
self._check_cloud()
|
||||
|
||||
context = {"task": self.task, "admin": {"endpoint": self.admin}}
|
||||
ctx_conf = {"task": self.task, "admin": {"endpoint": self.admin}}
|
||||
deployment = objects.Deployment.get(self.task["deployment_uuid"])
|
||||
|
||||
# TODO(boris-42): It's quite hard at the moment to validate case
|
||||
@ -175,12 +175,12 @@ class BenchmarkEngine(object):
|
||||
# specified. So after switching to plugin base
|
||||
# and refactoring validation mechanism this place
|
||||
# will be replaced
|
||||
with self._get_user_ctx_for_validation(context) as ctx:
|
||||
with self._get_user_ctx_for_validation(ctx_conf) as ctx:
|
||||
ctx.setup()
|
||||
admin = osclients.Clients(self.admin)
|
||||
user = osclients.Clients(context["users"][0]["endpoint"])
|
||||
user = osclients.Clients(ctx_conf["users"][0]["endpoint"])
|
||||
|
||||
for u in context["users"]:
|
||||
for u in ctx_conf["users"]:
|
||||
user = osclients.Clients(u["endpoint"])
|
||||
for name, values in six.iteritems(config):
|
||||
for pos, kwargs in enumerate(values):
|
||||
@ -206,14 +206,14 @@ class BenchmarkEngine(object):
|
||||
runner_cfg.setdefault("type", consts.RunnerType.SERIAL)
|
||||
return runner.ScenarioRunner.get_runner(self.task, runner_cfg)
|
||||
|
||||
def _prepare_context(self, context, name, endpoint):
|
||||
def _prepare_context(self, ctx, name, endpoint):
|
||||
scenario_context = base_scenario.Scenario.meta(name, "context")
|
||||
if self.existing_users and "users" not in context:
|
||||
if self.existing_users and "users" not in ctx:
|
||||
scenario_context.setdefault("existing_users", self.existing_users)
|
||||
elif "users" not in context:
|
||||
elif "users" not in ctx:
|
||||
scenario_context.setdefault("users", {})
|
||||
|
||||
scenario_context.update(context)
|
||||
scenario_context.update(ctx)
|
||||
context_obj = {
|
||||
"task": self.task,
|
||||
"admin": {"endpoint": endpoint},
|
||||
@ -252,7 +252,7 @@ class BenchmarkEngine(object):
|
||||
self.full_duration = 0
|
||||
try:
|
||||
with rutils.Timer() as timer:
|
||||
with base_ctx.ContextManager(context_obj):
|
||||
with context.ContextManager(context_obj):
|
||||
self.duration = runner_obj.run(
|
||||
name, context_obj, kw.get("args", {}))
|
||||
except Exception as e:
|
||||
|
@ -13,13 +13,13 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from rally.benchmark.context import base
|
||||
from rally.benchmark import context
|
||||
from rally import consts
|
||||
from rally import exceptions
|
||||
|
||||
|
||||
@base.context(name="dummy_context", order=750)
|
||||
class DummyContext(base.Context):
|
||||
@context.context(name="dummy_context", order=750)
|
||||
class DummyContext(context.Context):
|
||||
"""Dummy context."""
|
||||
CONFIG_SCHEMA = {
|
||||
"type": "object",
|
||||
@ -30,9 +30,6 @@ class DummyContext(base.Context):
|
||||
},
|
||||
}
|
||||
|
||||
def __init__(self, context):
|
||||
super(DummyContext, self).__init__(context)
|
||||
|
||||
def setup(self):
|
||||
if self.config.get("fail_setup", False):
|
||||
raise exceptions.RallyException("Oops...setup is failed")
|
||||
|
@ -12,7 +12,7 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from rally.benchmark.context import base
|
||||
from rally.benchmark import context
|
||||
from rally.common.i18n import _
|
||||
from rally.common import log as logging
|
||||
from rally.common import utils as rutils
|
||||
@ -24,8 +24,8 @@ from rally.plugins.openstack.scenarios.ceilometer import utils as ceilo_utils
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@base.context(name="ceilometer", order=450)
|
||||
class CeilometerSampleGenerator(base.Context):
|
||||
@context.context(name="ceilometer", order=450)
|
||||
class CeilometerSampleGenerator(context.Context):
|
||||
"""Context for creating samples and collecting resources for benchmarks."""
|
||||
|
||||
CONFIG_SCHEMA = {
|
||||
|
@ -15,7 +15,7 @@
|
||||
|
||||
import sys
|
||||
|
||||
from rally.benchmark.context import base
|
||||
from rally.benchmark import context
|
||||
from rally.common.i18n import _
|
||||
from rally.common import log as logging
|
||||
from rally.common import utils as rutils
|
||||
@ -47,8 +47,8 @@ class CleanupMixin(object):
|
||||
|
||||
|
||||
# NOTE(amaretskiy): Set order to run this just before UserCleanup
|
||||
@base.context(name="admin_cleanup", order=(sys.maxsize - 1), hidden=True)
|
||||
class AdminCleanup(CleanupMixin, base.Context):
|
||||
@context.context(name="admin_cleanup", order=(sys.maxsize - 1), hidden=True)
|
||||
class AdminCleanup(CleanupMixin, context.Context):
|
||||
"""Context class for admin resources cleanup."""
|
||||
|
||||
@classmethod
|
||||
@ -72,8 +72,8 @@ class AdminCleanup(CleanupMixin, base.Context):
|
||||
|
||||
|
||||
# NOTE(amaretskiy): Set maximum order to run this last
|
||||
@base.context(name="cleanup", order=sys.maxsize, hidden=True)
|
||||
class UserCleanup(CleanupMixin, base.Context):
|
||||
@context.context(name="cleanup", order=sys.maxsize, hidden=True)
|
||||
class UserCleanup(CleanupMixin, context.Context):
|
||||
"""Context class for user resources cleanup."""
|
||||
|
||||
@classmethod
|
||||
|
@ -13,7 +13,7 @@
|
||||
# under the License.
|
||||
|
||||
|
||||
from rally.benchmark.context import base
|
||||
from rally.benchmark import context
|
||||
from rally.common.i18n import _
|
||||
from rally.common import log as logging
|
||||
from rally.common import utils as rutils
|
||||
@ -27,8 +27,8 @@ LOG = logging.getLogger(__name__)
|
||||
# NOTE(boris-42): This context should be hidden for now and used only by
|
||||
# benchmark engine. In future during various refactoring of
|
||||
# validation system and rally CI testing we will make it public
|
||||
@base.context(name="existing_users", order=99, hidden=True)
|
||||
class ExistingUsers(base.Context):
|
||||
@context.context(name="existing_users", order=99, hidden=True)
|
||||
class ExistingUsers(context.Context):
|
||||
"""This context supports using existing users in Rally.
|
||||
|
||||
It uses information about deployment to properly
|
||||
@ -42,8 +42,8 @@ class ExistingUsers(base.Context):
|
||||
# this is used only by benchmark engine
|
||||
CONFIG_SCHEMA = {}
|
||||
|
||||
def __init__(self, context):
|
||||
super(ExistingUsers, self).__init__(context)
|
||||
def __init__(self, ctx):
|
||||
super(ExistingUsers, self).__init__(ctx)
|
||||
self.context["users"] = []
|
||||
self.context["tenants"] = {}
|
||||
|
||||
|
@ -15,7 +15,7 @@
|
||||
|
||||
from novaclient import exceptions as nova_exceptions
|
||||
|
||||
from rally.benchmark.context import base
|
||||
from rally.benchmark import context
|
||||
from rally.common.i18n import _
|
||||
from rally.common import log as logging
|
||||
from rally.common import utils as rutils
|
||||
@ -25,8 +25,8 @@ from rally import osclients
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@base.context(name="flavors", order=340)
|
||||
class FlavorsGenerator(base.Context):
|
||||
@context.context(name="flavors", order=340)
|
||||
class FlavorsGenerator(context.Context):
|
||||
"""Context creates a list of flavors."""
|
||||
|
||||
CONFIG_SCHEMA = {
|
||||
|
@ -12,7 +12,7 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from rally.benchmark.context import base
|
||||
from rally.benchmark import context
|
||||
from rally.common.i18n import _
|
||||
from rally.common import log as logging
|
||||
from rally.common import utils as rutils
|
||||
@ -25,8 +25,8 @@ from rally.plugins.openstack.scenarios.glance import utils as glance_utils
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@base.context(name="images", order=410)
|
||||
class ImageGenerator(base.Context):
|
||||
@context.context(name="images", order=410)
|
||||
class ImageGenerator(context.Context):
|
||||
"""Context class for adding images to each user for benchmarks."""
|
||||
|
||||
CONFIG_SCHEMA = {
|
||||
@ -64,8 +64,8 @@ class ImageGenerator(base.Context):
|
||||
"additionalProperties": False
|
||||
}
|
||||
|
||||
def __init__(self, context):
|
||||
super(ImageGenerator, self).__init__(context)
|
||||
def __init__(self, ctx):
|
||||
super(ImageGenerator, self).__init__(ctx)
|
||||
|
||||
@rutils.log_task_wrapper(LOG.info, _("Enter context: `Images`"))
|
||||
def setup(self):
|
||||
|
@ -15,7 +15,7 @@
|
||||
|
||||
import novaclient.exceptions
|
||||
|
||||
from rally.benchmark.context import base
|
||||
from rally.benchmark import context
|
||||
from rally.common.i18n import _
|
||||
from rally.common import log as logging
|
||||
from rally.common import utils
|
||||
@ -26,8 +26,8 @@ from rally.plugins.openstack.context.cleanup import manager as resource_manager
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@base.context(name="keypair", order=310)
|
||||
class Keypair(base.Context):
|
||||
@context.context(name="keypair", order=310)
|
||||
class Keypair(context.Context):
|
||||
KEYPAIR_NAME = "rally_ssh_key"
|
||||
|
||||
def _generate_keypair(self, endpoint):
|
||||
|
@ -15,7 +15,7 @@
|
||||
|
||||
import zipfile
|
||||
|
||||
from rally.benchmark.context import base
|
||||
from rally.benchmark import context
|
||||
from rally.common.i18n import _, _LE
|
||||
from rally.common import log as logging
|
||||
from rally.common import utils
|
||||
@ -27,8 +27,8 @@ from rally.plugins.openstack.context.cleanup import manager as resource_manager
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@base.context(name="murano_packages", order=401)
|
||||
class PackageGenerator(base.Context):
|
||||
@context.context(name="murano_packages", order=401)
|
||||
class PackageGenerator(context.Context):
|
||||
"""Context class for uploading applications for murano."""
|
||||
|
||||
CONFIG_SCHEMA = {
|
||||
|
@ -15,7 +15,7 @@
|
||||
|
||||
import six
|
||||
|
||||
from rally.benchmark.context import base
|
||||
from rally.benchmark import context
|
||||
from rally.common.i18n import _
|
||||
from rally.common import log as logging
|
||||
from rally.common import utils
|
||||
@ -27,8 +27,8 @@ from rally.plugins.openstack.wrappers import network as network_wrapper
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@base.context(name="network", order=350)
|
||||
class Network(base.Context):
|
||||
@context.context(name="network", order=350)
|
||||
class Network(context.Context):
|
||||
CONFIG_SCHEMA = {
|
||||
"type": "object",
|
||||
"$schema": consts.JSON_SCHEMA,
|
||||
@ -49,10 +49,10 @@ class Network(base.Context):
|
||||
"networks_per_tenant": 1
|
||||
}
|
||||
|
||||
def __init__(self, context):
|
||||
super(Network, self).__init__(context)
|
||||
def __init__(self, ctx):
|
||||
super(Network, self).__init__(ctx)
|
||||
self.net_wrapper = network_wrapper.wrap(
|
||||
osclients.Clients(context["admin"]["endpoint"]),
|
||||
osclients.Clients(ctx["admin"]["endpoint"]),
|
||||
self.config)
|
||||
|
||||
@utils.log_task_wrapper(LOG.info, _("Enter context: `network`"))
|
||||
|
@ -13,7 +13,7 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from rally.benchmark.context import base
|
||||
from rally.benchmark import context
|
||||
from rally.common.i18n import _
|
||||
from rally.common import log as logging
|
||||
from rally.common import utils
|
||||
@ -28,8 +28,8 @@ from rally.plugins.openstack.context.quotas import nova_quotas
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@base.context(name="quotas", order=300)
|
||||
class Quotas(base.Context):
|
||||
@context.context(name="quotas", order=300)
|
||||
class Quotas(context.Context):
|
||||
"""Context class for updating benchmarks' tenants quotas."""
|
||||
|
||||
CONFIG_SCHEMA = {
|
||||
@ -44,9 +44,9 @@ class Quotas(base.Context):
|
||||
}
|
||||
}
|
||||
|
||||
def __init__(self, context):
|
||||
super(Quotas, self).__init__(context)
|
||||
self.clients = osclients.Clients(context["admin"]["endpoint"])
|
||||
def __init__(self, ctx):
|
||||
super(Quotas, self).__init__(ctx)
|
||||
self.clients = osclients.Clients(self.context["admin"]["endpoint"])
|
||||
|
||||
self.manager = {
|
||||
"nova": nova_quotas.NovaQuotas(self.clients),
|
||||
|
@ -13,7 +13,7 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from rally.benchmark.context import base
|
||||
from rally.benchmark import context
|
||||
from rally.common.i18n import _
|
||||
from rally.common import log as logging
|
||||
from rally.common import utils as rutils
|
||||
@ -25,8 +25,8 @@ from rally import osclients
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@base.context(name="roles", order=330)
|
||||
class RoleGenerator(base.Context):
|
||||
@context.context(name="roles", order=330)
|
||||
class RoleGenerator(context.Context):
|
||||
"""Context class for adding temporary roles for benchmarks."""
|
||||
|
||||
CONFIG_SCHEMA = {
|
||||
@ -38,8 +38,8 @@ class RoleGenerator(base.Context):
|
||||
"additionalProperties": False
|
||||
}
|
||||
|
||||
def __init__(self, context):
|
||||
super(RoleGenerator, self).__init__(context)
|
||||
def __init__(self, ctx):
|
||||
super(RoleGenerator, self).__init__(ctx)
|
||||
self.context["roles"] = []
|
||||
self.endpoint = self.context["admin"]["endpoint"]
|
||||
|
||||
|
@ -15,7 +15,7 @@
|
||||
|
||||
from oslo_config import cfg
|
||||
|
||||
from rally.benchmark.context import base
|
||||
from rally.benchmark import context
|
||||
from rally.benchmark import utils as bench_utils
|
||||
from rally.common.i18n import _
|
||||
from rally.common import log as logging
|
||||
@ -31,8 +31,8 @@ CONF = cfg.CONF
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@base.context(name="sahara_cluster", order=441)
|
||||
class SaharaCluster(base.Context):
|
||||
@context.context(name="sahara_cluster", order=441)
|
||||
class SaharaCluster(context.Context):
|
||||
"""Context class for setting up the Cluster an EDP job."""
|
||||
|
||||
CONFIG_SCHEMA = {
|
||||
@ -87,8 +87,8 @@ class SaharaCluster(base.Context):
|
||||
"flavor_id"]
|
||||
}
|
||||
|
||||
def __init__(self, context):
|
||||
super(SaharaCluster, self).__init__(context)
|
||||
def __init__(self, ctx):
|
||||
super(SaharaCluster, self).__init__(ctx)
|
||||
self.context["sahara_clusters"] = {}
|
||||
|
||||
@rutils.log_task_wrapper(LOG.info, _("Enter context: `Sahara Cluster`"))
|
||||
|
@ -15,7 +15,7 @@
|
||||
|
||||
import requests
|
||||
|
||||
from rally.benchmark.context import base
|
||||
from rally.benchmark import context
|
||||
from rally.common.i18n import _
|
||||
from rally.common import log as logging
|
||||
from rally.common import utils as rutils
|
||||
@ -28,8 +28,8 @@ from rally.plugins.openstack.context.cleanup import manager as resource_manager
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@base.context(name="sahara_edp", order=442)
|
||||
class SaharaEDP(base.Context):
|
||||
@context.context(name="sahara_edp", order=442)
|
||||
class SaharaEDP(context.Context):
|
||||
"""Context class for setting up the environment for an EDP job."""
|
||||
|
||||
CONFIG_SCHEMA = {
|
||||
@ -86,8 +86,8 @@ class SaharaEDP(base.Context):
|
||||
"output_type", "output_url_prefix"]
|
||||
}
|
||||
|
||||
def __init__(self, context):
|
||||
super(SaharaEDP, self).__init__(context)
|
||||
def __init__(self, ctx):
|
||||
super(SaharaEDP, self).__init__(ctx)
|
||||
self.context["sahara_output_conf"] = {
|
||||
"output_type": self.config["output_type"],
|
||||
"output_url_prefix": self.config["output_url_prefix"]
|
||||
|
@ -12,7 +12,7 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from rally.benchmark.context import base
|
||||
from rally.benchmark import context
|
||||
from rally.common.i18n import _
|
||||
from rally.common import log as logging
|
||||
from rally.common import utils as rutils
|
||||
@ -26,8 +26,8 @@ from rally.plugins.openstack.scenarios.glance import utils as glance_utils
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@base.context(name="sahara_image", order=440)
|
||||
class SaharaImage(base.Context):
|
||||
@context.context(name="sahara_image", order=440)
|
||||
class SaharaImage(context.Context):
|
||||
"""Context class for adding and tagging Sahara images."""
|
||||
|
||||
CONFIG_SCHEMA = {
|
||||
@ -58,8 +58,8 @@ class SaharaImage(base.Context):
|
||||
"additionalProperties": False
|
||||
}
|
||||
|
||||
def __init__(self, context):
|
||||
super(SaharaImage, self).__init__(context)
|
||||
def __init__(self, ctx):
|
||||
super(SaharaImage, self).__init__(ctx)
|
||||
self.context["sahara_images"] = {}
|
||||
|
||||
def _create_image(self, hadoop_version, image_url, plugin_name, user,
|
||||
|
@ -15,7 +15,7 @@
|
||||
|
||||
import six
|
||||
|
||||
from rally.benchmark.context import base
|
||||
from rally.benchmark import context
|
||||
from rally.common.i18n import _
|
||||
from rally.common import log as logging
|
||||
from rally.common import utils
|
||||
@ -85,11 +85,8 @@ def _prepare_open_secgroup(endpoint, secgroup_name):
|
||||
return rally_open.to_dict()
|
||||
|
||||
|
||||
@base.context(name="allow_ssh", order=320)
|
||||
class AllowSSH(base.Context):
|
||||
|
||||
def __init__(self, context):
|
||||
super(AllowSSH, self).__init__(context)
|
||||
@context.context(name="allow_ssh", order=320)
|
||||
class AllowSSH(context.Context):
|
||||
|
||||
@utils.log_task_wrapper(LOG.info, _("Enter context: `allow_ssh`"))
|
||||
def setup(self):
|
||||
|
@ -12,7 +12,7 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from rally.benchmark.context import base
|
||||
from rally.benchmark import context
|
||||
from rally.benchmark import types as types
|
||||
from rally.common.i18n import _
|
||||
from rally.common import log as logging
|
||||
@ -26,8 +26,8 @@ from rally.plugins.openstack.scenarios.nova import utils as nova_utils
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@base.context(name="servers", order=430)
|
||||
class ServerGenerator(base.Context):
|
||||
@context.context(name="servers", order=430)
|
||||
class ServerGenerator(context.Context):
|
||||
"""Context class for adding temporary servers for benchmarks.
|
||||
|
||||
Servers are added for each tenant.
|
||||
|
@ -13,7 +13,7 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from rally.benchmark.context import base
|
||||
from rally.benchmark import context
|
||||
from rally.common.i18n import _
|
||||
from rally.common import log as logging
|
||||
from rally.common import utils as rutils
|
||||
@ -25,8 +25,8 @@ from rally.plugins.openstack.scenarios.heat import utils as heat_utils
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@base.context(name="stacks", order=435)
|
||||
class StackGenerator(base.Context):
|
||||
@context.context(name="stacks", order=435)
|
||||
class StackGenerator(context.Context):
|
||||
"""Context class for create temporary stacks with resources.
|
||||
|
||||
Stack generator allows to generate arbitrary number of stacks for
|
||||
|
@ -17,7 +17,7 @@ import os
|
||||
import shutil
|
||||
import tempfile
|
||||
|
||||
from rally.benchmark.context import base
|
||||
from rally.benchmark import context
|
||||
from rally.common.i18n import _
|
||||
from rally.common import log as logging
|
||||
from rally.common import utils
|
||||
@ -29,8 +29,8 @@ from rally.verification.tempest import tempest
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@base.context(name="tempest", order=666)
|
||||
class Tempest(base.Context):
|
||||
@context.context(name="tempest", order=666)
|
||||
class Tempest(context.Context):
|
||||
CONFIG_SCHEMA = {
|
||||
"type": "object",
|
||||
"$schema": consts.JSON_SCHEMA,
|
||||
|
@ -18,7 +18,7 @@ import uuid
|
||||
|
||||
from oslo_config import cfg
|
||||
|
||||
from rally.benchmark.context import base
|
||||
from rally.benchmark import context
|
||||
from rally.benchmark import utils
|
||||
from rally.common import broker
|
||||
from rally.common.i18n import _
|
||||
@ -52,8 +52,8 @@ CONF.register_opts(USER_CONTEXT_OPTS,
|
||||
title="benchmark context options"))
|
||||
|
||||
|
||||
@base.context(name="users", order=100)
|
||||
class UserGenerator(base.Context):
|
||||
@context.context(name="users", order=100)
|
||||
class UserGenerator(context.Context):
|
||||
"""Context class for generating temporary users/tenants for benchmarks."""
|
||||
|
||||
CONFIG_SCHEMA = {
|
||||
|
@ -17,7 +17,7 @@ import abc
|
||||
|
||||
import six
|
||||
|
||||
from rally.benchmark.context import base
|
||||
from rally.benchmark import context
|
||||
from rally.benchmark import types
|
||||
from rally.common import broker
|
||||
from rally.common.i18n import _
|
||||
@ -32,8 +32,8 @@ LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@six.add_metaclass(abc.ABCMeta)
|
||||
@base.context(name="custom_image", order=500, hidden=True)
|
||||
class BaseCustomImageGenerator(base.Context):
|
||||
@context.context(name="custom_image", order=500, hidden=True)
|
||||
class BaseCustomImageGenerator(context.Context):
|
||||
"""Base class for the contexts providing customized image with.
|
||||
|
||||
Every context class for the specific customization must implement
|
||||
|
@ -12,7 +12,7 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from rally.benchmark.context import base
|
||||
from rally.benchmark import context
|
||||
from rally.benchmark.scenarios import base as scenario_base
|
||||
from rally.common.i18n import _
|
||||
from rally.common import log as logging
|
||||
@ -26,8 +26,8 @@ from rally.plugins.openstack.scenarios.cinder import utils as cinder_utils
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@base.context(name="volumes", order=420)
|
||||
class VolumeGenerator(base.Context):
|
||||
@context.context(name="volumes", order=420)
|
||||
class VolumeGenerator(context.Context):
|
||||
"""Context class for adding volumes to each user for benchmarks."""
|
||||
|
||||
CONFIG_SCHEMA = {
|
||||
|
@ -13,7 +13,7 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from rally.benchmark.context import base
|
||||
from rally.benchmark import context
|
||||
from rally.common import log as logging
|
||||
from rally import consts
|
||||
from rally import osclients
|
||||
@ -21,14 +21,14 @@ from rally import osclients
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@base.context(name="create_flavor", order=1000)
|
||||
class CreateFlavorContext(base.Context):
|
||||
@context.context(name="create_flavor", order=1000)
|
||||
class CreateFlavorContext(context.Context):
|
||||
"""Create sample flavor
|
||||
|
||||
This sample create flavor with specified options before task starts and
|
||||
delete it after task completion.
|
||||
To create your own context plugin, inherit it from
|
||||
rally.benchmark.context.base.Context
|
||||
rally.benchmark.context.Context
|
||||
"""
|
||||
|
||||
CONFIG_SCHEMA = {
|
||||
@ -57,7 +57,7 @@ class CreateFlavorContext(base.Context):
|
||||
def setup(self):
|
||||
"""This method is called before the task start."""
|
||||
try:
|
||||
# use rally.osclients to get nessesary client instance
|
||||
# use rally.osclients to get necessary client instance
|
||||
nova = osclients.Clients(self.context["admin"]["endpoint"]).nova()
|
||||
# and than do what you need with this client
|
||||
self.context["flavor"] = nova.flavors.create(
|
||||
|
@ -18,7 +18,7 @@ import traceback
|
||||
import mock
|
||||
import six
|
||||
|
||||
from rally.benchmark.context import base as base_ctx
|
||||
from rally.benchmark import context
|
||||
from rally.benchmark.scenarios import base
|
||||
from rally.benchmark import validation
|
||||
from rally import consts
|
||||
@ -248,9 +248,9 @@ class ScenarioTestCase(test.TestCase):
|
||||
self.assertEqual(scenario.idle_duration(), mock_uniform.return_value)
|
||||
|
||||
def test_context(self):
|
||||
context = {}
|
||||
scenario = base.Scenario(context=context)
|
||||
self.assertEqual(context, scenario.context)
|
||||
ctx = {}
|
||||
scenario = base.Scenario(context=ctx)
|
||||
self.assertEqual(ctx, scenario.context)
|
||||
|
||||
def test_clients(self):
|
||||
clients = fakes.FakeClients()
|
||||
@ -272,9 +272,9 @@ class ScenarioTestCase(test.TestCase):
|
||||
for scenario in scenarios:
|
||||
cls_name, method_name = scenario.split(".", 1)
|
||||
cls = base.Scenario.get_by_name(cls_name)
|
||||
context = getattr(cls, method_name).context
|
||||
ctx = getattr(cls, method_name).context
|
||||
try:
|
||||
base_ctx.ContextManager.validate(context)
|
||||
context.ContextManager.validate(ctx)
|
||||
except Exception:
|
||||
print(traceback.format_exc())
|
||||
self.assertTrue(False,
|
||||
|
@ -17,7 +17,7 @@
|
||||
import jsonschema
|
||||
import mock
|
||||
|
||||
from rally.benchmark.context import base
|
||||
from rally.benchmark import context
|
||||
from rally import exceptions
|
||||
from tests.unit import fakes
|
||||
from tests.unit import test
|
||||
@ -26,7 +26,7 @@ from tests.unit import test
|
||||
class BaseContextTestCase(test.TestCase):
|
||||
|
||||
def test_init(self):
|
||||
context = {
|
||||
ctx0 = {
|
||||
"config": {
|
||||
"a": 1,
|
||||
"fake": mock.MagicMock()
|
||||
@ -34,19 +34,19 @@ class BaseContextTestCase(test.TestCase):
|
||||
"task": mock.MagicMock()
|
||||
}
|
||||
|
||||
ctx = fakes.FakeContext(context)
|
||||
self.assertEqual(ctx.config, context["config"]["fake"])
|
||||
self.assertEqual(ctx.task, context["task"])
|
||||
self.assertEqual(ctx.context, context)
|
||||
ctx = fakes.FakeContext(ctx0)
|
||||
self.assertEqual(ctx.config, ctx0["config"]["fake"])
|
||||
self.assertEqual(ctx.task, ctx0["task"])
|
||||
self.assertEqual(ctx.context, ctx0)
|
||||
|
||||
def test_init_empty_context(self):
|
||||
context = {
|
||||
ctx0 = {
|
||||
"task": mock.MagicMock()
|
||||
}
|
||||
ctx = fakes.FakeContext(context)
|
||||
ctx = fakes.FakeContext(ctx0)
|
||||
self.assertEqual(ctx.config, {})
|
||||
self.assertEqual(ctx.task, context["task"])
|
||||
self.assertEqual(ctx.context, context)
|
||||
self.assertEqual(ctx.task, ctx0["task"])
|
||||
self.assertEqual(ctx.context, ctx0)
|
||||
|
||||
def test_validate__context(self):
|
||||
fakes.FakeContext.validate({"test": 2})
|
||||
@ -55,35 +55,35 @@ class BaseContextTestCase(test.TestCase):
|
||||
self.assertRaises(jsonschema.ValidationError,
|
||||
fakes.FakeContext.validate, {"nonexisting": 2})
|
||||
|
||||
@mock.patch("rally.benchmark.context.base.utils.itersubclasses")
|
||||
@mock.patch("rally.benchmark.context.utils.itersubclasses")
|
||||
def test_get_by_name(self, mock_itersubclasses):
|
||||
|
||||
@base.context(name="some_fake1", order=1)
|
||||
class SomeFake1(base.Context):
|
||||
@context.context(name="some_fake1", order=1)
|
||||
class SomeFake1(context.Context):
|
||||
pass
|
||||
|
||||
@base.context(name="some_fake2", order=1)
|
||||
class SomeFake2(base.Context):
|
||||
@context.context(name="some_fake2", order=1)
|
||||
class SomeFake2(context.Context):
|
||||
pass
|
||||
|
||||
mock_itersubclasses.return_value = [SomeFake1, SomeFake2]
|
||||
|
||||
self.assertEqual(SomeFake1, base.Context.get_by_name("some_fake1"))
|
||||
self.assertEqual(SomeFake2, base.Context.get_by_name("some_fake2"))
|
||||
self.assertEqual(SomeFake1, context.Context.get_by_name("some_fake1"))
|
||||
self.assertEqual(SomeFake2, context.Context.get_by_name("some_fake2"))
|
||||
|
||||
@mock.patch("rally.benchmark.context.base.utils.itersubclasses")
|
||||
@mock.patch("rally.benchmark.context.utils.itersubclasses")
|
||||
def test_get_by_name_non_existing(self, mock_itersubclasses):
|
||||
mock_itersubclasses.return_value = []
|
||||
self.assertRaises(exceptions.NoSuchContext,
|
||||
base.Context.get_by_name, "nonexisting")
|
||||
context.Context.get_by_name, "nonexisting")
|
||||
|
||||
def test_get_by_name_hidder(self):
|
||||
self.assertRaises(exceptions.NoSuchContext,
|
||||
base.Context.validate, {}, non_hidden=True)
|
||||
context.Context.validate, {}, non_hidden=True)
|
||||
|
||||
def test_setup_is_abstract(self):
|
||||
|
||||
class A(base.Context):
|
||||
class A(context.Context):
|
||||
|
||||
def cleanup(self):
|
||||
pass
|
||||
@ -91,7 +91,7 @@ class BaseContextTestCase(test.TestCase):
|
||||
self.assertRaises(TypeError, A)
|
||||
|
||||
def test_cleanup_is_abstract(self):
|
||||
class A(base.Context):
|
||||
class A(context.Context):
|
||||
|
||||
def setup(self):
|
||||
pass
|
||||
@ -99,10 +99,10 @@ class BaseContextTestCase(test.TestCase):
|
||||
self.assertRaises(TypeError, A)
|
||||
|
||||
def test_with_statement(self):
|
||||
context = {
|
||||
ctx0 = {
|
||||
"task": mock.MagicMock()
|
||||
}
|
||||
ctx = fakes.FakeContext(context)
|
||||
ctx = fakes.FakeContext(ctx0)
|
||||
ctx.setup = mock.MagicMock()
|
||||
ctx.cleanup = mock.MagicMock()
|
||||
|
||||
@ -113,7 +113,7 @@ class BaseContextTestCase(test.TestCase):
|
||||
|
||||
def test_lt(self):
|
||||
|
||||
@base.context(name="fake_lt", order=fakes.FakeContext.get_order() - 1)
|
||||
@context.context(name="lt", order=fakes.FakeContext.get_order() - 1)
|
||||
class FakeLowerContext(fakes.FakeContext):
|
||||
pass
|
||||
|
||||
@ -124,7 +124,7 @@ class BaseContextTestCase(test.TestCase):
|
||||
|
||||
def test_gt(self):
|
||||
|
||||
@base.context(name="fake_gt", order=fakes.FakeContext.get_order() + 1)
|
||||
@context.context(name="f", order=fakes.FakeContext.get_order() + 1)
|
||||
class FakeBiggerContext(fakes.FakeContext):
|
||||
pass
|
||||
|
||||
@ -135,7 +135,7 @@ class BaseContextTestCase(test.TestCase):
|
||||
|
||||
def test_eq(self):
|
||||
|
||||
@base.context(name="fake2", order=fakes.FakeContext.get_order() + 1)
|
||||
@context.context(name="fake2", order=fakes.FakeContext.get_order() + 1)
|
||||
class FakeOtherContext(fakes.FakeContext):
|
||||
pass
|
||||
|
||||
@ -146,28 +146,28 @@ class BaseContextTestCase(test.TestCase):
|
||||
|
||||
class ContextManagerTestCase(test.TestCase):
|
||||
|
||||
@mock.patch("rally.benchmark.context.base.Context.get_by_name")
|
||||
@mock.patch("rally.benchmark.context.Context.get_by_name")
|
||||
def test_validate(self, mock_get):
|
||||
config = {
|
||||
"ctx1": mock.MagicMock(),
|
||||
"ctx2": mock.MagicMock()
|
||||
}
|
||||
|
||||
base.ContextManager.validate(config)
|
||||
context.ContextManager.validate(config)
|
||||
for ctx in ("ctx1", "ctx2"):
|
||||
mock_get.assert_has_calls([
|
||||
mock.call(ctx),
|
||||
mock.call().validate(config[ctx], non_hidden=False),
|
||||
])
|
||||
|
||||
@mock.patch("rally.benchmark.context.base.Context.get_by_name")
|
||||
@mock.patch("rally.benchmark.context.Context.get_by_name")
|
||||
def test_validate_non_hidden(self, mock_get):
|
||||
config = {
|
||||
"ctx1": mock.MagicMock(),
|
||||
"ctx2": mock.MagicMock()
|
||||
}
|
||||
|
||||
base.ContextManager.validate(config, non_hidden=True)
|
||||
context.ContextManager.validate(config, non_hidden=True)
|
||||
for ctx in ("ctx1", "ctx2"):
|
||||
mock_get.assert_has_calls([
|
||||
mock.call(ctx),
|
||||
@ -179,16 +179,16 @@ class ContextManagerTestCase(test.TestCase):
|
||||
"nonexisting": {"nonexisting": 2}
|
||||
}
|
||||
self.assertRaises(exceptions.NoSuchContext,
|
||||
base.ContextManager.validate, config)
|
||||
context.ContextManager.validate, config)
|
||||
|
||||
@mock.patch("rally.benchmark.context.base.Context.get_by_name")
|
||||
@mock.patch("rally.benchmark.context.Context.get_by_name")
|
||||
def test_setup(self, mock_get_by_name):
|
||||
mock_context = mock.MagicMock()
|
||||
mock_context.return_value = mock.MagicMock(__lt__=lambda x, y: True)
|
||||
mock_get_by_name.return_value = mock_context
|
||||
ctx_object = {"config": {"a": [], "b": []}}
|
||||
|
||||
manager = base.ContextManager(ctx_object)
|
||||
manager = context.ContextManager(ctx_object)
|
||||
result = manager.setup()
|
||||
|
||||
self.assertEqual(result, ctx_object)
|
||||
@ -201,14 +201,14 @@ class ContextManagerTestCase(test.TestCase):
|
||||
mock.call.setup()],
|
||||
any_order=True)
|
||||
|
||||
@mock.patch("rally.benchmark.context.base.Context.get_by_name")
|
||||
@mock.patch("rally.benchmark.context.Context.get_by_name")
|
||||
def test_cleanup(self, mock_get_by_name):
|
||||
mock_context = mock.MagicMock()
|
||||
mock_context.return_value = mock.MagicMock(__lt__=lambda x, y: True)
|
||||
mock_get_by_name.return_value = mock_context
|
||||
ctx_object = {"config": {"a": [], "b": []}}
|
||||
|
||||
manager = base.ContextManager(ctx_object)
|
||||
manager = context.ContextManager(ctx_object)
|
||||
manager.cleanup()
|
||||
mock_get_by_name.assert_has_calls([mock.call("a"), mock.call("b")],
|
||||
any_order=True)
|
||||
@ -218,14 +218,14 @@ class ContextManagerTestCase(test.TestCase):
|
||||
mock.call.cleanup()],
|
||||
any_order=True)
|
||||
|
||||
@mock.patch("rally.benchmark.context.base.Context.get_by_name")
|
||||
@mock.patch("rally.benchmark.context.Context.get_by_name")
|
||||
def test_cleanup_exception(self, mock_get_by_name):
|
||||
mock_context = mock.MagicMock()
|
||||
mock_context.return_value = mock.MagicMock(__lt__=lambda x, y: True)
|
||||
mock_context.cleanup.side_effect = Exception()
|
||||
mock_get_by_name.return_value = mock_context
|
||||
ctx_object = {"config": {"a": [], "b": []}}
|
||||
manager = base.ContextManager(ctx_object)
|
||||
manager = context.ContextManager(ctx_object)
|
||||
manager.cleanup()
|
||||
|
||||
mock_get_by_name.assert_has_calls([mock.call("a"), mock.call("b")],
|
||||
@ -236,24 +236,24 @@ class ContextManagerTestCase(test.TestCase):
|
||||
mock.call.cleanup()],
|
||||
any_order=True)
|
||||
|
||||
@mock.patch("rally.benchmark.context.base.ContextManager.cleanup")
|
||||
@mock.patch("rally.benchmark.context.base.ContextManager.setup")
|
||||
@mock.patch("rally.benchmark.context.ContextManager.cleanup")
|
||||
@mock.patch("rally.benchmark.context.ContextManager.setup")
|
||||
def test_with_statement(self, mock_setup, mock_cleanup):
|
||||
with base.ContextManager(mock.MagicMock()):
|
||||
with context.ContextManager(mock.MagicMock()):
|
||||
mock_setup.assert_called_once_with()
|
||||
mock_setup.reset_mock()
|
||||
self.assertFalse(mock_cleanup.called)
|
||||
self.assertFalse(mock_setup.called)
|
||||
mock_cleanup.assert_called_once_with()
|
||||
|
||||
@mock.patch("rally.benchmark.context.base.ContextManager.cleanup")
|
||||
@mock.patch("rally.benchmark.context.base.ContextManager.setup")
|
||||
@mock.patch("rally.benchmark.context.ContextManager.cleanup")
|
||||
@mock.patch("rally.benchmark.context.ContextManager.setup")
|
||||
def test_with_statement_excpetion_during_setup(self, mock_setup,
|
||||
mock_cleanup):
|
||||
mock_setup.side_effect = Exception("abcdef")
|
||||
|
||||
try:
|
||||
with base.ContextManager(mock.MagicMock()):
|
||||
with context.ContextManager(mock.MagicMock()):
|
||||
pass
|
||||
except Exception:
|
||||
pass
|
@ -124,7 +124,7 @@ class BenchmarkEngineTestCase(test.TestCase):
|
||||
eng._validate_config_scenarios_name, config)
|
||||
|
||||
@mock.patch("rally.benchmark.engine.runner.ScenarioRunner.validate")
|
||||
@mock.patch("rally.benchmark.engine.base_ctx.ContextManager.validate")
|
||||
@mock.patch("rally.benchmark.engine.context.ContextManager.validate")
|
||||
def test__validate_config_syntax(self, mock_context, mock_runner):
|
||||
config = {"sca": [{"context": "a"}], "scb": [{"runner": "b"}]}
|
||||
eng = engine.BenchmarkEngine(mock.MagicMock(), mock.MagicMock())
|
||||
@ -136,7 +136,7 @@ class BenchmarkEngineTestCase(test.TestCase):
|
||||
any_order=True)
|
||||
|
||||
@mock.patch("rally.benchmark.engine.runner.ScenarioRunner")
|
||||
@mock.patch("rally.benchmark.engine.base_ctx.ContextManager.validate")
|
||||
@mock.patch("rally.benchmark.engine.context.ContextManager.validate")
|
||||
def test__validate_config_syntax__wrong_runner(self, mock_context,
|
||||
mock_runner):
|
||||
config = {"sca": [{"context": "a"}], "scb": [{"runner": "b"}]}
|
||||
@ -148,7 +148,7 @@ class BenchmarkEngineTestCase(test.TestCase):
|
||||
eng._validate_config_syntax, config)
|
||||
|
||||
@mock.patch("rally.benchmark.engine.runner.ScenarioRunner.validate")
|
||||
@mock.patch("rally.benchmark.engine.base_ctx.ContextManager")
|
||||
@mock.patch("rally.benchmark.engine.context.ContextManager")
|
||||
def test__validate_config_syntax__wrong_context(self, mock_context,
|
||||
mock_runner):
|
||||
config = {"sca": [{"context": "a"}], "scb": [{"runner": "b"}]}
|
||||
@ -235,8 +235,8 @@ class BenchmarkEngineTestCase(test.TestCase):
|
||||
mock_helper.assert_has_calls(expected_calls, any_order=True)
|
||||
|
||||
@mock.patch("rally.benchmark.engine.BenchmarkEngine.consume_results")
|
||||
@mock.patch("rally.benchmark.engine.base_ctx.ContextManager.cleanup")
|
||||
@mock.patch("rally.benchmark.engine.base_ctx.ContextManager.setup")
|
||||
@mock.patch("rally.benchmark.engine.context.ContextManager.cleanup")
|
||||
@mock.patch("rally.benchmark.engine.context.ContextManager.setup")
|
||||
@mock.patch("rally.benchmark.engine.base_scenario.Scenario")
|
||||
@mock.patch("rally.benchmark.engine.runner.ScenarioRunner")
|
||||
def test_run__update_status(self, mock_runner, mock_scenario,
|
||||
@ -252,8 +252,8 @@ class BenchmarkEngineTestCase(test.TestCase):
|
||||
@mock.patch("rally.benchmark.engine.BenchmarkEngine.consume_results")
|
||||
@mock.patch("rally.benchmark.engine.base_scenario.Scenario")
|
||||
@mock.patch("rally.benchmark.engine.runner.ScenarioRunner")
|
||||
@mock.patch("rally.benchmark.engine.base_ctx.ContextManager.cleanup")
|
||||
@mock.patch("rally.benchmark.engine.base_ctx.ContextManager.setup")
|
||||
@mock.patch("rally.benchmark.engine.context.ContextManager.cleanup")
|
||||
@mock.patch("rally.benchmark.engine.context.ContextManager.setup")
|
||||
def test_run__config_has_args(self, mock_setup, mock_cleanup,
|
||||
mock_runner, mock_scenario, mock_consume):
|
||||
config = {
|
||||
@ -267,8 +267,8 @@ class BenchmarkEngineTestCase(test.TestCase):
|
||||
@mock.patch("rally.benchmark.engine.BenchmarkEngine.consume_results")
|
||||
@mock.patch("rally.benchmark.engine.base_scenario.Scenario")
|
||||
@mock.patch("rally.benchmark.engine.runner.ScenarioRunner")
|
||||
@mock.patch("rally.benchmark.engine.base_ctx.ContextManager.cleanup")
|
||||
@mock.patch("rally.benchmark.engine.base_ctx.ContextManager.setup")
|
||||
@mock.patch("rally.benchmark.engine.context.ContextManager.cleanup")
|
||||
@mock.patch("rally.benchmark.engine.context.ContextManager.setup")
|
||||
def test_run__config_has_runner(self, mock_setup, mock_cleanup,
|
||||
mock_runner, mock_scenario, mock_consume):
|
||||
config = {
|
||||
@ -282,8 +282,8 @@ class BenchmarkEngineTestCase(test.TestCase):
|
||||
@mock.patch("rally.benchmark.engine.BenchmarkEngine.consume_results")
|
||||
@mock.patch("rally.benchmark.engine.base_scenario.Scenario")
|
||||
@mock.patch("rally.benchmark.engine.runner.ScenarioRunner")
|
||||
@mock.patch("rally.benchmark.engine.base_ctx.ContextManager.cleanup")
|
||||
@mock.patch("rally.benchmark.engine.base_ctx.ContextManager.setup")
|
||||
@mock.patch("rally.benchmark.engine.context.ContextManager.cleanup")
|
||||
@mock.patch("rally.benchmark.engine.context.ContextManager.setup")
|
||||
def test_run__config_has_context(self, mock_ctx_setup, mock_ctx_cleanup,
|
||||
mock_runner, mock_scenario, mock_consume):
|
||||
config = {
|
||||
@ -298,8 +298,8 @@ class BenchmarkEngineTestCase(test.TestCase):
|
||||
@mock.patch("rally.benchmark.engine.BenchmarkEngine.consume_results")
|
||||
@mock.patch("rally.benchmark.engine.base_scenario.Scenario")
|
||||
@mock.patch("rally.benchmark.engine.runner.ScenarioRunner")
|
||||
@mock.patch("rally.benchmark.engine.base_ctx.ContextManager.cleanup")
|
||||
@mock.patch("rally.benchmark.engine.base_ctx.ContextManager.setup")
|
||||
@mock.patch("rally.benchmark.engine.context.ContextManager.cleanup")
|
||||
@mock.patch("rally.benchmark.engine.context.ContextManager.setup")
|
||||
def test_run_exception_is_logged(self, mock_ctx_setup, mock_ctx_cleanup,
|
||||
mock_runner, mock_scenario, mock_consume,
|
||||
mock_log):
|
||||
|
@ -27,7 +27,7 @@ from novaclient import exceptions as nova_exceptions
|
||||
import six
|
||||
from swiftclient import exceptions as swift_exceptions
|
||||
|
||||
from rally.benchmark.context import base as base_ctx
|
||||
from rally.benchmark import context
|
||||
from rally.benchmark.scenarios import base
|
||||
from rally.common import utils as rally_utils
|
||||
from rally import consts
|
||||
@ -1498,8 +1498,8 @@ class FakeTimer(rally_utils.Timer):
|
||||
return 0
|
||||
|
||||
|
||||
@base_ctx.context("fake", order=1)
|
||||
class FakeContext(base_ctx.Context):
|
||||
@context.context("fake", order=1)
|
||||
class FakeContext(context.Context):
|
||||
|
||||
CONFIG_SCHEMA = {
|
||||
"type": "object",
|
||||
@ -1532,15 +1532,15 @@ class FakeUserContext(FakeContext):
|
||||
}
|
||||
tenants = {"uuid": {"name": "tenant"}}
|
||||
|
||||
def __init__(self, context):
|
||||
context.setdefault("task", mock.MagicMock())
|
||||
super(FakeUserContext, self).__init__(context)
|
||||
def __init__(self, ctx):
|
||||
ctx.setdefault("task", mock.MagicMock())
|
||||
super(FakeUserContext, self).__init__(ctx)
|
||||
|
||||
context.setdefault("admin", FakeUserContext.admin)
|
||||
context.setdefault("users", [FakeUserContext.user])
|
||||
context.setdefault("tenants", FakeUserContext.tenants)
|
||||
context.setdefault("scenario_name",
|
||||
"NovaServers.boot_server_from_volume_and_delete")
|
||||
self.context.setdefault("admin", FakeUserContext.admin)
|
||||
self.context.setdefault("users", [FakeUserContext.user])
|
||||
self.context.setdefault("tenants", FakeUserContext.tenants)
|
||||
self.context.setdefault(
|
||||
"scenario_name", "NovaServers.boot_server_from_volume_and_delete")
|
||||
|
||||
|
||||
class FakeDeployment(dict):
|
||||
|
@ -34,11 +34,11 @@ class ImageGeneratorTestCase(test.TestCase):
|
||||
tenants[str(id_)] = dict(name=str(id_))
|
||||
return tenants
|
||||
|
||||
@mock.patch("rally.plugins.openstack.context.images.base.Context.__init__")
|
||||
@mock.patch("%s.images.context.Context.__init__" % CTX)
|
||||
def test_init(self, mock_base_context_init):
|
||||
context = {}
|
||||
context["task"] = mock.MagicMock()
|
||||
context["config"] = {
|
||||
ctx = {}
|
||||
ctx["task"] = mock.MagicMock()
|
||||
ctx["config"] = {
|
||||
"images": {
|
||||
"image_url": "mock_url",
|
||||
"image_type": "qcow2",
|
||||
@ -50,8 +50,8 @@ class ImageGeneratorTestCase(test.TestCase):
|
||||
}
|
||||
}
|
||||
|
||||
images.ImageGenerator(context)
|
||||
mock_base_context_init.assert_called_once_with(context)
|
||||
images.ImageGenerator(ctx)
|
||||
mock_base_context_init.assert_called_once_with(ctx)
|
||||
|
||||
def test_init_validation(self):
|
||||
context = {}
|
||||
|
Loading…
x
Reference in New Issue
Block a user