Refactoring log utils

* Moved log functions from rally/common/utils.py #L137-L234 to rally/common/log.y
* Moved test tunctions form test/unit/common/test_utils.py to test/unit/common/test_log.py

Change-Id: Icac3e87d507a3cf90e27071cb26bc871dac78514
This commit is contained in:
Bo Chi 2015-10-29 08:20:07 -04:00
parent 32318312b0
commit 4bfbeb271d
45 changed files with 302 additions and 297 deletions

View File

@ -13,12 +13,14 @@
# License for the specific language governing permissions and limitations
# under the License.
import functools
import logging
from oslo_config import cfg
from oslo_log import handlers
from oslo_log import log as oslogging
from rally.common.i18n import _
DEBUG_OPTS = [cfg.BoolOpt(
"rally-debug",
@ -55,6 +57,12 @@ def setup(product_name, version="unknown"):
project=product_name).logger.setLevel(logging.RDEBUG)
class RallyContextAdapter(oslogging.KeywordArgumentAdapter):
def debug(self, msg, *args, **kwargs):
self.log(logging.RDEBUG, msg, *args, **kwargs)
def getLogger(name="unknown", version="unknown"):
if name not in oslogging._loggers:
@ -64,10 +72,7 @@ def getLogger(name="unknown", version="unknown"):
return oslogging._loggers[name]
class RallyContextAdapter(oslogging.KeywordArgumentAdapter):
def debug(self, msg, *args, **kwargs):
self.log(logging.RDEBUG, msg, *args, **kwargs)
LOG = getLogger(__name__)
class ExceptionLogger(object):
@ -164,5 +169,104 @@ class LogCatcher(object):
return [record.msg for record in self.handler.buffer]
def _log_wrapper(obj, log_function, msg, **kw):
"""A logging wrapper for any method of a class.
Class instances that use this decorator should have self.task or
self.deployment attribute. The wrapper produces logs messages both
before and after the method execution, in the following format
(example for tasks):
"Task <Task UUID> | Starting: <Logging message>"
[Method execution...]
"Task <Task UUID> | Completed: <Logging message>"
:param obj: task or deployment which must be attribute of "self"
:param log_function: Logging method to be used, e.g. LOG.info
:param msg: Text message (possibly parameterized) to be put to the log
:param **kw: Parameters for msg
"""
def decorator(f):
@functools.wraps(f)
def wrapper(self, *args, **kwargs):
params = {"msg": msg % kw, "obj_name": obj.title(),
"uuid": getattr(self, obj)["uuid"]}
log_function(_("%(obj_name)s %(uuid)s | Starting: %(msg)s") %
params)
result = f(self, *args, **kwargs)
log_function(_("%(obj_name)s %(uuid)s | Completed: %(msg)s") %
params)
return result
return wrapper
return decorator
def log_task_wrapper(log_function, msg, **kw):
return _log_wrapper("task", log_function, msg, **kw)
def log_deploy_wrapper(log_function, msg, **kw):
return _log_wrapper("deployment", log_function, msg, **kw)
def log_verification_wrapper(log_function, msg, **kw):
return _log_wrapper("verification", log_function, msg, **kw)
def log_deprecated(message, rally_version, log_function=None, once=False):
"""A wrapper marking a certain method as deprecated.
:param message: Message that describes why the method was deprecated
:param rally_version: version of Rally when the method was deprecated
:param log_function: Logging method to be used, e.g. LOG.info
:param once: Show only once (default is each)
"""
log_function = log_function or LOG.warning
def decorator(f):
@functools.wraps(f)
def wrapper(*args, **kwargs):
if (not once) or (not getattr(f, "_warned_dep_method", False)):
log_function("'%(func)s' is deprecated in Rally v%(version)s: "
"%(msg)s" % {"msg": message,
"version": rally_version,
"func": f.__name__})
setattr(f, "_warned_dep_method", once)
return f(*args, **kwargs)
return wrapper
return decorator
def log_deprecated_args(message, rally_version, deprecated_args,
log_function=None, once=False):
"""A wrapper marking certain arguments as deprecated.
:param message: Message that describes why the arguments were deprecated
:param rally_version: version of Rally when the arguments were deprecated
:param deprecated_args: List of deprecated args.
:param log_function: Logging method to be used, e.g. LOG.info
:param once: Show only once (default is each)
"""
log_function = log_function or LOG.warning
def decorator(f):
@functools.wraps(f)
def wrapper(*args, **kwargs):
if (not once) or (not getattr(f, "_warned_dep_args", False)):
deprecated = ", ".join([
"`%s'" % x for x in deprecated_args if x in kwargs])
if deprecated:
log_function(
"%(msg)s (args %(args)s deprecated in Rally "
"v%(version)s)" %
{"msg": message, "version": rally_version,
"args": deprecated})
setattr(f, "_warned_dep_args", once)
result = f(*args, **kwargs)
return result
return wrapper
return decorator
def is_debug():
return CONF.debug or CONF.rally_debug

View File

@ -13,7 +13,6 @@
# License for the specific language governing permissions and limitations
# under the License.
import functools
import inspect
import multiprocessing
import random
@ -24,7 +23,6 @@ import time
from six import moves
from rally.common.i18n import _
from rally.common import log as logging
from rally import exceptions
@ -134,105 +132,6 @@ class RAMInt(object):
self.__int.value = 0
def _log_wrapper(obj, log_function, msg, **kw):
"""A logging wrapper for any method of a class.
Class instances that use this decorator should have self.task or
self.deployment attribute. The wrapper produces logs messages both
before and after the method execution, in the following format
(example for tasks):
"Task <Task UUID> | Starting: <Logging message>"
[Method execution...]
"Task <Task UUID> | Completed: <Logging message>"
:param obj: task or deployment which must be attribute of "self"
:param log_function: Logging method to be used, e.g. LOG.info
:param msg: Text message (possibly parameterized) to be put to the log
:param **kw: Parameters for msg
"""
def decorator(f):
@functools.wraps(f)
def wrapper(self, *args, **kwargs):
params = {"msg": msg % kw, "obj_name": obj.title(),
"uuid": getattr(self, obj)["uuid"]}
log_function(_("%(obj_name)s %(uuid)s | Starting: %(msg)s") %
params)
result = f(self, *args, **kwargs)
log_function(_("%(obj_name)s %(uuid)s | Completed: %(msg)s") %
params)
return result
return wrapper
return decorator
def log_task_wrapper(log_function, msg, **kw):
return _log_wrapper("task", log_function, msg, **kw)
def log_deploy_wrapper(log_function, msg, **kw):
return _log_wrapper("deployment", log_function, msg, **kw)
def log_verification_wrapper(log_function, msg, **kw):
return _log_wrapper("verification", log_function, msg, **kw)
def log_deprecated(message, rally_version, log_function=None, once=False):
"""A wrapper marking a certain method as deprecated.
:param message: Message that describes why the method was deprecated
:param rally_version: version of Rally when the method was deprecated
:param log_function: Logging method to be used, e.g. LOG.info
:param once: Show only once (default is each)
"""
log_function = log_function or LOG.warning
def decorator(f):
@functools.wraps(f)
def wrapper(*args, **kwargs):
if (not once) or (not getattr(f, "_warned_dep_method", False)):
log_function("'%(func)s' is deprecated in Rally v%(version)s: "
"%(msg)s" % {"msg": message,
"version": rally_version,
"func": f.__name__})
setattr(f, "_warned_dep_method", once)
return f(*args, **kwargs)
return wrapper
return decorator
def log_deprecated_args(message, rally_version, deprecated_args,
log_function=None, once=False):
"""A wrapper marking certain arguments as deprecated.
:param message: Message that describes why the arguments were deprecated
:param rally_version: version of Rally when the arguments were deprecated
:param deprecated_args: List of deprecated args.
:param log_function: Logging method to be used, e.g. LOG.info
:param once: Show only once (default is each)
"""
log_function = log_function or LOG.warning
def decorator(f):
@functools.wraps(f)
def wrapper(*args, **kwargs):
if (not once) or (not getattr(f, "_warned_dep_args", False)):
deprecated = ", ".join([
"`%s'" % x for x in deprecated_args if x in kwargs])
if deprecated:
log_function(
"%(msg)s (args %(args)s deprecated in Rally "
"v%(version)s)" %
{"msg": message, "version": rally_version,
"args": deprecated})
setattr(f, "_warned_dep_args", once)
result = f(*args, **kwargs)
return result
return wrapper
return decorator
def get_method_class(func):
"""Return the class that defined the given method.

View File

@ -21,7 +21,6 @@ import six
from rally.common.i18n import _
from rally.common import log as logging
from rally.common.plugin import plugin
from rally.common import utils
from rally import consts
from rally.deployment.serverprovider import provider
from rally import exceptions
@ -112,15 +111,15 @@ class Engine(plugin.Plugin):
def cleanup(self):
"""Cleanup OpenStack deployment."""
@utils.log_deploy_wrapper(LOG.info, _("OpenStack cloud deployment."))
@logging.log_deploy_wrapper(LOG.info, _("OpenStack cloud deployment."))
def make_deploy(self):
self.deployment.set_started()
endpoints = self.deploy()
self.deployment.set_completed()
return endpoints
@utils.log_deploy_wrapper(LOG.info,
_("Destroy cloud and free allocated resources."))
@logging.log_deploy_wrapper(LOG.info, _("Destroy cloud and free "
"allocated resources."))
def make_cleanup(self):
self.deployment.update_status(consts.DeployStatus.CLEANUP_STARTED)
self.cleanup()

View File

@ -20,7 +20,6 @@ import six
from rally.common.i18n import _
from rally.common import log as logging
from rally.common import objects
from rally.common import utils
from rally import consts
from rally.deployment import engine
from rally.deployment.serverprovider import provider
@ -96,7 +95,7 @@ class DevstackEngine(engine.Engine):
if "local_conf" in self.config:
self.local_conf.update(self.config["local_conf"])
@utils.log_deploy_wrapper(LOG.info, _("Prepare server for devstack"))
@logging.log_deploy_wrapper(LOG.info, _("Prepare server for devstack"))
def prepare_server(self, server):
script_path = os.path.abspath(os.path.join(os.path.dirname(__file__),
"devstack", "install.sh"))
@ -104,7 +103,7 @@ class DevstackEngine(engine.Engine):
if server.password:
server.ssh.run("chpasswd", stdin="rally:%s" % server.password)
@utils.log_deploy_wrapper(LOG.info, _("Deploy devstack"))
@logging.log_deploy_wrapper(LOG.info, _("Deploy devstack"))
def deploy(self):
self.servers = self.get_provider().create_servers()
devstack_repo = self.config.get("devstack_repo", DEVSTACK_REPO)

View File

@ -21,7 +21,6 @@ import six
from rally.common.i18n import _
from rally.common import log as logging
from rally.common import objects
from rally.common import utils
from rally.deployment import engine
from rally.deployment.serverprovider import provider
from rally.deployment.serverprovider.providers import lxc
@ -111,7 +110,7 @@ class LxcEngine(engine.Engine):
return provider.ProviderFactory.get_provider(self.config["provider"],
self.deployment)
@utils.log_deploy_wrapper(LOG.info, _("Create containers on host"))
@logging.log_deploy_wrapper(LOG.info, _("Create containers on host"))
def deploy(self):
name = self.config["container_name"]
start_script = self.config.get("start_script",

View File

@ -23,7 +23,6 @@ from six import moves
from rally.common.i18n import _
from rally.common import log as logging
from rally.common import utils
from rally.deployment.serverprovider import provider
from rally import exceptions
@ -309,7 +308,7 @@ class LxcProvider(provider.ProviderFactory):
return provider.ProviderFactory.get_provider(
self.config["host_provider"], self.deployment)
@utils.log_deploy_wrapper(LOG.info, _("Create containers on host"))
@logging.log_deploy_wrapper(LOG.info, _("Create containers on host"))
def create_servers(self):
host_provider = self.get_host_provider()
name_prefix = self.config["container_name_prefix"]
@ -353,7 +352,7 @@ class LxcProvider(provider.ProviderFactory):
self.resources.create(info)
return servers
@utils.log_deploy_wrapper(LOG.info, _("Destroy host(s)"))
@logging.log_deploy_wrapper(LOG.info, _("Destroy host(s)"))
def destroy_servers(self):
for resource in self.resources.get_all():
server = provider.Server.from_credentials(resource["info"]["host"])

View File

@ -22,7 +22,6 @@ from rally.common.i18n import _
from rally.common import log as logging
from rally.common import objects
from rally.common.plugin import plugin
from rally.common import utils
from rally import consts
from rally import exceptions
@ -695,8 +694,8 @@ class Clients(object):
return self.cache["services_data"]
@classmethod
@utils.log_deprecated("Use rally.osclients.configure decorator instead.",
"0.1.2")
@logging.log_deprecated("Use rally.osclients.configure decorator instead.",
"0.1.2")
def register(cls, client_name):
"""DEPRECATED!Decorator that adds new OpenStack client dynamically.

View File

@ -63,7 +63,7 @@ class CeilometerSampleGenerator(context.Context):
"samples_per_resource": 5
}
@rutils.log_task_wrapper(LOG.info, _("Enter context: `Ceilometer`"))
@logging.log_task_wrapper(LOG.info, _("Enter context: `Ceilometer`"))
def setup(self):
counter_name = self.config["counter_name"]
counter_type = self.config["counter_type"]
@ -87,7 +87,7 @@ class CeilometerSampleGenerator(context.Context):
self.context["tenants"][tenant_id]["resources"].append(
sample[0].resource_id)
@rutils.log_task_wrapper(LOG.info, _("Exit context: `Ceilometer`"))
@logging.log_task_wrapper(LOG.info, _("Exit context: `Ceilometer`"))
def cleanup(self):
# We don't have API for removal of samples and resources
pass

View File

@ -49,7 +49,7 @@ class VolumeGenerator(context.Context):
"volumes_per_tenant": 1
}
@rutils.log_task_wrapper(LOG.info, _("Enter context: `Volumes`"))
@logging.log_task_wrapper(LOG.info, _("Enter context: `Volumes`"))
def setup(self):
size = self.config["size"]
volumes_per_tenant = self.config["volumes_per_tenant"]
@ -65,7 +65,7 @@ class VolumeGenerator(context.Context):
vol = cinder_util._create_volume(size, display_name=rnd_name)
self.context["tenants"][tenant_id]["volumes"].append(vol._info)
@rutils.log_task_wrapper(LOG.info, _("Exit context: `Volumes`"))
@logging.log_task_wrapper(LOG.info, _("Exit context: `Volumes`"))
def cleanup(self):
# TODO(boris-42): Delete only resources created by this context
resource_manager.cleanup(names=["cinder.volumes"],

View File

@ -17,7 +17,6 @@ import sys
from rally.common.i18n import _
from rally.common import log as logging
from rally.common import utils as rutils
from rally import consts
from rally import exceptions
from rally.plugins.openstack.context.cleanup import manager
@ -63,7 +62,7 @@ class AdminCleanup(CleanupMixin, context.Context):
% missing)
raise NoSuchCleanupResources(missing)
@rutils.log_task_wrapper(LOG.info, _("admin resources cleanup"))
@logging.log_task_wrapper(LOG.info, _("admin resources cleanup"))
def cleanup(self):
manager.cleanup(names=self.config,
admin_required=True,
@ -88,7 +87,7 @@ class UserCleanup(CleanupMixin, context.Context):
% missing)
raise NoSuchCleanupResources(missing)
@rutils.log_task_wrapper(LOG.info, _("user resources cleanup"))
@logging.log_task_wrapper(LOG.info, _("user resources cleanup"))
def cleanup(self):
manager.cleanup(names=self.config,
admin_required=False,

View File

@ -62,7 +62,7 @@ class EC2ServerGenerator(context.Context):
"additionalProperties": False
}
@rutils.log_task_wrapper(LOG.info, _("Enter context: `EC2 Servers`"))
@logging.log_task_wrapper(LOG.info, _("Enter context: `EC2 Servers`"))
def setup(self):
image = self.config["image"]
flavor = self.config["flavor"]
@ -92,7 +92,7 @@ class EC2ServerGenerator(context.Context):
self.context["tenants"][tenant_id]["ec2_servers"] = current_servers
@rutils.log_task_wrapper(LOG.info, _("Exit context: `EC2 Servers`"))
@logging.log_task_wrapper(LOG.info, _("Exit context: `EC2 Servers`"))
def cleanup(self):
resource_manager.cleanup(names=["ec2.servers"],
users=self.context.get("users", []))

View File

@ -17,7 +17,6 @@ import collections
from rally.common import broker
from rally.common.i18n import _
from rally.common import log as logging
from rally.common import utils as rutils
from rally import consts
from rally import exceptions
from rally.plugins.openstack.scenarios.fuel import utils as fuel_utils
@ -101,7 +100,8 @@ class FuelEnvGenerator(base.Context):
broker.run(publish, consume, threads)
self.context["fuel"] = {}
@rutils.log_task_wrapper(LOG.info, _("Enter context: `fuel_environments`"))
@logging.log_task_wrapper(LOG.info,
_("Enter context: `fuel_environments`"))
def setup(self):
"""Create Fuel environments, using the broker pattern."""
@ -122,7 +122,7 @@ class FuelEnvGenerator(base.Context):
msg=_("failed to create the requested"
" number of environments."))
@rutils.log_task_wrapper(LOG.info, _("Exit context: `fuel_environments`"))
@logging.log_task_wrapper(LOG.info, _("Exit context: `fuel_environments`"))
def cleanup(self):
"""Delete environments, using the broker pattern."""
self._delete_envs()

View File

@ -63,7 +63,7 @@ class ImageGenerator(context.Context):
"additionalProperties": False
}
@rutils.log_task_wrapper(LOG.info, _("Enter context: `Images`"))
@logging.log_task_wrapper(LOG.info, _("Enter context: `Images`"))
def setup(self):
image_url = self.config["image_url"]
image_type = self.config["image_type"]
@ -92,7 +92,7 @@ class ImageGenerator(context.Context):
self.context["tenants"][tenant_id]["images"] = current_images
@rutils.log_task_wrapper(LOG.info, _("Exit context: `Images`"))
@logging.log_task_wrapper(LOG.info, _("Exit context: `Images`"))
def cleanup(self):
# TODO(boris-42): Delete only resources created by this context
resource_manager.cleanup(names=["glance.images"],

View File

@ -70,7 +70,7 @@ class StackGenerator(context.Context):
template["resources"]["TestResource%d" % i] = rand_string
return template
@rutils.log_task_wrapper(LOG.info, _("Enter context: `Stacks`"))
@logging.log_task_wrapper(LOG.info, _("Enter context: `Stacks`"))
def setup(self):
template = self._prepare_stack_template(
self.config["resources_per_stack"])
@ -83,7 +83,7 @@ class StackGenerator(context.Context):
stack = heat_scenario._create_stack(template)
self.context["tenants"][tenant_id]["stacks"].append(stack.id)
@rutils.log_task_wrapper(LOG.info, _("Exit context: `Stacks`"))
@logging.log_task_wrapper(LOG.info, _("Exit context: `Stacks`"))
def cleanup(self):
resource_manager.cleanup(names=["heat.stacks"],
users=self.context.get("users", []))

View File

@ -16,7 +16,6 @@
from rally.common.i18n import _
from rally.common import log as logging
from rally.common import objects
from rally.common import utils as rutils
from rally import osclients
from rally.plugins.openstack.context.keystone import users
from rally.task import context
@ -44,7 +43,7 @@ class ExistingUsers(users.UserContextMixin, context.Context):
# this is used only by benchmark engine
CONFIG_SCHEMA = {}
@rutils.log_task_wrapper(LOG.info, _("Enter context: `existing_users`"))
@logging.log_task_wrapper(LOG.info, _("Enter context: `existing_users`"))
def setup(self):
self.context["users"] = []
self.context["tenants"] = {}
@ -65,6 +64,6 @@ class ExistingUsers(users.UserContextMixin, context.Context):
"tenant_id": user_kclient.tenant_id
})
@rutils.log_task_wrapper(LOG.info, _("Exit context: `existing_users`"))
@logging.log_task_wrapper(LOG.info, _("Exit context: `existing_users`"))
def cleanup(self):
"""These users are not managed by Rally, so don't touch them."""

View File

@ -15,7 +15,6 @@
from rally.common.i18n import _
from rally.common import log as logging
from rally.common import utils as rutils
from rally import consts
from rally import exceptions
from rally import osclients
@ -79,13 +78,13 @@ class RoleGenerator(context.Context):
user_id=user["id"], role_id=role["id"],
project_id=user["tenant_id"])
@rutils.log_task_wrapper(LOG.info, _("Enter context: `roles`"))
@logging.log_task_wrapper(LOG.info, _("Enter context: `roles`"))
def setup(self):
"""Add roles to all users."""
self.context["roles"] = [self._add_role(self.endpoint, name)
for name in self.config]
@rutils.log_task_wrapper(LOG.info, _("Exit context: `roles`"))
@logging.log_task_wrapper(LOG.info, _("Exit context: `roles`"))
def cleanup(self):
"""Remove roles from users."""
for role in self.context["roles"]:

View File

@ -266,7 +266,7 @@ class UserGenerator(UserContextMixin, context.Context):
broker.run(publish, consume, threads)
self.context["users"] = []
@rutils.log_task_wrapper(LOG.info, _("Enter context: `users`"))
@logging.log_task_wrapper(LOG.info, _("Enter context: `users`"))
def setup(self):
"""Create tenants and users, using the broker pattern."""
self.context["users"] = []
@ -293,7 +293,7 @@ class UserGenerator(UserContextMixin, context.Context):
ctx_name=self.get_name(),
msg=_("Failed to create the requested number of users."))
@rutils.log_task_wrapper(LOG.info, _("Exit context: `users`"))
@logging.log_task_wrapper(LOG.info, _("Exit context: `users`"))
def cleanup(self):
"""Delete tenants and users, using the broker pattern."""
self._remove_default_security_group()

View File

@ -124,7 +124,7 @@ class ManilaShareNetworks(context.Context):
self.context["tenants"][tenant_id][CONTEXT_NAME]["sn_iterator"] = (
utils.RAMInt())
@utils.log_task_wrapper(LOG.info, _("Enter context: `%s`") % CONTEXT_NAME)
@log.log_task_wrapper(LOG.info, _("Enter context: `%s`") % CONTEXT_NAME)
def setup(self):
self.context[CONTEXT_NAME] = {}
if not self.config["use_share_networks"]:
@ -135,7 +135,7 @@ class ManilaShareNetworks(context.Context):
# TODO(vponomaryov): add support of autocreated resources
pass
@utils.log_task_wrapper(LOG.info, _("Exit context: `%s`") % CONTEXT_NAME)
@log.log_task_wrapper(LOG.info, _("Exit context: `%s`") % CONTEXT_NAME)
def cleanup(self):
# TODO(vponomaryov): add cleanup for autocreated resources when appear.
return

View File

@ -47,7 +47,7 @@ class PackageGenerator(context.Context):
"additionalProperties": False
}
@utils.log_task_wrapper(LOG.info, _("Enter context: `Murano packages`"))
@logging.log_task_wrapper(LOG.info, _("Enter context: `Murano packages`"))
def setup(self):
is_config_app_dir = False
pckg_path = os.path.expanduser(self.config["app_package"])
@ -74,7 +74,7 @@ class PackageGenerator(context.Context):
self.context["tenants"][tenant_id]["packages"].append(package)
@utils.log_task_wrapper(LOG.info, _("Exit context: `Murano packages`"))
@logging.log_task_wrapper(LOG.info, _("Exit context: `Murano packages`"))
def cleanup(self):
resource_manager.cleanup(names=["murano.packages"],
users=self.context.get("users", []))

View File

@ -87,7 +87,7 @@ def _prepare_open_secgroup(endpoint, secgroup_name):
class AllowSSH(context.Context):
"""Sets up security groups for all users to access VM via SSH."""
@utils.log_task_wrapper(LOG.info, _("Enter context: `allow_ssh`"))
@logging.log_task_wrapper(LOG.info, _("Enter context: `allow_ssh`"))
def setup(self):
admin_or_user = (self.context.get("admin") or
self.context.get("users")[0])
@ -106,7 +106,7 @@ class AllowSSH(context.Context):
user["secgroup"] = _prepare_open_secgroup(user["endpoint"],
secgroup_name)
@utils.log_task_wrapper(LOG.info, _("Exit context: `allow_ssh`"))
@logging.log_task_wrapper(LOG.info, _("Exit context: `allow_ssh`"))
def cleanup(self):
for user, tenant_id in utils.iterate_per_tenants(
self.context["users"]):

View File

@ -38,7 +38,7 @@ class ExistingNetwork(context.Context):
"additionalProperties": False
}
@utils.log_task_wrapper(LOG.info, _("Enter context: `existing_network`"))
@logging.log_task_wrapper(LOG.info, _("Enter context: `existing_network`"))
def setup(self):
for user, tenant_id in utils.iterate_per_tenants(
self.context.get("users", [])):
@ -49,6 +49,6 @@ class ExistingNetwork(context.Context):
self.context["tenants"][tenant_id]["networks"] = (
net_wrapper.list_networks())
@utils.log_task_wrapper(LOG.info, _("Exit context: `existing_network`"))
@logging.log_task_wrapper(LOG.info, _("Exit context: `existing_network`"))
def cleanup(self):
"""Networks were not created by Rally, so nothing to do."""

View File

@ -59,7 +59,7 @@ class Network(context.Context):
"network_create_args": {}
}
@utils.log_task_wrapper(LOG.info, _("Enter context: `network`"))
@logging.log_task_wrapper(LOG.info, _("Enter context: `network`"))
def setup(self):
# NOTE(rkiran): Some clients are not thread-safe. Thus during
# multithreading/multiprocessing, it is likely the
@ -81,7 +81,7 @@ class Network(context.Context):
network_create_args=self.config["network_create_args"])
self.context["tenants"][tenant_id]["networks"].append(network)
@utils.log_task_wrapper(LOG.info, _("Exit context: `network`"))
@logging.log_task_wrapper(LOG.info, _("Exit context: `network`"))
def cleanup(self):
net_wrapper = network_wrapper.wrap(
osclients.Clients(self.context["admin"]["endpoint"]),

View File

@ -49,7 +49,7 @@ class Lbaas(context.Context):
"lbaas_version": 1
}
@utils.log_task_wrapper(LOG.info, _("Enter context: `lbaas`"))
@logging.log_task_wrapper(LOG.info, _("Enter context: `lbaas`"))
def setup(self):
net_wrapper = network_wrapper.wrap(
osclients.Clients(self.context["admin"]["endpoint"]),
@ -76,7 +76,7 @@ class Lbaas(context.Context):
"Context for LBaaS version %s not implemented."
% self.config["lbaas_version"])
@utils.log_task_wrapper(LOG.info, _("Exit context: `lbaas`"))
@logging.log_task_wrapper(LOG.info, _("Exit context: `lbaas`"))
def cleanup(self):
net_wrapper = network_wrapper.wrap(
osclients.Clients(self.context["admin"]["endpoint"]),

View File

@ -19,7 +19,6 @@ import tempfile
from rally.common.i18n import _
from rally.common import log as logging
from rally.common import utils
from rally import consts
from rally import exceptions
from rally.task import context
@ -48,7 +47,7 @@ class Tempest(context.Context):
tempest_config=self.config.get(
"tempest-config"))
@utils.log_task_wrapper(LOG.info, _("Enter context: `tempest`"))
@logging.log_task_wrapper(LOG.info, _("Enter context: `tempest`"))
def setup(self):
self.verifier.log_file_raw = "/dev/null"
# Create temporary directory for subunit-results.
@ -71,7 +70,7 @@ class Tempest(context.Context):
self.context["verifier"] = self.verifier
@utils.log_task_wrapper(LOG.info, _("Exit context: `tempest`"))
@logging.log_task_wrapper(LOG.info, _("Exit context: `tempest`"))
def cleanup(self):
LOG.info("Built-in stress cleanup from Tempest looks like can help to "
"shot yourself in the foot. Sorry, but even Rally can not "

View File

@ -70,7 +70,7 @@ class FlavorsGenerator(context.Context):
}
}
@rutils.log_task_wrapper(LOG.info, _("Enter context: `flavors`"))
@logging.log_task_wrapper(LOG.info, _("Enter context: `flavors`"))
def setup(self):
"""Create list of flavors."""
self.context["flavors"] = {}
@ -96,7 +96,7 @@ class FlavorsGenerator(context.Context):
self.context["flavors"][flavor_config["name"]] = flavor.to_dict()
LOG.debug("Created flavor with id '%s'" % flavor.id)
@rutils.log_task_wrapper(LOG.info, _("Exit context: `flavors`"))
@logging.log_task_wrapper(LOG.info, _("Exit context: `flavors`"))
def cleanup(self):
"""Delete created flavors."""
clients = osclients.Clients(self.context["admin"]["endpoint"])

View File

@ -17,7 +17,6 @@ import novaclient.exceptions
from rally.common.i18n import _
from rally.common import log as logging
from rally.common import utils
from rally import osclients
from rally.plugins.openstack.context.cleanup import manager as resource_manager
from rally.task import context
@ -47,12 +46,12 @@ class Keypair(context.Context):
"name": keypair_name,
"id": keypair.id}
@utils.log_task_wrapper(LOG.info, _("Enter context: `keypair`"))
@logging.log_task_wrapper(LOG.info, _("Enter context: `keypair`"))
def setup(self):
for user in self.context["users"]:
user["keypair"] = self._generate_keypair(user["endpoint"])
@utils.log_task_wrapper(LOG.info, _("Exit context: `keypair`"))
@logging.log_task_wrapper(LOG.info, _("Exit context: `keypair`"))
def cleanup(self):
# TODO(boris-42): Delete only resources created by this context
resource_manager.cleanup(names=["nova.keypairs"],

View File

@ -70,7 +70,7 @@ class ServerGenerator(context.Context):
"auto_assign_nic": False
}
@rutils.log_task_wrapper(LOG.info, _("Enter context: `Servers`"))
@logging.log_task_wrapper(LOG.info, _("Enter context: `Servers`"))
def setup(self):
image = self.config["image"]
flavor = self.config["flavor"]
@ -112,7 +112,7 @@ class ServerGenerator(context.Context):
self.context["tenants"][tenant_id][
"servers"] = current_servers
@rutils.log_task_wrapper(LOG.info, _("Exit context: `Servers`"))
@logging.log_task_wrapper(LOG.info, _("Exit context: `Servers`"))
def cleanup(self):
resource_manager.cleanup(names=["nova.servers"],
users=self.context.get("users", []))

View File

@ -15,7 +15,6 @@
from rally.common.i18n import _
from rally.common import log as logging
from rally.common import utils
from rally import consts
from rally import osclients
from rally.plugins.openstack.context.quotas import cinder_quotas
@ -61,7 +60,7 @@ class Quotas(context.Context):
def _service_has_quotas(self, service):
return len(self.config.get(service, {})) > 0
@utils.log_task_wrapper(LOG.info, _("Enter context: `quotas`"))
@logging.log_task_wrapper(LOG.info, _("Enter context: `quotas`"))
def setup(self):
for tenant_id in self.context["tenants"]:
for service in self.manager:
@ -69,7 +68,7 @@ class Quotas(context.Context):
self.manager[service].update(tenant_id,
**self.config[service])
@utils.log_task_wrapper(LOG.info, _("Exit context: `quotas`"))
@logging.log_task_wrapper(LOG.info, _("Exit context: `quotas`"))
def cleanup(self):
for service in self.manager:
if self._service_has_quotas(service):

View File

@ -89,7 +89,7 @@ class SaharaCluster(context.Context):
"flavor_id"]
}
@rutils.log_task_wrapper(LOG.info, _("Enter context: `Sahara Cluster`"))
@logging.log_task_wrapper(LOG.info, _("Enter context: `Sahara Cluster`"))
def setup(self):
self.context["sahara_clusters"] = {}
@ -160,7 +160,7 @@ class SaharaCluster(context.Context):
return False
return True
@rutils.log_task_wrapper(LOG.info, _("Exit context: `Sahara Cluster`"))
@logging.log_task_wrapper(LOG.info, _("Exit context: `Sahara Cluster`"))
def cleanup(self):
# TODO(boris-42): Delete only resources created by this context

View File

@ -51,8 +51,8 @@ class SaharaDataSources(context.Context):
"output_type", "output_url_prefix"]
}
@rutils.log_task_wrapper(LOG.info,
_("Enter context: `Sahara Data Sources`"))
@logging.log_task_wrapper(LOG.info,
_("Enter context: `Sahara Data Sources`"))
def setup(self):
self.context["sahara_output_conf"] = {
"output_type": self.config["output_type"],
@ -79,7 +79,7 @@ class SaharaDataSources(context.Context):
self.context["tenants"][tenant_id]["sahara_input"] = input_ds.id
@rutils.log_task_wrapper(LOG.info, _("Exit context: `Sahara EDP`"))
@logging.log_task_wrapper(LOG.info, _("Exit context: `Sahara EDP`"))
def cleanup(self):
resources = ["job_executions", "jobs", "data_sources"]

View File

@ -73,7 +73,7 @@ class SaharaImage(context.Context):
image_id=image.id, new_tags=[plugin_name, hadoop_version])
return image.id
@rutils.log_task_wrapper(LOG.info, _("Enter context: `Sahara Image`"))
@logging.log_task_wrapper(LOG.info, _("Enter context: `Sahara Image`"))
def setup(self):
self.context["sahara_images"] = {}
@ -111,7 +111,7 @@ class SaharaImage(context.Context):
self.context["tenants"][tenant_id]["sahara_image"] = image_id
@rutils.log_task_wrapper(LOG.info, _("Exit context: `Sahara Image`"))
@logging.log_task_wrapper(LOG.info, _("Exit context: `Sahara Image`"))
def cleanup(self):
# TODO(boris-42): Delete only resources created by this context

View File

@ -76,8 +76,8 @@ class SaharaJobBinaries(context.Context):
# downloads for each tenant
lib_cache = {}
@rutils.log_task_wrapper(LOG.info,
_("Enter context: `Sahara Job Binaries`"))
@logging.log_task_wrapper(LOG.info,
_("Enter context: `Sahara Job Binaries`"))
def setup(self):
for user, tenant_id in rutils.iterate_per_tenants(
@ -138,8 +138,8 @@ class SaharaJobBinaries(context.Context):
self.context["tenants"][tenant_id][lib_type].append(job_binary.id)
@rutils.log_task_wrapper(LOG.info,
_("Exit context: `Sahara Job Binaries`"))
@logging.log_task_wrapper(LOG.info,
_("Exit context: `Sahara Job Binaries`"))
def cleanup(self):
resources = ["job_binary_internals", "job_binaries"]

View File

@ -15,7 +15,6 @@
from rally.common.i18n import _
from rally.common import log as logging
from rally.common import utils as rutils
from rally import consts
from rally import exceptions
from rally.plugins.openstack.context.swift import utils as swift_utils
@ -57,7 +56,7 @@ class SwiftObjectGenerator(swift_utils.SwiftObjectMixin, context.Context):
"resource_management_workers": 30
}
@rutils.log_task_wrapper(LOG.info, _("Enter context: `swift_objects`"))
@logging.log_task_wrapper(LOG.info, _("Enter context: `swift_objects`"))
def setup(self):
"""Create containers and objects, using the broker pattern."""
threads = self.config["resource_management_workers"]
@ -91,7 +90,7 @@ class SwiftObjectGenerator(swift_utils.SwiftObjectMixin, context.Context):
"expected %(expected)s but got %(actual)s.")
% {"expected": objects_num, "actual": objects_count})
@rutils.log_task_wrapper(LOG.info, _("Exit context: `swift_objects`"))
@logging.log_task_wrapper(LOG.info, _("Exit context: `swift_objects`"))
def cleanup(self):
"""Delete containers and objects, using the broker pattern."""
threads = self.config["resource_management_workers"]

View File

@ -105,7 +105,7 @@ class BaseCustomImageGenerator(context.Context):
"workers": 1
}
@utils.log_task_wrapper(LOG.info, _("Enter context: `custom_image`"))
@logging.log_task_wrapper(LOG.info, _("Enter context: `custom_image`"))
def setup(self):
"""Creates custom image(s) with preinstalled applications.
@ -185,7 +185,7 @@ class BaseCustomImageGenerator(context.Context):
admin_clients.glance().images.get(
custom_image["id"]).update(is_public=True)
@utils.log_task_wrapper(LOG.info, _("Exit context: `custom_image`"))
@logging.log_task_wrapper(LOG.info, _("Exit context: `custom_image`"))
def cleanup(self):
"""Delete created custom image(s)."""
@ -225,8 +225,8 @@ class BaseCustomImageGenerator(context.Context):
custom_image["id"])
nova_scenario._delete_image(custom_image)
@utils.log_task_wrapper(LOG.info,
_("Custom image context: customizing"))
@logging.log_task_wrapper(LOG.info,
_("Custom image context: customizing"))
def customize_image(self, server, ip, user):
return self._customize_image(server, ip, user)

View File

@ -16,7 +16,6 @@
import random
from rally.common import log as logging
from rally.common import utils
from rally import consts
from rally import exceptions
from rally.plugins.openstack import scenario
@ -349,8 +348,8 @@ class CinderVolumes(cinder_utils.CinderScenario,
@validation.required_services(consts.Service.NOVA, consts.Service.CINDER)
@validation.required_openstack(users=True)
@scenario.configure(context={"cleanup": ["cinder", "nova"]})
@utils.log_deprecated_args("Use 'nested_level' as an int", "0.1.2",
["nested_level"], once=True)
@logging.log_deprecated_args("Use 'nested_level' as an int", "0.1.2",
["nested_level"], once=True)
def create_nested_snapshots_and_attach_volume(self,
size=None,
nested_level=None,

View File

@ -13,7 +13,7 @@
# License for the specific language governing permissions and limitations
# under the License.
from rally.common import utils
from rally.common import log as logging
from rally.plugins.openstack import scenario
from rally.plugins.openstack.scenarios.keystone import utils as kutils
from rally.task import validation
@ -24,7 +24,7 @@ class KeystoneBasic(kutils.KeystoneScenario):
@validation.required_openstack(admin=True)
@scenario.configure(context={"admin_cleanup": ["keystone"]})
@utils.log_deprecated_args(
@logging.log_deprecated_args(
"The 'name_length' argument to create_user is ignored",
"0.1.2", ["name_length"], once=True)
def create_user(self, name_length=10, **kwargs):
@ -37,7 +37,7 @@ class KeystoneBasic(kutils.KeystoneScenario):
@validation.required_openstack(admin=True)
@scenario.configure(context={"admin_cleanup": ["keystone"]})
@utils.log_deprecated_args(
@logging.log_deprecated_args(
"The 'name_length' argument to create_delete_user is ignored",
"0.1.2", ["name_length"], once=True)
def create_delete_user(self, name_length=10, **kwargs):
@ -65,7 +65,7 @@ class KeystoneBasic(kutils.KeystoneScenario):
@validation.required_openstack(admin=True)
@scenario.configure(context={"admin_cleanup": ["keystone"]})
@utils.log_deprecated_args(
@logging.log_deprecated_args(
"The 'name_length' argument to create_tenant is ignored",
"0.1.2", ["name_length"], once=True)
def create_tenant(self, name_length=10, **kwargs):
@ -78,7 +78,7 @@ class KeystoneBasic(kutils.KeystoneScenario):
@validation.number("users_per_tenant", minval=1)
@validation.required_openstack(admin=True)
@scenario.configure(context={"admin_cleanup": ["keystone"]})
@utils.log_deprecated_args(
@logging.log_deprecated_args(
"The 'name_length' argument to create_tenant_with_users is ignored",
"0.1.2", ["name_length"], once=True)
def create_tenant_with_users(self, users_per_tenant, name_length=10,
@ -94,7 +94,7 @@ class KeystoneBasic(kutils.KeystoneScenario):
@validation.required_openstack(admin=True)
@scenario.configure(context={"admin_cleanup": ["keystone"]})
@utils.log_deprecated_args(
@logging.log_deprecated_args(
"The 'name_length' argument to create_and_list_users is ignored",
"0.1.2", ["name_length"], once=True)
def create_and_list_users(self, name_length=10, **kwargs):
@ -108,7 +108,7 @@ class KeystoneBasic(kutils.KeystoneScenario):
@validation.required_openstack(admin=True)
@scenario.configure(context={"admin_cleanup": ["keystone"]})
@utils.log_deprecated_args(
@logging.log_deprecated_args(
"The 'name_length' argument to create_and_list_tenants is ignored",
"0.1.2", ["name_length"], once=True)
def create_and_list_tenants(self, name_length=10, **kwargs):
@ -175,7 +175,7 @@ class KeystoneBasic(kutils.KeystoneScenario):
self._get_service(service.id)
@validation.required_openstack(admin=True)
@utils.log_deprecated_args(
@logging.log_deprecated_args(
"The 'name' argument to create_and_delete_service will be ignored",
"0.0.5", ["name"])
@scenario.configure(context={"admin_cleanup": ["keystone"]})
@ -191,7 +191,7 @@ class KeystoneBasic(kutils.KeystoneScenario):
@validation.required_openstack(admin=True)
@scenario.configure(context={"admin_cleanup": ["keystone"]})
@utils.log_deprecated_args(
@logging.log_deprecated_args(
"The 'name_length' argument to create_update_and_delete_tenant is "
"ignored", "0.1.2", ["name_length"], once=True)
def create_update_and_delete_tenant(self, name_length=None, **kwargs):
@ -205,7 +205,7 @@ class KeystoneBasic(kutils.KeystoneScenario):
@validation.required_openstack(admin=True)
@scenario.configure(context={"admin_cleanup": ["keystone"]})
@utils.log_deprecated_args(
@logging.log_deprecated_args(
"The 'name_length' and 'password_length' arguments to "
"create_user_update_password are ignored",
"0.1.2", ["name_length", "password_length"], once=True)
@ -217,7 +217,7 @@ class KeystoneBasic(kutils.KeystoneScenario):
self._update_user_password(user.id, password)
@validation.required_openstack(admin=True)
@utils.log_deprecated_args(
@logging.log_deprecated_args(
"The 'name' argument to create_and_list_services will be ignored",
"0.0.5", ["name"])
@scenario.configure(context={"admin_cleanup": ["keystone"]})

View File

@ -13,7 +13,7 @@
# License for the specific language governing permissions and limitations
# under the License.
from rally.common import utils as rutils
from rally.common import log as logging
from rally import consts
from rally.plugins.openstack import scenario
from rally.plugins.openstack.scenarios.manila import utils
@ -65,7 +65,7 @@ class ManilaShares(utils.ManilaScenario):
@validation.required_services(consts.Service.MANILA)
@validation.required_openstack(users=True)
@scenario.configure(context={"cleanup": ["manila"]})
@rutils.log_deprecated_args(
@logging.log_deprecated_args(
"The 'name' argument to create_and_delete_service will be ignored",
"1.1.2", ["name"], once=True)
def create_share_network_and_delete(self,
@ -92,7 +92,7 @@ class ManilaShares(utils.ManilaScenario):
@validation.required_services(consts.Service.MANILA)
@validation.required_openstack(users=True)
@scenario.configure(context={"cleanup": ["manila"]})
@rutils.log_deprecated_args(
@logging.log_deprecated_args(
"The 'name' argument to create_and_delete_service will be ignored",
"1.1.2", ["name"], once=True)
def create_share_network_and_list(self,
@ -141,7 +141,7 @@ class ManilaShares(utils.ManilaScenario):
@validation.required_services(consts.Service.MANILA)
@validation.required_openstack(users=True)
@scenario.configure(context={"cleanup": ["manila"]})
@rutils.log_deprecated_args(
@logging.log_deprecated_args(
"The 'name' argument to create_and_delete_service will be ignored",
"1.1.2", ["name"], once=True)
def create_security_service_and_delete(self, security_service_type,

View File

@ -15,7 +15,7 @@
import json
from rally.common import utils
from rally.common import log as logging
from rally import consts
from rally import exceptions
from rally.plugins.openstack import scenario
@ -33,8 +33,8 @@ class VMTasks(vm_utils.VMScenario):
@types.set(image=types.ImageResourceType,
flavor=types.FlavorResourceType)
@validation.image_valid_on_flavor("flavor", "image")
@utils.log_deprecated_args("Use `command' argument instead", "0.0.5",
("script", "interpreter"), once=True)
@logging.log_deprecated_args("Use `command' argument instead", "0.0.5",
("script", "interpreter"), once=True)
@validation.file_exists("script", required=False)
@validation.valid_command("command", required=False)
@validation.number("port", minval=1, maxval=65535, nullable=True,

View File

@ -14,7 +14,7 @@
import random
from rally.common import utils
from rally.common import log as logging
from rally.plugins.openstack import scenario
from rally.plugins.openstack.scenarios.zaqar import utils as zutils
@ -23,7 +23,7 @@ class ZaqarBasic(zutils.ZaqarScenario):
"""Benchmark scenarios for Zaqar."""
@scenario.configure(context={"cleanup": ["zaqar"]})
@utils.log_deprecated_args(
@logging.log_deprecated_args(
"The 'name_length' argument to create_queue is ignored",
"0.1.2", ["name_length"], once=True)
def create_queue(self, name_length=None, **kwargs):
@ -35,7 +35,7 @@ class ZaqarBasic(zutils.ZaqarScenario):
self._queue_create(**kwargs)
@scenario.configure(context={"cleanup": ["zaqar"]})
@utils.log_deprecated_args(
@logging.log_deprecated_args(
"The 'name_length' argument to producer_consumer is ignored",
"0.1.2", ["name_length"], once=True)
def producer_consumer(self, name_length=None,

View File

@ -25,7 +25,6 @@ import six
from rally.common.i18n import _
from rally.common import log as logging
from rally.common import objects
from rally.common import utils as rutils
from rally import consts
from rally import exceptions
from rally import osclients
@ -185,13 +184,13 @@ class BenchmarkEngine(object):
self.existing_users = users or []
self.abort_on_sla_failure = abort_on_sla_failure
@rutils.log_task_wrapper(LOG.info, _("Task validation check cloud."))
@logging.log_task_wrapper(LOG.info, _("Task validation check cloud."))
def _check_cloud(self):
clients = osclients.Clients(self.admin)
clients.verified_keystone()
@rutils.log_task_wrapper(LOG.info,
_("Task validation of scenarios names."))
@logging.log_task_wrapper(LOG.info,
_("Task validation of scenarios names."))
def _validate_config_scenarios_name(self, config):
available = set(s.get_name() for s in scenario.Scenario.get_all())
@ -204,7 +203,7 @@ class BenchmarkEngine(object):
names = ", ".join(specified - available)
raise exceptions.NotFoundScenarios(names=names)
@rutils.log_task_wrapper(LOG.info, _("Task validation of syntax."))
@logging.log_task_wrapper(LOG.info, _("Task validation of syntax."))
def _validate_config_syntax(self, config):
for subtask in config.subtasks:
for pos, scenario_obj in enumerate(subtask.scenarios):
@ -241,7 +240,7 @@ class BenchmarkEngine(object):
return user_context
@rutils.log_task_wrapper(LOG.info, _("Task validation of semantic."))
@logging.log_task_wrapper(LOG.info, _("Task validation of semantic."))
def _validate_config_semantic(self, config):
self._check_cloud()
@ -266,7 +265,7 @@ class BenchmarkEngine(object):
admin, user, scenario_obj["name"],
pos, deployment, scenario_obj)
@rutils.log_task_wrapper(LOG.info, _("Task validation."))
@logging.log_task_wrapper(LOG.info, _("Task validation."))
def validate(self):
"""Perform full task configuration validation."""
self.task.update_status(consts.TaskStatus.VERIFYING)
@ -301,7 +300,7 @@ class BenchmarkEngine(object):
return context_obj
@rutils.log_task_wrapper(LOG.info, _("Benchmarking."))
@logging.log_task_wrapper(LOG.info, _("Benchmarking."))
def run(self):
"""Run the benchmark according to the test configuration.

View File

@ -23,7 +23,6 @@ import six
from rally.common.i18n import _
from rally.common import log as logging
from rally.common import utils
from rally import consts
from rally import exceptions
@ -101,7 +100,7 @@ def manager_list_size(sizes):
return _list
@utils.log_deprecated("Use wait_for_status instead.", "0.1.2", once=True)
@logging.log_deprecated("Use wait_for_status instead.", "0.1.2", once=True)
def wait_for(resource, is_ready=None, ready_statuses=None,
failure_statuses=None, status_attr="status", update_resource=None,
timeout=60, check_interval=1):
@ -148,7 +147,7 @@ def wait_for(resource, is_ready=None, ready_statuses=None,
check_interval=check_interval)
@utils.log_deprecated("Use wait_for_status instead.", "0.1.2", once=True)
@logging.log_deprecated("Use wait_for_status instead.", "0.1.2", once=True)
def wait_is_ready(resource, is_ready, update_resource=None,
timeout=60, check_interval=1):
@ -247,7 +246,7 @@ def wait_for_status(resource, ready_statuses, failure_statuses=None,
resource_status=get_status(resource))
@utils.log_deprecated("Use wait_for_status instead.", "0.1.2", once=True)
@logging.log_deprecated("Use wait_for_status instead.", "0.1.2", once=True)
def wait_for_delete(resource, update_resource=None, timeout=60,
check_interval=1):
"""Wait for the full deletion of resource.

View File

@ -26,7 +26,6 @@ from oslo_utils import encodeutils
from rally.common import costilius
from rally.common.i18n import _
from rally.common import log as logging
from rally.common import utils
from rally import consts
from rally import exceptions
from rally.verification.tempest import config
@ -293,7 +292,7 @@ class Tempest(object):
if os.path.exists(self.path()):
shutil.rmtree(self.path())
@utils.log_verification_wrapper(LOG.info, _("Run verification."))
@logging.log_verification_wrapper(LOG.info, _("Run verification."))
def _prepare_and_run(self, set_name, regex, tests_file):
if not self.is_configured():
self.generate_config_file()
@ -385,7 +384,7 @@ class Tempest(object):
LOG.error("JSON-log file not found.")
return None, None
@utils.log_verification_wrapper(
@logging.log_verification_wrapper(
LOG.info, _("Saving verification results."))
def _save_results(self, log_file=None):
total, test_cases = self.parse_results(log_file)

View File

@ -0,0 +1,87 @@
#
# 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 mock
from rally.common.i18n import _
from rally.common import log as logging
from tests.unit import test
class LogTestCase(test.TestCase):
def test_log_task_wrapper(self):
mock_log = mock.MagicMock()
msg = "test %(a)s %(b)s"
class TaskLog(object):
def __init__(self):
self.task = {"uuid": "some_uuid"}
@logging.log_task_wrapper(mock_log, msg, a=10, b=20)
def some_method(self, x, y):
return x + y
t = TaskLog()
self.assertEqual(t.some_method.__name__, "some_method")
self.assertEqual(t.some_method(2, 2), 4)
params = {"msg": msg % {"a": 10, "b": 20}, "uuid": t.task["uuid"]}
expected = [
mock.call(_("Task %(uuid)s | Starting: %(msg)s") % params),
mock.call(_("Task %(uuid)s | Completed: %(msg)s") % params)
]
self.assertEqual(mock_log.mock_calls, expected)
def test_log_deprecated(self):
mock_log = mock.MagicMock()
@logging.log_deprecated("some alternative", "0.0.1", mock_log)
def some_method(x, y):
return x + y
self.assertEqual(some_method(2, 2), 4)
mock_log.assert_called_once_with("'some_method' is deprecated in "
"Rally v0.0.1: some alternative")
def test_log_deprecated_args(self):
mock_log = mock.MagicMock()
@logging.log_deprecated_args("Deprecated test", "0.0.1", ("z",),
mock_log, once=True)
def some_method(x, y, z):
return x + y + z
self.assertEqual(some_method(2, 2, z=3), 7)
mock_log.assert_called_once_with(
"Deprecated test (args `z' deprecated in Rally v0.0.1)")
mock_log.reset_mock()
self.assertEqual(some_method(2, 2, z=3), 7)
self.assertFalse(mock_log.called)
@logging.log_deprecated_args("Deprecated test", "0.0.1", ("z",),
mock_log, once=False)
def some_method(x, y, z):
return x + y + z
self.assertEqual(some_method(2, 2, z=3), 7)
mock_log.assert_called_once_with(
"Deprecated test (args `z' deprecated in Rally v0.0.1)")
mock_log.reset_mock()
self.assertEqual(some_method(2, 2, z=3), 7)
mock_log.assert_called_once_with(
"Deprecated test (args `z' deprecated in Rally v0.0.1)")

View File

@ -22,7 +22,6 @@ import ddt
import mock
import testtools
from rally.common.i18n import _
from rally.common import utils
from rally import exceptions
from tests.unit import test
@ -116,73 +115,6 @@ class TimerTestCase(test.TestCase):
self.assertEqual(timer.error[0], type(Exception()))
class LogTestCase(test.TestCase):
def test_log_task_wrapper(self):
mock_log = mock.MagicMock()
msg = "test %(a)s %(b)s"
class TaskLog(object):
def __init__(self):
self.task = {"uuid": "some_uuid"}
@utils.log_task_wrapper(mock_log, msg, a=10, b=20)
def some_method(self, x, y):
return x + y
t = TaskLog()
self.assertEqual(t.some_method.__name__, "some_method")
self.assertEqual(t.some_method(2, 2), 4)
params = {"msg": msg % {"a": 10, "b": 20}, "uuid": t.task["uuid"]}
expected = [
mock.call(_("Task %(uuid)s | Starting: %(msg)s") % params),
mock.call(_("Task %(uuid)s | Completed: %(msg)s") % params)
]
self.assertEqual(mock_log.mock_calls, expected)
def test_log_deprecated(self):
mock_log = mock.MagicMock()
@utils.log_deprecated("some alternative", "0.0.1", mock_log)
def some_method(x, y):
return x + y
self.assertEqual(some_method(2, 2), 4)
mock_log.assert_called_once_with("'some_method' is deprecated in "
"Rally v0.0.1: some alternative")
def test_log_deprecated_args(self):
mock_log = mock.MagicMock()
@utils.log_deprecated_args("Deprecated test", "0.0.1", ("z",),
mock_log, once=True)
def some_method(x, y, z):
return x + y + z
self.assertEqual(some_method(2, 2, z=3), 7)
mock_log.assert_called_once_with(
"Deprecated test (args `z' deprecated in Rally v0.0.1)")
mock_log.reset_mock()
self.assertEqual(some_method(2, 2, z=3), 7)
self.assertFalse(mock_log.called)
@utils.log_deprecated_args("Deprecated test", "0.0.1", ("z",),
mock_log, once=False)
def some_method(x, y, z):
return x + y + z
self.assertEqual(some_method(2, 2, z=3), 7)
mock_log.assert_called_once_with(
"Deprecated test (args `z' deprecated in Rally v0.0.1)")
mock_log.reset_mock()
self.assertEqual(some_method(2, 2, z=3), 7)
mock_log.assert_called_once_with(
"Deprecated test (args `z' deprecated in Rally v0.0.1)")
def module_level_method():
pass

View File

@ -15,8 +15,7 @@
import mock
from rally.common import log
from rally.common import utils
from rally.common import log as logging
from rally import exceptions
from rally.plugins.openstack.scenarios.vm import vmtasks
from tests.unit import test
@ -40,7 +39,7 @@ class VMTasksTestCase(test.ScenarioTestCase):
return_value=(0, "\"foo_out\"", "foo_err"))
def test_boot_runcommand_delete(self):
with log.LogCatcher(utils.LOG) as catcher:
with logging.LogCatcher(logging.LOG) as catcher:
self.scenario.boot_runcommand_delete(
"foo_image", "foo_flavor",
script="foo_script", interpreter="foo_interpreter",