diff --git a/rally/common/log.py b/rally/common/log.py index 166494a8c8..e5259723cc 100644 --- a/rally/common/log.py +++ b/rally/common/log.py @@ -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 | Starting: " + [Method execution...] + "Task | Completed: " + + :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 diff --git a/rally/common/utils.py b/rally/common/utils.py index d02357dc31..13bd7ceaf6 100644 --- a/rally/common/utils.py +++ b/rally/common/utils.py @@ -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 | Starting: " - [Method execution...] - "Task | Completed: " - - :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. diff --git a/rally/deployment/engine.py b/rally/deployment/engine.py index 3900bbb808..cee5e4cea6 100644 --- a/rally/deployment/engine.py +++ b/rally/deployment/engine.py @@ -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() diff --git a/rally/deployment/engines/devstack.py b/rally/deployment/engines/devstack.py index 6d8f134e50..9726ece805 100644 --- a/rally/deployment/engines/devstack.py +++ b/rally/deployment/engines/devstack.py @@ -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) diff --git a/rally/deployment/engines/lxc.py b/rally/deployment/engines/lxc.py index eaeaf410ed..c1d097e126 100644 --- a/rally/deployment/engines/lxc.py +++ b/rally/deployment/engines/lxc.py @@ -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", diff --git a/rally/deployment/serverprovider/providers/lxc.py b/rally/deployment/serverprovider/providers/lxc.py index 22a8d77667..1123e0dffd 100644 --- a/rally/deployment/serverprovider/providers/lxc.py +++ b/rally/deployment/serverprovider/providers/lxc.py @@ -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"]) diff --git a/rally/osclients.py b/rally/osclients.py index d19346676b..c5a1da2ec4 100644 --- a/rally/osclients.py +++ b/rally/osclients.py @@ -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. diff --git a/rally/plugins/openstack/context/ceilometer/samples.py b/rally/plugins/openstack/context/ceilometer/samples.py index 7a788da877..fc036dacc2 100644 --- a/rally/plugins/openstack/context/ceilometer/samples.py +++ b/rally/plugins/openstack/context/ceilometer/samples.py @@ -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 diff --git a/rally/plugins/openstack/context/cinder/volumes.py b/rally/plugins/openstack/context/cinder/volumes.py index 43caf00d14..fe53997db8 100644 --- a/rally/plugins/openstack/context/cinder/volumes.py +++ b/rally/plugins/openstack/context/cinder/volumes.py @@ -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"], diff --git a/rally/plugins/openstack/context/cleanup/context.py b/rally/plugins/openstack/context/cleanup/context.py index 843f26ae96..0be3694ad7 100644 --- a/rally/plugins/openstack/context/cleanup/context.py +++ b/rally/plugins/openstack/context/cleanup/context.py @@ -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, diff --git a/rally/plugins/openstack/context/ec2/servers.py b/rally/plugins/openstack/context/ec2/servers.py index ac8952f31d..04403d89e4 100644 --- a/rally/plugins/openstack/context/ec2/servers.py +++ b/rally/plugins/openstack/context/ec2/servers.py @@ -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", [])) diff --git a/rally/plugins/openstack/context/fuel.py b/rally/plugins/openstack/context/fuel.py index 1371f2dd56..0818466618 100644 --- a/rally/plugins/openstack/context/fuel.py +++ b/rally/plugins/openstack/context/fuel.py @@ -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() diff --git a/rally/plugins/openstack/context/glance/images.py b/rally/plugins/openstack/context/glance/images.py index af5b8d2078..6de6b5db7a 100644 --- a/rally/plugins/openstack/context/glance/images.py +++ b/rally/plugins/openstack/context/glance/images.py @@ -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"], diff --git a/rally/plugins/openstack/context/heat/stacks.py b/rally/plugins/openstack/context/heat/stacks.py index c954bde723..a46445d440 100644 --- a/rally/plugins/openstack/context/heat/stacks.py +++ b/rally/plugins/openstack/context/heat/stacks.py @@ -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", [])) diff --git a/rally/plugins/openstack/context/keystone/existing_users.py b/rally/plugins/openstack/context/keystone/existing_users.py index 1267bac77d..e91926aabf 100644 --- a/rally/plugins/openstack/context/keystone/existing_users.py +++ b/rally/plugins/openstack/context/keystone/existing_users.py @@ -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.""" diff --git a/rally/plugins/openstack/context/keystone/roles.py b/rally/plugins/openstack/context/keystone/roles.py index 5cc554f0d7..df5f5950cc 100644 --- a/rally/plugins/openstack/context/keystone/roles.py +++ b/rally/plugins/openstack/context/keystone/roles.py @@ -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"]: diff --git a/rally/plugins/openstack/context/keystone/users.py b/rally/plugins/openstack/context/keystone/users.py index 4e77aa5659..679820a171 100644 --- a/rally/plugins/openstack/context/keystone/users.py +++ b/rally/plugins/openstack/context/keystone/users.py @@ -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() diff --git a/rally/plugins/openstack/context/manila/manila_share_networks.py b/rally/plugins/openstack/context/manila/manila_share_networks.py index 650fe9b525..f1fab5c05c 100644 --- a/rally/plugins/openstack/context/manila/manila_share_networks.py +++ b/rally/plugins/openstack/context/manila/manila_share_networks.py @@ -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 diff --git a/rally/plugins/openstack/context/murano/murano_packages.py b/rally/plugins/openstack/context/murano/murano_packages.py index 9e57165862..614ed61f51 100644 --- a/rally/plugins/openstack/context/murano/murano_packages.py +++ b/rally/plugins/openstack/context/murano/murano_packages.py @@ -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", [])) diff --git a/rally/plugins/openstack/context/network/allow_ssh.py b/rally/plugins/openstack/context/network/allow_ssh.py index e7d19abcdf..a8d14228b5 100644 --- a/rally/plugins/openstack/context/network/allow_ssh.py +++ b/rally/plugins/openstack/context/network/allow_ssh.py @@ -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"]): diff --git a/rally/plugins/openstack/context/network/existing_network.py b/rally/plugins/openstack/context/network/existing_network.py index 96268cf252..72bfdcf0c4 100644 --- a/rally/plugins/openstack/context/network/existing_network.py +++ b/rally/plugins/openstack/context/network/existing_network.py @@ -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.""" diff --git a/rally/plugins/openstack/context/network/networks.py b/rally/plugins/openstack/context/network/networks.py index 82a9bd9b6f..3647851ce1 100644 --- a/rally/plugins/openstack/context/network/networks.py +++ b/rally/plugins/openstack/context/network/networks.py @@ -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"]), diff --git a/rally/plugins/openstack/context/neutron/lbaas.py b/rally/plugins/openstack/context/neutron/lbaas.py index e72f6ccf72..1a308d5433 100644 --- a/rally/plugins/openstack/context/neutron/lbaas.py +++ b/rally/plugins/openstack/context/neutron/lbaas.py @@ -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"]), diff --git a/rally/plugins/openstack/context/not_for_production/tempest.py b/rally/plugins/openstack/context/not_for_production/tempest.py index 83100e6690..b8087b17c2 100644 --- a/rally/plugins/openstack/context/not_for_production/tempest.py +++ b/rally/plugins/openstack/context/not_for_production/tempest.py @@ -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 " diff --git a/rally/plugins/openstack/context/nova/flavors.py b/rally/plugins/openstack/context/nova/flavors.py index b35d89a507..afbce24cc1 100644 --- a/rally/plugins/openstack/context/nova/flavors.py +++ b/rally/plugins/openstack/context/nova/flavors.py @@ -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"]) diff --git a/rally/plugins/openstack/context/nova/keypairs.py b/rally/plugins/openstack/context/nova/keypairs.py index fb6fbc0d38..b69f49352d 100644 --- a/rally/plugins/openstack/context/nova/keypairs.py +++ b/rally/plugins/openstack/context/nova/keypairs.py @@ -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"], diff --git a/rally/plugins/openstack/context/nova/servers.py b/rally/plugins/openstack/context/nova/servers.py index f287739bbc..99f470c0e9 100644 --- a/rally/plugins/openstack/context/nova/servers.py +++ b/rally/plugins/openstack/context/nova/servers.py @@ -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", [])) diff --git a/rally/plugins/openstack/context/quotas/quotas.py b/rally/plugins/openstack/context/quotas/quotas.py index b5313cf2c0..d568808ecf 100644 --- a/rally/plugins/openstack/context/quotas/quotas.py +++ b/rally/plugins/openstack/context/quotas/quotas.py @@ -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): diff --git a/rally/plugins/openstack/context/sahara/sahara_cluster.py b/rally/plugins/openstack/context/sahara/sahara_cluster.py index 299d471ad7..e7e64c9fa9 100644 --- a/rally/plugins/openstack/context/sahara/sahara_cluster.py +++ b/rally/plugins/openstack/context/sahara/sahara_cluster.py @@ -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 diff --git a/rally/plugins/openstack/context/sahara/sahara_data_sources.py b/rally/plugins/openstack/context/sahara/sahara_data_sources.py index 56ddf6845c..4252a85cfd 100644 --- a/rally/plugins/openstack/context/sahara/sahara_data_sources.py +++ b/rally/plugins/openstack/context/sahara/sahara_data_sources.py @@ -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"] diff --git a/rally/plugins/openstack/context/sahara/sahara_image.py b/rally/plugins/openstack/context/sahara/sahara_image.py index bfe826e011..c8cfd24a06 100644 --- a/rally/plugins/openstack/context/sahara/sahara_image.py +++ b/rally/plugins/openstack/context/sahara/sahara_image.py @@ -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 diff --git a/rally/plugins/openstack/context/sahara/sahara_job_binaries.py b/rally/plugins/openstack/context/sahara/sahara_job_binaries.py index 4d5c80f229..009773e3de 100644 --- a/rally/plugins/openstack/context/sahara/sahara_job_binaries.py +++ b/rally/plugins/openstack/context/sahara/sahara_job_binaries.py @@ -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"] diff --git a/rally/plugins/openstack/context/swift/objects.py b/rally/plugins/openstack/context/swift/objects.py index c648871f1e..8891d35101 100644 --- a/rally/plugins/openstack/context/swift/objects.py +++ b/rally/plugins/openstack/context/swift/objects.py @@ -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"] diff --git a/rally/plugins/openstack/context/vm/custom_image.py b/rally/plugins/openstack/context/vm/custom_image.py index 3871f0c1b5..730c09e9f0 100644 --- a/rally/plugins/openstack/context/vm/custom_image.py +++ b/rally/plugins/openstack/context/vm/custom_image.py @@ -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) diff --git a/rally/plugins/openstack/scenarios/cinder/volumes.py b/rally/plugins/openstack/scenarios/cinder/volumes.py index 40432ee4e9..630017c6bc 100644 --- a/rally/plugins/openstack/scenarios/cinder/volumes.py +++ b/rally/plugins/openstack/scenarios/cinder/volumes.py @@ -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, diff --git a/rally/plugins/openstack/scenarios/keystone/basic.py b/rally/plugins/openstack/scenarios/keystone/basic.py index e10ccbaffa..03c9a22305 100644 --- a/rally/plugins/openstack/scenarios/keystone/basic.py +++ b/rally/plugins/openstack/scenarios/keystone/basic.py @@ -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"]}) diff --git a/rally/plugins/openstack/scenarios/manila/shares.py b/rally/plugins/openstack/scenarios/manila/shares.py index 4aa37b45bb..5f8a0632f0 100644 --- a/rally/plugins/openstack/scenarios/manila/shares.py +++ b/rally/plugins/openstack/scenarios/manila/shares.py @@ -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, diff --git a/rally/plugins/openstack/scenarios/vm/vmtasks.py b/rally/plugins/openstack/scenarios/vm/vmtasks.py index 2a76779b49..94dea1fb97 100644 --- a/rally/plugins/openstack/scenarios/vm/vmtasks.py +++ b/rally/plugins/openstack/scenarios/vm/vmtasks.py @@ -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, diff --git a/rally/plugins/openstack/scenarios/zaqar/basic.py b/rally/plugins/openstack/scenarios/zaqar/basic.py index 16741c0fdc..79d409ca44 100644 --- a/rally/plugins/openstack/scenarios/zaqar/basic.py +++ b/rally/plugins/openstack/scenarios/zaqar/basic.py @@ -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, diff --git a/rally/task/engine.py b/rally/task/engine.py index 124670d074..7593804dff 100644 --- a/rally/task/engine.py +++ b/rally/task/engine.py @@ -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. diff --git a/rally/task/utils.py b/rally/task/utils.py index 3a978def15..feae2256b8 100644 --- a/rally/task/utils.py +++ b/rally/task/utils.py @@ -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. diff --git a/rally/verification/tempest/tempest.py b/rally/verification/tempest/tempest.py index 5e43de5c15..d515b75469 100644 --- a/rally/verification/tempest/tempest.py +++ b/rally/verification/tempest/tempest.py @@ -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) diff --git a/tests/unit/common/test_log.py b/tests/unit/common/test_log.py new file mode 100644 index 0000000000..67f8774a4d --- /dev/null +++ b/tests/unit/common/test_log.py @@ -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)") diff --git a/tests/unit/common/test_utils.py b/tests/unit/common/test_utils.py index b92bd35198..cf3a62b157 100644 --- a/tests/unit/common/test_utils.py +++ b/tests/unit/common/test_utils.py @@ -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 diff --git a/tests/unit/plugins/openstack/scenarios/vm/test_vmtasks.py b/tests/unit/plugins/openstack/scenarios/vm/test_vmtasks.py index a2e6f83f6a..b1b0740073 100644 --- a/tests/unit/plugins/openstack/scenarios/vm/test_vmtasks.py +++ b/tests/unit/plugins/openstack/scenarios/vm/test_vmtasks.py @@ -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",