From 9b88f73b872ce14b5f0ea647528bb40fc17a9cd5 Mon Sep 17 00:00:00 2001 From: zhangshuai <446077695@qq.com> Date: Fri, 17 Mar 2017 05:11:16 +0800 Subject: [PATCH] Remove log translations Log messages are no longer being translated. This removes all use of the _LE, _LI, and _LW translation markers to simplify logging and to avoid confusion with new contributions. See: http://lists.openstack.org/pipermail/openstack-i18n/2016-November/002574.html http://lists.openstack.org/pipermail/openstack-dev/2017-March/113365.html Change-Id: I62bf3bda7a0769fc8ff941d8238222beb392cf68 --- karbor/api/openstack/wsgi.py | 22 ++++--- karbor/api/v1/plans.py | 24 ++++---- karbor/api/v1/protectables.py | 26 ++++---- karbor/api/v1/providers.py | 44 +++++++------- karbor/api/v1/restores.py | 16 ++--- karbor/api/v1/scheduled_operations.py | 4 +- karbor/api/v1/triggers.py | 4 +- karbor/common/karbor_keystone_plugin.py | 7 +-- karbor/db/sqlalchemy/api.py | 22 ++++--- karbor/exception.py | 6 +- karbor/i18n.py | 10 ---- karbor/service.py | 30 +++++----- .../engine/executors/green_thread_executor.py | 26 ++++---- .../executors/scheduled_operation_executor.py | 9 ++- .../engine/executors/thread_pool_executor.py | 3 +- .../triggers/timetrigger/time_trigger.py | 27 ++++----- .../operationengine/operations/base.py | 5 +- .../operationengine/user_trust_manager.py | 5 +- .../bank_plugins/swift_bank_plugin.py | 27 ++++----- karbor/services/protection/checkpoint.py | 4 +- karbor/services/protection/client_factory.py | 4 +- karbor/services/protection/clients/eisoo.py | 6 +- karbor/services/protection/clients/heat.py | 3 +- karbor/services/protection/clients/nova.py | 3 +- karbor/services/protection/flows/delete.py | 4 +- karbor/services/protection/flows/restore.py | 25 ++++---- karbor/services/protection/flows/worker.py | 3 +- karbor/services/protection/flows/workflow.py | 14 ++--- karbor/services/protection/manager.py | 55 ++++++++--------- .../protection/protectable_plugins/image.py | 11 ++-- .../protection/protectable_plugins/server.py | 5 +- .../protection/protectable_plugins/volume.py | 10 +--- .../image/image_protection_plugin.py | 29 ++++----- .../server/nova_protection_plugin.py | 23 ++++---- .../volume/cinder_protection_plugin.py | 59 ++++++++----------- karbor/services/protection/provider.py | 14 ++--- karbor/services/protection/resource_flow.py | 3 +- karbor/services/protection/restore_heat.py | 3 +- karbor/tests/unit/protection/fakes.py | 11 ++-- karbor/utils.py | 6 +- karbor/wsgi/common.py | 4 +- karbor/wsgi/eventlet_server.py | 13 ++-- 42 files changed, 273 insertions(+), 356 deletions(-) diff --git a/karbor/api/openstack/wsgi.py b/karbor/api/openstack/wsgi.py index 16312bf4..00a79089 100644 --- a/karbor/api/openstack/wsgi.py +++ b/karbor/api/openstack/wsgi.py @@ -23,7 +23,7 @@ import webob from karbor import exception from karbor import i18n -from karbor.i18n import _, _LE, _LI +from karbor.i18n import _ from karbor.wsgi import common as wsgi @@ -363,15 +363,14 @@ class ResourceExceptionHandler(object): code=ex_value.code, explanation=ex_value.msg)) elif isinstance(ex_value, TypeError): exc_info = (ex_type, ex_value, ex_traceback) - LOG.error(_LE( - 'Exception handling resource: %s'), - ex_value, exc_info=exc_info) + LOG.error('Exception handling resource: %s', + ex_value, exc_info=exc_info) raise Fault(webob.exc.HTTPBadRequest()) elif isinstance(ex_value, Fault): - LOG.info(_LI("Fault thrown: %s"), ex_value) + LOG.info("Fault thrown: %s", ex_value) raise ex_value elif isinstance(ex_value, webob.exc.HTTPException): - LOG.info(_LI("HTTP exception thrown: %s"), ex_value) + LOG.info("HTTP exception thrown: %s", ex_value) raise Fault(ex_value) # We didn't handle the exception @@ -567,9 +566,8 @@ class Resource(wsgi.Application): def __call__(self, request): """WSGI method that controls (de)serialization and method dispatch.""" - LOG.info(_LI("%(method)s %(url)s"), - {"method": request.method, - "url": request.url}) + LOG.info("%(method)s %(url)s", + {"method": request.method, "url": request.url}) # Identify the action, its arguments, and the requested # content type @@ -667,10 +665,10 @@ class Resource(wsgi.Application): try: msg_dict = dict(url=request.url, status=response.status_int) - msg = _LI("%(url)s returned with HTTP %(status)d") + msg = "%(url)s returned with HTTP %(status)d" except AttributeError as e: msg_dict = dict(url=request.url, e=e) - msg = _LI("%(url)s returned a fault: %(e)s") + msg = "%(url)s returned a fault: %(e)s" LOG.info(msg, msg_dict) @@ -691,7 +689,7 @@ class Resource(wsgi.Application): 'create', 'delete', 'update']): - LOG.exception(_LE('Get method error.')) + LOG.exception('Get method error.') else: ctxt.reraise = False else: diff --git a/karbor/api/v1/plans.py b/karbor/api/v1/plans.py index 46a37943..c3f9956f 100644 --- a/karbor/api/v1/plans.py +++ b/karbor/api/v1/plans.py @@ -23,7 +23,7 @@ from karbor.api import common from karbor.api.openstack import wsgi from karbor.common import constants from karbor import exception -from karbor.i18n import _, _LI +from karbor.i18n import _ from karbor import objects from karbor.objects import base as objects_base @@ -132,7 +132,7 @@ class PlansController(wsgi.Controller): """Return data about the given plan.""" context = req.environ['karbor.context'] - LOG.info(_LI("Show plan with id: %s"), id, context=context) + LOG.info("Show plan with id: %s", id, context=context) if not uuidutils.is_uuid_like(id): msg = _("Invalid plan id provided.") @@ -143,7 +143,7 @@ class PlansController(wsgi.Controller): except exception.PlanNotFound as error: raise exc.HTTPNotFound(explanation=error.msg) - LOG.info(_LI("Show plan request issued successfully."), + LOG.info("Show plan request issued successfully.", resource={'id': plan.id}) return self._view_builder.detail(req, plan) @@ -151,7 +151,7 @@ class PlansController(wsgi.Controller): """Delete a plan.""" context = req.environ['karbor.context'] - LOG.info(_LI("Delete plan with id: %s"), id, context=context) + LOG.info("Delete plan with id: %s", id, context=context) try: plan = self._plan_get(context, id) @@ -160,14 +160,14 @@ class PlansController(wsgi.Controller): check_policy(context, 'delete', plan) plan.destroy() - LOG.info(_LI("Delete plan request issued successfully."), + LOG.info("Delete plan request issued successfully.", resource={'id': plan.id}) def index(self, req): """Returns a list of plans, transformed through view builder.""" context = req.environ['karbor.context'] - LOG.info(_LI("Show plan list"), context=context) + LOG.info("Show plan list", context=context) params = req.params.copy() marker, limit, offset = common.get_pagination_params(params) @@ -187,7 +187,7 @@ class PlansController(wsgi.Controller): retval_plans = self._view_builder.detail_list(req, plans) - LOG.info(_LI("Show plan list request issued successfully.")) + LOG.info("Show plan list request issued successfully.") return retval_plans @@ -227,7 +227,7 @@ class PlansController(wsgi.Controller): sort_keys=sort_keys, sort_dirs=sort_dirs, filters=filters, offset=offset) - LOG.info(_LI("Get all plans completed successfully.")) + LOG.info("Get all plans completed successfully.") return plans def _get_plan_filter_options(self): @@ -341,13 +341,13 @@ class PlansController(wsgi.Controller): # raise PlanNotFound instead to make sure karbor behaves # as it used to raise exception.PlanNotFound(plan_id=plan_id) - LOG.info(_LI("Plan info retrieved successfully."), resource=plan) + LOG.info("Plan info retrieved successfully.", resource=plan) return plan def _plan_update(self, context, plan, fields): if plan['status'] != constants.PLAN_STATUS_SUSPENDED: - LOG.info(_LI("Unable to update plan, " - "because it is in %s state."), plan['status']) + LOG.info("Unable to update plan, because it is in %s state.", + plan['status']) msg = _("The plan can be only updated in suspended status.") raise exception.InvalidPlan(reason=msg) # TODO(chenying) replication scene: need call rpc API when @@ -355,7 +355,7 @@ class PlansController(wsgi.Controller): if isinstance(plan, objects_base.KarborObject): plan.update(fields) plan.save() - LOG.info(_LI("Plan updated successfully."), resource=plan) + LOG.info("Plan updated successfully.", resource=plan) else: msg = _("The parameter plan must be a object of " "KarborObject class.") diff --git a/karbor/api/v1/protectables.py b/karbor/api/v1/protectables.py index bc8bb5ed..f40ca3ca 100644 --- a/karbor/api/v1/protectables.py +++ b/karbor/api/v1/protectables.py @@ -19,7 +19,7 @@ from webob import exc from karbor.api import common from karbor.api.openstack import wsgi from karbor import exception -from karbor.i18n import _, _LI +from karbor.i18n import _ import karbor.policy from karbor.services.protection import api as protection_api @@ -129,8 +129,8 @@ class ProtectablesController(wsgi.Controller): context = req.environ['karbor.context'] protectable_type = id - LOG.info(_LI("Show the information of a given" - " protectable type: %s"), protectable_type) + LOG.info("Show the information of a given protectable type: %s", + protectable_type) protectable_types = self._get_all(context) @@ -145,8 +145,7 @@ class ProtectablesController(wsgi.Controller): except exception.ProtectableTypeNotFound as error: raise exc.HTTPNotFound(explanation=error.msg) - LOG.info(_LI("Show the protectable type information" - " issued successfully.")) + LOG.info("Show the protectable type information issued successfully.") return self._view_builder.show(req, retval_protectable_type) def index(self, req): @@ -155,15 +154,14 @@ class ProtectablesController(wsgi.Controller): transformed through view builder. """ context = req.environ['karbor.context'] - LOG.info(_LI("Show protectable type list"), context=context) + LOG.info("Show protectable type list", context=context) protectable_types = self._get_all(context) retval_protectable_types = { "protectable_type": protectable_types } - LOG.info(_LI("Show protectable type list request issued" - " successfully.")) + LOG.info("Show protectable type list request issued successfully.") return retval_protectable_types def _get_all(self, context): @@ -171,14 +169,14 @@ class ProtectablesController(wsgi.Controller): protectable_types = self.protection_api.list_protectable_types(context) - LOG.info(_LI("Get all protectable types completed successfully.")) + LOG.info("Get all protectable types completed successfully.") return protectable_types def instances_index(self, req, protectable_type): """Return data about the given protectable_type.""" context = req.environ['karbor.context'] - LOG.info(_LI("Show the instances of a given" - " protectable type: %s"), protectable_type) + LOG.info("Show the instances of a given protectable type: %s", + protectable_type) params = req.params.copy() marker, limit, offset = common.get_pagination_params(params) @@ -250,7 +248,7 @@ class ProtectablesController(wsgi.Controller): offset=offset, parameters=parameters) - LOG.info(_LI("Get all instances completed successfully.")) + LOG.info("Get all instances completed successfully.") return instances def _get_instance_filter_options(self): @@ -265,8 +263,8 @@ class ProtectablesController(wsgi.Controller): utils.check_filters(params) parameters = params.get("parameters", None) - LOG.info(_LI("Show the instance of a given protectable" - " type: %s"), protectable_type) + LOG.info("Show the instance of a given protectable type: %s", + protectable_type) if parameters is not None: if not isinstance(parameters, dict): diff --git a/karbor/api/v1/providers.py b/karbor/api/v1/providers.py index 7ffedce7..34a86254 100644 --- a/karbor/api/v1/providers.py +++ b/karbor/api/v1/providers.py @@ -23,7 +23,7 @@ from karbor.api import common from karbor.api.openstack import wsgi from karbor.common import constants from karbor import exception -from karbor.i18n import _, _LI +from karbor.i18n import _ from karbor import objects import karbor.policy @@ -196,14 +196,14 @@ class ProvidersController(wsgi.Controller): """Return data about the given provider id.""" context = req.environ['karbor.context'] - LOG.info(_LI("Show provider with id: %s"), id) + LOG.info("Show provider with id: %s", id) try: provider = self._provider_get(context, id) except exception.ProviderNotFound as error: raise exc.HTTPNotFound(explanation=error.msg) - LOG.info(_LI("Show provider request issued successfully."), + LOG.info("Show provider request issued successfully.", resource={'id': provider.get("id")}) return self._view_builder.detail(req, provider) @@ -211,7 +211,7 @@ class ProvidersController(wsgi.Controller): """Returns a list of providers, transformed through view builder.""" context = req.environ['karbor.context'] - LOG.info(_LI("Show provider list"), context=context) + LOG.info("Show provider list", context=context) params = req.params.copy() marker, limit, offset = common.get_pagination_params(params) @@ -232,7 +232,7 @@ class ProvidersController(wsgi.Controller): retval_providers = self._view_builder.detail_list(req, providers) - LOG.info(_LI("Show provider list request issued successfully.")) + LOG.info("Show provider list request issued successfully.") return retval_providers @@ -263,7 +263,7 @@ class ProvidersController(wsgi.Controller): filters=filters, offset=offset) - LOG.info(_LI("Get all providers completed successfully.")) + LOG.info("Get all providers completed successfully.") return providers def _get_provider_filter_options(self): @@ -288,15 +288,14 @@ class ProvidersController(wsgi.Controller): provider = self.protection_api.show_provider(context, provider_id) - LOG.info(_LI("Provider info retrieved successfully.")) + LOG.info("Provider info retrieved successfully.") return provider def checkpoints_index(self, req, provider_id): """Returns a list of checkpoints, transformed through view builder.""" context = req.environ['karbor.context'] - LOG.info(_LI("Show checkpoints list. " - "provider_id:%s"), provider_id) + LOG.info("Show checkpoints list. provider_id:%s", provider_id) params = req.params.copy() marker, limit, offset = common.get_pagination_params(params) @@ -317,8 +316,7 @@ class ProvidersController(wsgi.Controller): retval_checkpoints = self._checkpoint_view_builder.detail_list( req, checkpoints) - LOG.info(_LI("Show checkpoints list request issued successfully.")) - + LOG.info("Show checkpoints list request issued successfully.") return retval_checkpoints def _checkpoints_get_all(self, context, provider_id, marker=None, @@ -349,7 +347,7 @@ class ProvidersController(wsgi.Controller): filters=filters, offset=offset) - LOG.info(_LI("Get all checkpoints completed successfully.")) + LOG.info("Get all checkpoints completed successfully.") return checkpoints def checkpoints_create(self, req, provider_id, body): @@ -427,7 +425,7 @@ class ProvidersController(wsgi.Controller): raise exc.HTTPBadRequest(explanation=msg) checkpoint_properties['id'] = checkpoint_id - LOG.info(_LI("Create the checkpoint successfully. checkpoint_id:%s"), + LOG.info("Create the checkpoint successfully. checkpoint_id:%s", checkpoint_id) returnval = self._checkpoint_view_builder.detail( req, checkpoint_properties) @@ -437,9 +435,8 @@ class ProvidersController(wsgi.Controller): """Return data about the given checkpoint id.""" context = req.environ['karbor.context'] - LOG.info(_LI("Show checkpoint with id: %s."), - checkpoint_id) - LOG.info(_LI("provider_id: %s."), provider_id) + LOG.info("Show checkpoint with id: %s.", checkpoint_id) + LOG.info("provider_id: %s.", provider_id) try: checkpoint = self._checkpoint_get(context, provider_id, @@ -447,10 +444,10 @@ class ProvidersController(wsgi.Controller): except exception.CheckpointNotFound as error: raise exc.HTTPNotFound(explanation=error.msg) - LOG.info(_LI("Show checkpoint request issued successfully.")) - LOG.info(_LI("checkpoint: %s"), checkpoint) + LOG.info("Show checkpoint request issued successfully.") + LOG.info("checkpoint: %s", checkpoint) retval = self._checkpoint_view_builder.detail(req, checkpoint) - LOG.info(_LI("retval: %s"), retval) + LOG.info("retval: %s", retval) return retval def _checkpoint_get(self, context, provider_id, checkpoint_id): @@ -475,16 +472,15 @@ class ProvidersController(wsgi.Controller): if checkpoint is None: raise exception.CheckpointNotFound(checkpoint_id=checkpoint_id) - LOG.info(_LI("Checkpoint info retrieved successfully.")) + LOG.info("Checkpoint info retrieved successfully.") return checkpoint def checkpoints_delete(self, req, provider_id, checkpoint_id): """Delete a checkpoint.""" context = req.environ['karbor.context'] - LOG.info(_LI("Delete checkpoint with id: %s."), - checkpoint_id) - LOG.info(_LI("provider_id: %s."), provider_id) + LOG.info("Delete checkpoint with id: %s.", checkpoint_id) + LOG.info("provider_id: %s.", provider_id) if not uuidutils.is_uuid_like(provider_id): msg = _("Invalid provider id provided.") @@ -499,7 +495,7 @@ class ProvidersController(wsgi.Controller): provider_id, checkpoint_id) - LOG.info(_LI("Delete checkpoint request issued successfully.")) + LOG.info("Delete checkpoint request issued successfully.") return {} diff --git a/karbor/api/v1/restores.py b/karbor/api/v1/restores.py index ce0ec36c..a2a3b986 100644 --- a/karbor/api/v1/restores.py +++ b/karbor/api/v1/restores.py @@ -23,7 +23,7 @@ from karbor.api import common from karbor.api.openstack import wsgi from karbor.common import constants from karbor import exception -from karbor.i18n import _, _LI +from karbor.i18n import _ from karbor import objects from karbor.objects import base as objects_base @@ -135,7 +135,7 @@ class RestoresController(wsgi.Controller): """Return data about the given restore.""" context = req.environ['karbor.context'] - LOG.info(_LI("Show restore with id: %s"), id, context=context) + LOG.info("Show restore with id: %s", id, context=context) if not uuidutils.is_uuid_like(id): msg = _("Invalid restore id provided.") @@ -146,7 +146,7 @@ class RestoresController(wsgi.Controller): except exception.RestoreNotFound as error: raise exc.HTTPNotFound(explanation=error.msg) - LOG.info(_LI("Show restore request issued successfully."), + LOG.info("Show restore request issued successfully.", resource={'id': restore.id}) return self._view_builder.detail(req, restore) @@ -154,7 +154,7 @@ class RestoresController(wsgi.Controller): """Returns a list of restores, transformed through view builder.""" context = req.environ['karbor.context'] - LOG.info(_LI("Show restore list"), context=context) + LOG.info("Show restore list", context=context) params = req.params.copy() marker, limit, offset = common.get_pagination_params(params) @@ -175,7 +175,7 @@ class RestoresController(wsgi.Controller): retval_restores = self._view_builder.detail_list(req, restores) - LOG.info(_LI("Show restore list request issued successfully.")) + LOG.info("Show restore list request issued successfully.") return retval_restores @@ -216,7 +216,7 @@ class RestoresController(wsgi.Controller): sort_keys=sort_keys, sort_dirs=sort_dirs, filters=filters, offset=offset) - LOG.info(_LI("Get all restores completed successfully.")) + LOG.info("Get all restores completed successfully.") return restores def _get_restore_filter_options(self): @@ -303,7 +303,7 @@ class RestoresController(wsgi.Controller): # raise RestoreNotFound instead to make sure karbor behaves # as it used to raise exception.RestoreNotFound(restore_id=restore_id) - LOG.info(_LI("Restore info retrieved successfully.")) + LOG.info("Restore info retrieved successfully.") return restore def _restore_update(self, context, restore_id, fields): @@ -315,7 +315,7 @@ class RestoresController(wsgi.Controller): if isinstance(restore, objects_base.KarborObject): restore.update(fields) restore.save() - LOG.info(_LI("restore updated successfully.")) + LOG.info("restore updated successfully.") return restore else: msg = _("The parameter restore must be a object of " diff --git a/karbor/api/v1/scheduled_operations.py b/karbor/api/v1/scheduled_operations.py index 3f885593..44da64b6 100644 --- a/karbor/api/v1/scheduled_operations.py +++ b/karbor/api/v1/scheduled_operations.py @@ -19,7 +19,7 @@ from webob import exc from karbor.api import common from karbor.api.openstack import wsgi from karbor import exception -from karbor.i18n import _, _LE +from karbor.i18n import _ from karbor import objects from karbor import policy from karbor.services.operationengine import api as operationengine_api @@ -246,7 +246,7 @@ class ScheduledOperationController(wsgi.Controller): self._raise_unknown_exception(ex) def _raise_unknown_exception(self, exception_instance): - LOG.exception(_LE('An unknown exception happened')) + LOG.exception('An unknown exception happened') value = exception_instance.msg if isinstance( exception_instance, exception.KarborException) else type( diff --git a/karbor/api/v1/triggers.py b/karbor/api/v1/triggers.py index 3ee790d5..1f08dec8 100644 --- a/karbor/api/v1/triggers.py +++ b/karbor/api/v1/triggers.py @@ -20,7 +20,7 @@ from webob import exc from karbor.api import common from karbor.api.openstack import wsgi from karbor import exception -from karbor.i18n import _, _LE +from karbor.i18n import _ from karbor import objects from karbor import policy from karbor.services.operationengine import api as operationengine_api @@ -243,7 +243,7 @@ class TriggersController(wsgi.Controller): return trigger def _raise_unknown_exception(self, exception_instance): - LOG.exception(_LE('An unknown exception happened')) + LOG.exception('An unknown exception happened') value = exception_instance.msg if isinstance( exception_instance, exception.KarborException) else type( diff --git a/karbor/common/karbor_keystone_plugin.py b/karbor/common/karbor_keystone_plugin.py index 8bc35684..0fac6654 100644 --- a/karbor/common/karbor_keystone_plugin.py +++ b/karbor/common/karbor_keystone_plugin.py @@ -19,7 +19,6 @@ from oslo_config import cfg from oslo_log import log as logging from karbor import exception -from karbor.i18n import _LW from karbor import utils @@ -163,9 +162,9 @@ class KarborKeystonePlugin(object): CONF, TRUSTEE_CONF_GROUP, trust_id=trust_id) if not auth_plugin: - LOG.warning(_LW('Please add the trustee credentials you ' - 'need to the %s section of your karbor.conf ' - 'file.') % TRUSTEE_CONF_GROUP) + LOG.warning('Please add the trustee credentials you need to the' + ' %s section of your karbor.conf file.', + TRUSTEE_CONF_GROUP) raise exception.AuthorizationFailure(obj=TRUSTEE_CONF_GROUP) return auth_plugin diff --git a/karbor/db/sqlalchemy/api.py b/karbor/db/sqlalchemy/api.py index 44b49630..67c5e437 100644 --- a/karbor/db/sqlalchemy/api.py +++ b/karbor/db/sqlalchemy/api.py @@ -38,7 +38,7 @@ from sqlalchemy.sql import func from karbor.db.sqlalchemy import models from karbor import exception -from karbor.i18n import _, _LW, _LE, _LI +from karbor.i18n import _ CONF = cfg.CONF @@ -89,7 +89,7 @@ def get_backend(): def is_admin_context(context): """Indicates if the request context is an administrator.""" if not context: - LOG.warning(_LW('Use of empty request context is deprecated'), + LOG.warning('Use of empty request context is deprecated', DeprecationWarning) raise Exception('die') return context.is_admin @@ -177,9 +177,8 @@ def _retry_on_deadlock(f): try: return f(*args, **kwargs) except db_exc.DBDeadlock: - LOG.warning(_LW("Deadlock detected when running " - "'%(func_name)s': Retrying..."), - dict(func_name=f.__name__)) + LOG.warning("Deadlock detected when running '%(func_name)s':" + " Retrying...", dict(func_name=f.__name__)) # Retry! time.sleep(0.5) continue @@ -1665,16 +1664,15 @@ def purge_deleted_rows(context, age_in_days): try: tables.remove(tbl) except ValueError: - LOG.warning(_LW('Expected table %(tbl)s was not found in DB.'), + LOG.warning('Expected table %(tbl)s was not found in DB.', **locals()) else: tables.append(tbl) for table in tables: t = Table(table, metadata, autoload=True) - LOG.info(_LI('Purging deleted rows older than age=%(age)d days ' - 'from table=%(table)s'), {'age': age_in_days, - 'table': table}) + LOG.info('Purging deleted rows older than age=%(age)d days from ' + 'table=%(table)s', {'age': age_in_days, 'table': table}) deleted_age = timeutils.utcnow() - dt.timedelta(days=age_in_days) try: with session.begin(): @@ -1682,10 +1680,10 @@ def purge_deleted_rows(context, age_in_days): t.delete() .where(t.c.deleted_at < deleted_age)) except db_exc.DBReferenceError: - LOG.exception(_LE('DBError detected when purging from ' - 'table=%(table)s'), {'table': table}) + LOG.exception('DBError detected when purging from ' + 'table=%(table)s', {'table': table}) raise rows_purged = result.rowcount - LOG.info(_LI("Deleted %(row)d rows from table=%(table)s"), + LOG.info("Deleted %(row)d rows from table=%(table)s", {'row': rows_purged, 'table': table}) diff --git a/karbor/exception.py b/karbor/exception.py index 505b2152..8b10181a 100644 --- a/karbor/exception.py +++ b/karbor/exception.py @@ -28,7 +28,7 @@ import webob.exc from webob.util import status_generic_reasons from webob.util import status_reasons -from karbor.i18n import _, _LE +from karbor.i18n import _ LOG = logging.getLogger(__name__) @@ -111,9 +111,9 @@ class KarborException(Exception): exc_info = sys.exc_info() # kwargs doesn't match a variable in the message # log the issue and the kwargs - LOG.exception(_LE('Exception in string format operation')) + LOG.exception('Exception in string format operation') for name, value in kwargs.items(): - LOG.error(_LE("%(name)s: %(value)s"), + LOG.error("%(name)s: %(value)s", {'name': name, 'value': value}) if CONF.fatal_exception_format_errors: six.reraise(*exc_info) diff --git a/karbor/i18n.py b/karbor/i18n.py index 428bfdff..c7b563e0 100644 --- a/karbor/i18n.py +++ b/karbor/i18n.py @@ -25,16 +25,6 @@ _translators = i18n.TranslatorFactory(domain=DOMAIN) # The primary translation function using the well-known name "_" _ = _translators.primary -# Translators for log levels. -# -# The abbreviated names are meant to reflect the usual use of a short -# name like '_'. The "L" is for "log" and the other letter comes from -# the level. -_LI = _translators.log_info -_LW = _translators.log_warning -_LE = _translators.log_error -_LC = _translators.log_critical - def enable_lazy(enable=True): return i18n.enable_lazy(enable) diff --git a/karbor/service.py b/karbor/service.py index e58f9b72..353dabef 100644 --- a/karbor/service.py +++ b/karbor/service.py @@ -29,7 +29,7 @@ from oslo_utils import importutils from karbor import context from karbor import db from karbor import exception -from karbor.i18n import _, _LE, _LI, _LW +from karbor.i18n import _ from karbor.objects import base as objects_base from karbor import rpc from karbor import version @@ -99,7 +99,7 @@ class Service(service.Service): def start(self): version_string = version.version_string() - LOG.info(_LI('Starting %(topic)s node (version %(version_string)s)'), + LOG.info('Starting %(topic)s node (version %(version_string)s)', {'topic': self.topic, 'version_string': version_string}) self.model_disconnected = False ctxt = context.get_admin_context() @@ -150,11 +150,11 @@ class Service(service.Service): if CONF.service_down_time <= self.report_interval: new_down_time = int(self.report_interval * 2.5) LOG.warning( - _LW("Report interval must be less than service down " - "time. Current config service_down_time: " - "%(service_down_time)s, report_interval for this: " - "service is: %(report_interval)s. Setting global " - "service_down_time to: %(new_down_time)s"), + "Report interval must be less than service down " + "time. Current config service_down_time: " + "%(service_down_time)s, report_interval for this: " + "service is: %(report_interval)s. Setting global " + "service_down_time to: %(new_down_time)s", {'service_down_time': CONF.service_down_time, 'report_interval': self.report_interval, 'new_down_time': new_down_time}) @@ -217,7 +217,7 @@ class Service(service.Service): try: db.service_destroy(context.get_admin_context(), self.service_id) except exception.NotFound: - LOG.warning(_LW('Service killed that has no database entry')) + LOG.warning('Service killed that has no database entry') def stop(self): # Try to shut the connection down, but if we get any sort of @@ -253,9 +253,9 @@ class Service(service.Service): if not self.manager.is_working(): # NOTE(dulek): If manager reports a problem we're not sending # heartbeats - to indicate that service is actually down. - LOG.error(_LE('Manager for service %(binary)s %(host)s is ' - 'reporting problems, not sending heartbeat. ' - 'Service will appear "down".'), + LOG.error('Manager for service %(binary)s %(host)s is ' + 'reporting problems, not sending heartbeat. ' + 'Service will appear "down".', {'binary': self.binary, 'host': self.host}) return @@ -279,24 +279,24 @@ class Service(service.Service): # TODO(termie): make this pattern be more elegant. if getattr(self, 'model_disconnected', False): self.model_disconnected = False - LOG.error(_LE('Recovered model server connection!')) + LOG.error('Recovered model server connection!') except db_exc.DBConnectionError: if not getattr(self, 'model_disconnected', False): self.model_disconnected = True - LOG.exception(_LE('model server went away')) + LOG.exception('model server went away') # NOTE(jsbryant) Other DB errors can happen in HA configurations. # such errors shouldn't kill this thread, so we handle them here. except db_exc.DBError: if not getattr(self, 'model_disconnected', False): self.model_disconnected = True - LOG.exception(_LE('DBError encountered: ')) + LOG.exception('DBError encountered: ') except Exception: if not getattr(self, 'model_disconnected', False): self.model_disconnected = True - LOG.exception(_LE('Exception encountered: ')) + LOG.exception('Exception encountered: ') class WSGIService(service.ServiceBase): diff --git a/karbor/services/operationengine/engine/executors/green_thread_executor.py b/karbor/services/operationengine/engine/executors/green_thread_executor.py index 33aa3ba1..991a0a51 100644 --- a/karbor/services/operationengine/engine/executors/green_thread_executor.py +++ b/karbor/services/operationengine/engine/executors/green_thread_executor.py @@ -21,7 +21,6 @@ from oslo_utils import timeutils from karbor.common import constants from karbor import context -from karbor.i18n import _LE, _LW from karbor import objects from karbor.services.operationengine.engine.executors import base @@ -50,15 +49,14 @@ class GreenThreadExecutor(base.BaseExecutor): expect_start_time, window_time, **kwargs): if operation_id in self._operation_thread_map: - LOG.warning(_LW("Execute operation(%s), " - "the previous one has not been finished"), - operation_id) + LOG.warning("Execute operation(%s), the previous one has not been" + " finished", operation_id) return num = CONF.operationengine.max_concurrent_operations if num and len(self._operation_thread_map) >= num: - LOG.warning(_LW("The amount of concurrent running operations " - "exceeds %d"), num) + LOG.warning("The amount of concurrent running operations " + "exceeds %d", num) return self._operation_thread_map[operation_id] = None @@ -76,7 +74,7 @@ class GreenThreadExecutor(base.BaseExecutor): # green thread. So if operation_id is not exist, it may be # canceled by 'cancel_operation' during the call to DB in # the codes above. - LOG.warning(_LW("Operation(%s) is not exist after call to DB"), + LOG.warning("Operation(%s) is not exist after call to DB", operation_id) return @@ -91,8 +89,8 @@ class GreenThreadExecutor(base.BaseExecutor): self._create_thread(self._run_operation, operation_id, param) except Exception: self._operation_thread_map.pop(operation_id, None) - LOG.exception(_LE("Execute operation (%s), " - "and create green thread failed"), operation_id) + LOG.exception("Execute operation (%s), and create green thread " + "failed", operation_id) def cancel_operation(self, operation_id): gt = self._operation_thread_map.get(operation_id, None) @@ -143,7 +141,7 @@ class GreenThreadExecutor(base.BaseExecutor): operation = objects.ScheduledOperation.get_by_id( context.get_admin_context(), operation_id) except Exception: - LOG.exception(_LE("Run operation(%s), get operation failed"), + LOG.exception("Run operation(%s), get operation failed", operation_id) return @@ -156,7 +154,7 @@ class GreenThreadExecutor(base.BaseExecutor): operation.operation_definition, param=param) except Exception: - LOG.exception(_LE("Run operation(%s) failed"), operation_id) + LOG.exception("Run operation(%s) failed", operation_id) finally: self._update_operation_state( @@ -173,7 +171,7 @@ class GreenThreadExecutor(base.BaseExecutor): setattr(state_ref, item, value) state_ref.save() except Exception: - LOG.exception(_LE("Execute operation(%s), update state failed"), + LOG.exception("Execute operation(%s), update state failed", operation_id) return False return True @@ -183,8 +181,8 @@ class GreenThreadExecutor(base.BaseExecutor): try: del self._operation_thread_map[op_id] except Exception: - LOG.warning(_LW("Unknown operation id(%s) received, " - "when the green thread exit"), op_id) + LOG.warning("Unknown operation id(%s) received, " + "when the green thread exit", op_id) def _create_thread(self, function, operation_id, param): gt = eventlet.spawn(function, operation_id, param) diff --git a/karbor/services/operationengine/engine/executors/scheduled_operation_executor.py b/karbor/services/operationengine/engine/executors/scheduled_operation_executor.py index a92954b5..8f2c844a 100644 --- a/karbor/services/operationengine/engine/executors/scheduled_operation_executor.py +++ b/karbor/services/operationengine/engine/executors/scheduled_operation_executor.py @@ -18,7 +18,6 @@ from oslo_utils import timeutils from karbor.common import constants from karbor import context -from karbor.i18n import _LE, _LW from karbor import objects from karbor.services.operationengine.engine.executors import base @@ -40,7 +39,7 @@ class ScheduledOperationExecutor(base.BaseExecutor): expect_start_time, window_time, **kwargs): if self._check_operation(operation_id, self._CHECK_ITEMS.values()): - LOG.warning(_LW("Execute operation(%s), it can't be executed"), + LOG.warning("Execute operation(%s), it can't be executed", operation_id) return @@ -92,7 +91,7 @@ class ScheduledOperationExecutor(base.BaseExecutor): operation = objects.ScheduledOperation.get_by_id( context.get_admin_context(), operation_id) except Exception: - LOG.exception(_LE("Run operation(%s), get operation failed"), + LOG.exception("Run operation(%s), get operation failed", operation_id) return @@ -105,7 +104,7 @@ class ScheduledOperationExecutor(base.BaseExecutor): operation.operation_definition, param=param) except Exception: - LOG.exception(_LE("Run operation(%s) failed"), operation_id) + LOG.exception("Run operation(%s) failed", operation_id) finally: self._update_operation_state( @@ -122,7 +121,7 @@ class ScheduledOperationExecutor(base.BaseExecutor): setattr(state_ref, item, value) state_ref.save() except Exception: - LOG.exception(_LE("Execute operation(%s), update state failed"), + LOG.exception("Execute operation(%s), update state failed", operation_id) return False return True diff --git a/karbor/services/operationengine/engine/executors/thread_pool_executor.py b/karbor/services/operationengine/engine/executors/thread_pool_executor.py index c15e84c1..2c3bbc9f 100644 --- a/karbor/services/operationengine/engine/executors/thread_pool_executor.py +++ b/karbor/services/operationengine/engine/executors/thread_pool_executor.py @@ -16,7 +16,6 @@ from oslo_config import cfg from oslo_log import log as logging from threading import RLock -from karbor.i18n import _LE from karbor.services.operationengine.engine.executors import \ scheduled_operation_executor as base_executor @@ -82,7 +81,7 @@ class ThreadPoolExecutor(base_executor.ScheduledOperationExecutor): except Exception: self._operation_to_run[operation_id] -= 1 - LOG.exception(_LE("Submit operation(%(o_id)s) failed."), + LOG.exception("Submit operation(%(o_id)s) failed.", operation_id) def _finish_operation(self, operation_id): diff --git a/karbor/services/operationengine/engine/triggers/timetrigger/time_trigger.py b/karbor/services/operationengine/engine/triggers/timetrigger/time_trigger.py index 5235cd86..28f3a60c 100644 --- a/karbor/services/operationengine/engine/triggers/timetrigger/time_trigger.py +++ b/karbor/services/operationengine/engine/triggers/timetrigger/time_trigger.py @@ -21,7 +21,7 @@ import six from stevedore import driver as import_driver from karbor import exception -from karbor.i18n import _, _LE, _LW +from karbor.i18n import _ from karbor.services.operationengine.engine import triggers time_trigger_opts = [ @@ -226,17 +226,16 @@ class TimeTrigger(triggers.BaseTrigger): if operation_id not in self._operation_ids: # Maybe, when traversing this operation_id, it has been # removed by self.unregister_operation - LOG.warn(_LW("Execuete operation %s which is not exist, " - "ignore it"), operation_id) + LOG.warn("Execuete operation %s which is not exist, " + "ignore it", operation_id) continue now = datetime.utcnow() if now >= end_time: - LOG.error(_LE("Can not trigger operations to run. " - "Because it is out of window time. " - "now=%(now)s, end time=%(end_time)s, " - "expect run time=%(expect)s, " - "wating operations=%(ops)s"), + LOG.error("Can not trigger operations to run. Because it is " + "out of window time. now=%(now)s, " + "end time=%(end_time)s, expect run time=%(expect)s," + " wating operations=%(ops)s", {'now': now, 'end_time': end_time, 'expect': expect_run_time, 'ops': operation_ids - sent_ops}) @@ -246,8 +245,8 @@ class TimeTrigger(triggers.BaseTrigger): self._executor.execute_operation( operation_id, now, expect_run_time, window) except Exception: - LOG.exception(_LE("Submit operation to executor " - "failed, operation id=%s"), operation_id) + LOG.exception("Submit operation to executor failed, operation" + " id=%s", operation_id) sent_ops.add(operation_id) @@ -255,10 +254,10 @@ class TimeTrigger(triggers.BaseTrigger): expect_run_time, trigger_property['end_time'], timer) now = datetime.utcnow() if next_time and next_time <= now: - LOG.error(_LE("Next run time:%(next_time)s <= now:%(now)s. Maybe " - "the entry time=%(entry)s is too late, even exceeds " - "the end time of window=%(end)s, or it was blocked " - "where sending the operation to executor."), + LOG.error("Next run time:%(next_time)s <= now:%(now)s. Maybe the " + "entry time=%(entry)s is too late, even exceeds the end" + " time of window=%(end)s, or it was blocked where " + "sending the operation to executor.", {'next_time': next_time, 'now': now, 'entry': entry_time, 'end': end_time}) return next_time diff --git a/karbor/services/operationengine/operations/base.py b/karbor/services/operationengine/operations/base.py index 6c56622c..11b2382c 100644 --- a/karbor/services/operationengine/operations/base.py +++ b/karbor/services/operationengine/operations/base.py @@ -24,7 +24,6 @@ from oslo_log import log as logging from karbor.common import constants from karbor import context -from karbor.i18n import _LE from karbor import objects from karbor.services.operationengine import karbor_client @@ -136,7 +135,7 @@ class Operation(object): try: log_ref.create() except Exception: - LOG.exception(_LE("Execute operation(%s), create log obj failed"), + LOG.exception("Execute operation(%s), create log obj failed", param['operation_id']) return return log_ref @@ -160,7 +159,7 @@ class Operation(object): try: log_ref.save() except Exception: - LOG.exception(_LE("Execute operation(%s), save log failed"), + LOG.exception("Execute operation(%s), save log failed", log_ref.operation_id) def _update_log_when_operation_finished(self, log_ref, state, diff --git a/karbor/services/operationengine/user_trust_manager.py b/karbor/services/operationengine/user_trust_manager.py index ee6e8b1e..b1d5c5b7 100644 --- a/karbor/services/operationengine/user_trust_manager.py +++ b/karbor/services/operationengine/user_trust_manager.py @@ -13,7 +13,6 @@ from oslo_log import log as logging from karbor.common import karbor_keystone_plugin -from karbor.i18n import _LE LOG = logging.getLogger(__name__) @@ -52,8 +51,8 @@ class UserTrustManager(object): try: return auth_info['session'].get_token() except Exception: - LOG.exception(_LE("Get token failed, " - "user_id=%(user_id)s, project_id=%(proj_id)s"), + LOG.exception("Get token failed, user_id=%(user_id)s, " + "project_id=%(proj_id)s", {'user_id': user_id, 'proj_id': project_id}) return None diff --git a/karbor/services/protection/bank_plugins/swift_bank_plugin.py b/karbor/services/protection/bank_plugins/swift_bank_plugin.py index 017d0b59..8037904a 100644 --- a/karbor/services/protection/bank_plugins/swift_bank_plugin.py +++ b/karbor/services/protection/bank_plugins/swift_bank_plugin.py @@ -15,7 +15,7 @@ import math import time from karbor import exception -from karbor.i18n import _, _LE +from karbor.i18n import _ from karbor.services.protection.bank_plugin import BankPlugin from karbor.services.protection.bank_plugin import LeasePlugin from karbor.services.protection import client_factory @@ -88,14 +88,14 @@ class SwiftBankPlugin(BankPlugin, LeasePlugin): self._put_container(self.bank_object_container) self._put_container(self.bank_leases_container) except SwiftConnectionFailed as err: - LOG.error(_LE("bank plugin create container failed.")) + LOG.error("bank plugin create container failed.") raise exception.CreateContainerFailed(reason=err) # acquire lease try: self.acquire_lease() except exception.AcquireLeaseFailed: - LOG.error(_LE("bank plugin acquire lease failed.")) + LOG.error("bank plugin acquire lease failed.") raise # start renew lease @@ -121,27 +121,24 @@ class SwiftBankPlugin(BankPlugin, LeasePlugin): 'x-object-meta-serialized': str(serialized) }) except SwiftConnectionFailed as err: - LOG.error(_LE("update object failed, err: %s."), err) - raise exception.BankUpdateObjectFailed(reason=err, - key=key) + LOG.error("update object failed, err: %s.", err) + raise exception.BankUpdateObjectFailed(reason=err, key=key) def delete_object(self, key): try: self._delete_object(container=self.bank_object_container, obj=key) except SwiftConnectionFailed as err: - LOG.error(_LE("delete object failed, err: %s."), err) - raise exception.BankDeleteObjectFailed(reason=err, - key=key) + LOG.error("delete object failed, err: %s.", err) + raise exception.BankDeleteObjectFailed(reason=err, key=key) def get_object(self, key): try: return self._get_object(container=self.bank_object_container, obj=key) except SwiftConnectionFailed as err: - LOG.error(_LE("get object failed, err: %s."), err) - raise exception.BankGetObjectFailed(reason=err, - key=key) + LOG.error("get object failed, err: %s.", err) + raise exception.BankGetObjectFailed(reason=err, key=key) def list_objects(self, prefix=None, limit=None, marker=None, sort_dir=None): @@ -158,7 +155,7 @@ class SwiftBankPlugin(BankPlugin, LeasePlugin): prefix=prefix, limit=limit, marker=marker) return [obj.get("name") for obj in body] except SwiftConnectionFailed as err: - LOG.error(_LE("list objects failed, err: %s."), err) + LOG.error("list objects failed, err: %s.", err) raise exception.BankListObjectsFailed(reason=err) def acquire_lease(self): @@ -174,7 +171,7 @@ class SwiftBankPlugin(BankPlugin, LeasePlugin): self.lease_expire_time = math.floor( time.time()) + self.lease_expire_window except SwiftConnectionFailed as err: - LOG.error(_LE("acquire lease failed, err:%s."), err) + LOG.error("acquire lease failed, err:%s.", err) raise exception.AcquireLeaseFailed(reason=err) def renew_lease(self): @@ -188,7 +185,7 @@ class SwiftBankPlugin(BankPlugin, LeasePlugin): self.lease_expire_time = math.floor( time.time()) + self.lease_expire_window except SwiftConnectionFailed as err: - LOG.error(_LE("acquire lease failed, err:%s."), err) + LOG.error("acquire lease failed, err:%s.", err) def check_lease_validity(self): if (self.lease_expire_time - math.floor(time.time()) >= diff --git a/karbor/services/protection/checkpoint.py b/karbor/services/protection/checkpoint.py index 3800fcd1..252779ea 100644 --- a/karbor/services/protection/checkpoint.py +++ b/karbor/services/protection/checkpoint.py @@ -13,7 +13,7 @@ from datetime import datetime from karbor.common import constants from karbor import exception -from karbor.i18n import _, _LE +from karbor.i18n import _ from karbor.services.protection import graph from oslo_config import cfg from oslo_log import log as logging @@ -120,7 +120,7 @@ class Checkpoint(object): try: new_md = self._checkpoint_section.get_object(_INDEX_FILE_NAME) except exception.BankGetObjectFailed: - LOG.error(_LE("unable to reload metadata for checkpoint id: %s"), + LOG.error("unable to reload metadata for checkpoint id: %s", self.id) raise exception.CheckpointNotFound(checkpoint_id=self.id) self._assert_supported_version(new_md) diff --git a/karbor/services/protection/client_factory.py b/karbor/services/protection/client_factory.py index b660bbc0..cb77a640 100644 --- a/karbor/services/protection/client_factory.py +++ b/karbor/services/protection/client_factory.py @@ -20,7 +20,7 @@ from oslo_utils import importutils from karbor.common import karbor_keystone_plugin from karbor import exception -from karbor.i18n import _LE +from karbor.i18n import _ LOG = logging.getLogger(__name__) @@ -33,7 +33,7 @@ class ClientFactory(object): def _list_clients(): clients_dir = os.path.join(os.path.dirname(__file__), 'clients') if not os.path.isdir(clients_dir): - LOG.error(_LE('clients directory "%s" not found'), clients_dir) + LOG.error('clients directory "%s" not found', clients_dir) return for file in os.listdir(clients_dir): diff --git a/karbor/services/protection/clients/eisoo.py b/karbor/services/protection/clients/eisoo.py index 285a7b1c..ec3d09f0 100644 --- a/karbor/services/protection/clients/eisoo.py +++ b/karbor/services/protection/clients/eisoo.py @@ -12,14 +12,12 @@ import os +from abclient import client from oslo_config import cfg from oslo_log import log as logging -from karbor.i18n import _LI from karbor import utils -from abclient import client - EISOO_JOB_TYPE = (ORACLE_JOB_TYPE) = (1) EISOO_JOB_STATUS = (RUNNING, SUCCESS, FAILED) = (4, 32, 64) @@ -48,7 +46,7 @@ def create(context, conf): config.register_opts(eisoo_client_opts, group=SERVICE + '_client') - LOG.info(_LI('Creating eisoo client with url %s.'), + LOG.info('Creating eisoo client with url %s.', config.eisoo_client.eisoo_endpoint) abclient = client.ABClient(config.eisoo_client.eisoo_endpoint, config.eisoo_client.eisoo_app_id, diff --git a/karbor/services/protection/clients/heat.py b/karbor/services/protection/clients/heat.py index 7bc77518..1ed8a265 100644 --- a/karbor/services/protection/clients/heat.py +++ b/karbor/services/protection/clients/heat.py @@ -16,7 +16,6 @@ from oslo_config import cfg from oslo_log import log as logging from karbor.common import config -from karbor.i18n import _LE from karbor.services.protection.clients import utils LOG = logging.getLogger(__name__) @@ -93,7 +92,7 @@ def _create_client_with_auth_url(context, client_config, **kwargs): token=auth_token, cacert=cacert, insecure=insecure) return heat except Exception: - LOG.error(_LE('Creating heat client with url %s.'), auth_url) + LOG.error('Creating heat client with url %s.', auth_url) raise diff --git a/karbor/services/protection/clients/nova.py b/karbor/services/protection/clients/nova.py index 064c8583..2a1b5246 100644 --- a/karbor/services/protection/clients/nova.py +++ b/karbor/services/protection/clients/nova.py @@ -16,7 +16,6 @@ from oslo_log import log as logging from karbor.common import config from karbor import exception -from karbor.i18n import _LE from karbor.services.protection.clients import utils LOG = logging.getLogger(__name__) @@ -63,7 +62,7 @@ def create(context, conf, **kwargs): extensions = nc.discover_extensions(NOVACLIENT_VERSION) session = kwargs.get('session') if session is None: - LOG.error(_LE('Creating nova client failed with url %s.'), url) + LOG.error('Creating nova client failed with url %s.', url) raise exception.InvalidParameterValue( err="The parameter session is None.") diff --git a/karbor/services/protection/flows/delete.py b/karbor/services/protection/flows/delete.py index 554a8d30..bf9ea0b1 100644 --- a/karbor/services/protection/flows/delete.py +++ b/karbor/services/protection/flows/delete.py @@ -11,7 +11,6 @@ # under the License. from karbor.common import constants -from karbor.i18n import _LI from karbor.services.protection import resource_flow from oslo_log import log as logging from taskflow import task @@ -44,8 +43,7 @@ class CompleteDeleteTask(task.Task): def get_flow(context, workflow_engine, checkpoint, provider): - LOG.info(_LI("Start get checkpoint flow, checkpoint_id: %s"), - checkpoint.id) + LOG.info("Start get checkpoint flow, checkpoint_id: %s", checkpoint.id) flow_name = "Delete_Checkpoint_" + checkpoint.id delete_flow = workflow_engine.build_flow(flow_name, 'linear') resource_graph = checkpoint.resource_graph diff --git a/karbor/services/protection/flows/restore.py b/karbor/services/protection/flows/restore.py index 7c04cf6f..5492a262 100644 --- a/karbor/services/protection/flows/restore.py +++ b/karbor/services/protection/flows/restore.py @@ -17,7 +17,6 @@ from oslo_service import loopingcall from oslo_utils import uuidutils from karbor.common import constants -from karbor.i18n import _LE, _LI, _LW from karbor.services.protection import client_factory from karbor.services.protection import resource_flow from karbor.services.protection import restore_heat @@ -67,7 +66,7 @@ class CreateHeatTask(task.Task): super(CreateHeatTask, self).__init__(*args, **kwargs) def execute(self, context, heat_conf): - LOG.info(_LI('Creating Heat template. Target: "%s"') + LOG.info('Creating Heat template. Target: "%s"' % heat_conf.get('auth_url', '(None)')) heat_client = client_factory.ClientFactory.create_client( 'heat', context=context, **heat_conf) @@ -86,9 +85,9 @@ class CreateStackTask(task.Task): def execute(self, heat_client, heat_template): stack_name = "restore_%s" % uuidutils.generate_uuid() if heat_template.len() == 0: - LOG.info(_LI('Not creating Heat stack, no resources in template')) + LOG.info('Not creating Heat stack, no resources in template') return None - LOG.info(_LI('Creating Heat stack, stack_name: %s'), stack_name) + LOG.info('Creating Heat stack, stack_name: %s', stack_name) try: body = heat_client.stacks.create( stack_name=stack_name, @@ -96,7 +95,7 @@ class CreateStackTask(task.Task): LOG.debug('Created stack with id: %s', body['stack']['id']) return body['stack']['id'] except Exception: - LOG.error(_LE("use heat to create stack failed")) + LOG.error("use heat to create stack failed") raise @@ -107,10 +106,10 @@ class SyncRestoreStatusTask(task.Task): def execute(self, stack_id, heat_client, restore): if stack_id is None: - LOG.info(_LI('Not syncing Heat stack status, stack is empty')) + LOG.info('Not syncing Heat stack status, stack is empty') return - LOG.info(_LI('Syncing Heat stack status, stack_id: %s'), stack_id) + LOG.info('Syncing Heat stack status, stack_id: %s', stack_id) self._restore = restore sync_status_loop = loopingcall.FixedIntervalLoopingCall( self._sync_status, heat_client, stack_id) @@ -128,12 +127,11 @@ class SyncRestoreStatusTask(task.Task): LOG.debug('Heat stack status: in progress, stack_id: %s', stack_id) elif stack_status == 'CREATE_COMPLETE': - LOG.info(_LI('Heat stack status: complete, stack_id: %s'), - stack_id) + LOG.info('Heat stack status: complete, stack_id: %s', stack_id) self._update_resource_status(heat_client, stack_id) raise loopingcall.LoopingCallDone() else: - LOG.info(_LI('Heat stack status: failure, stack_id: %s'), stack_id) + LOG.info('Heat stack status: failure, stack_id: %s', stack_id) self._update_resource_status(heat_client, stack_id) raise @@ -159,11 +157,8 @@ class SyncRestoreStatusTask(task.Task): ) self._restore.save() except Exception as e: - LOG.warning( - _LW('Unable to update resources status from heat stack. ' - 'Reason: %s'), - e, - ) + LOG.warning('Unable to update resources status from heat stack. ' + 'Reason: %s', e) def get_flow(context, workflow_engine, checkpoint, provider, restore, diff --git a/karbor/services/protection/flows/worker.py b/karbor/services/protection/flows/worker.py index 7723009a..a9c56354 100644 --- a/karbor/services/protection/flows/worker.py +++ b/karbor/services/protection/flows/worker.py @@ -17,7 +17,6 @@ from oslo_utils import importutils from karbor.common import constants from karbor import exception -from karbor.i18n import _LE from karbor.services.protection.flows import delete as flow_delete from karbor.services.protection.flows import protect as flow_protect from karbor.services.protection.flows import restore as flow_restore @@ -40,7 +39,7 @@ class Worker(object): try: self.workflow_engine = self._load_engine(engine_path) except Exception: - LOG.error(_LE("load work flow engine failed")) + LOG.error("load work flow engine failed") raise def _load_engine(self, engine_path): diff --git a/karbor/services/protection/flows/workflow.py b/karbor/services/protection/flows/workflow.py index 3127d4d6..336ec158 100644 --- a/karbor/services/protection/flows/workflow.py +++ b/karbor/services/protection/flows/workflow.py @@ -15,7 +15,7 @@ import futurist import six from karbor import exception -from karbor.i18n import _, _LE +from karbor.i18n import _ from oslo_log import log as logging from taskflow import engines @@ -100,7 +100,7 @@ class TaskFlowEngine(WorkFlowEngine): def get_engine(self, flow, **kwargs): if flow is None: - LOG.error(_LE("The flow is None, build it first")) + LOG.error("The flow is None, build it first") raise exception.InvalidTaskFlowObject( reason=_("The flow is None")) executor = kwargs.get('executor', None) @@ -126,7 +126,7 @@ class TaskFlowEngine(WorkFlowEngine): def run_engine(self, flow_engine): if flow_engine is None: - LOG.error(_LE("Flow engine is None,get it first")) + LOG.error("Flow engine is None,get it first") raise exception.InvalidTaskFlowObject( reason=_("The flow_engine is None")) @@ -136,7 +136,7 @@ class TaskFlowEngine(WorkFlowEngine): def output(self, flow_engine, target=None): if flow_engine is None: - LOG.error(_LE("Flow engine is None,return nothing")) + LOG.error("Flow engine is None,return nothing") raise exception.InvalidTaskFlowObject( reason=_("The flow_engine is None")) if target: @@ -163,7 +163,7 @@ class TaskFlowEngine(WorkFlowEngine): def link_task(self, flow, u, v): if flow is None: - LOG.error(_LE("The flow is None, build it first")) + LOG.error("The flow is None, build it first") raise exception.InvalidTaskFlowObject( reason=_("The flow is None")) if u and v: @@ -171,14 +171,14 @@ class TaskFlowEngine(WorkFlowEngine): def add_tasks(self, flow, *nodes, **kwargs): if flow is None: - LOG.error(_LE("The flow is None, get it first")) + LOG.error("The flow is None, get it first") raise exception.InvalidTaskFlowObject( reason=_("The flow is None")) flow.add(*nodes, **kwargs) def search_task(self, flow, task_id): if not isinstance(flow, graph_flow.Flow): - LOG.error(_LE("this is not a graph flow,flow name:%s"), flow.name) + LOG.error("this is not a graph flow,flow name:%s", flow.name) return for node, meta in flow.iter_nodes(): if not isinstance(node, task.FunctorTask): diff --git a/karbor/services/protection/manager.py b/karbor/services/protection/manager.py index e7a46dab..d13cefd6 100644 --- a/karbor/services/protection/manager.py +++ b/karbor/services/protection/manager.py @@ -25,7 +25,7 @@ import oslo_messaging as messaging from karbor.common import constants from karbor import exception -from karbor.i18n import _, _LI, _LE +from karbor.i18n import _ from karbor import manager from karbor.resource import Resource from karbor.services.protection.flows import worker as flow_manager @@ -81,7 +81,7 @@ class ProtectionManager(manager.Manager): def init_host(self, **kwargs): """Handle initialization if this is a standalone service""" # TODO(wangliuan) - LOG.info(_LI("Starting protection service")) + LOG.info("Starting protection service") @messaging.expected_exceptions(exception.InvalidPlan, exception.ProviderNotFound, @@ -92,7 +92,7 @@ class ProtectionManager(manager.Manager): :param plan: Define that protection plan should be done """ - LOG.info(_LI("Starting protection service:protect action")) + LOG.info("Starting protection service:protect action") LOG.debug("protecting: %s checkpoint_properties:%s", plan, checkpoint_properties) @@ -107,8 +107,7 @@ class ProtectionManager(manager.Manager): checkpoint = checkpoint_collection.create(plan, checkpoint_properties) except Exception as e: - LOG.exception(_LE("Failed to create checkpoint, plan: %s"), - plan_id) + LOG.exception("Failed to create checkpoint, plan: %s", plan_id) exc = exception.FlowError(flow="protect", error="Error creating checkpoint") six.raise_from(exc, e) @@ -121,7 +120,7 @@ class ProtectionManager(manager.Manager): provider=provider, checkpoint=checkpoint) except Exception as e: - LOG.exception(_LE("Failed to create protection flow, plan: %s"), + LOG.exception("Failed to create protection flow, plan: %s", plan_id) raise exception.FlowError( flow="protect", @@ -134,7 +133,7 @@ class ProtectionManager(manager.Manager): exception.CheckpointNotAvailable, exception.FlowError) def restore(self, context, restore, restore_auth): - LOG.info(_LI("Starting restore service:restore action")) + LOG.info("Starting restore service:restore action") checkpoint_id = restore["checkpoint_id"] provider_id = restore["provider_id"] @@ -158,16 +157,15 @@ class ProtectionManager(manager.Manager): restore=restore, restore_auth=restore_auth) except Exception: - LOG.exception( - _LE("Failed to create restore flow checkpoint: %s"), - checkpoint_id) + LOG.exception("Failed to create restore flow checkpoint: %s", + checkpoint_id) raise exception.FlowError( flow="restore", error=_("Failed to create flow")) self._spawn(self.worker.run_flow, flow) def delete(self, context, provider_id, checkpoint_id): - LOG.info(_LI("Starting protection service:delete action")) + LOG.info("Starting protection service:delete action") LOG.debug('provider_id :%s checkpoint_id:%s', provider_id, checkpoint_id) provider = self.provider_registry.show_provider(provider_id) @@ -175,7 +173,7 @@ class ProtectionManager(manager.Manager): checkpoint_collection = provider.get_checkpoint_collection() checkpoint = checkpoint_collection.get(checkpoint_id) except Exception: - LOG.error(_LE("get checkpoint failed, checkpoint_id:%s"), + LOG.error("get checkpoint failed, checkpoint_id:%s", checkpoint_id) raise exception.InvalidInput( reason=_("Invalid checkpoint_id or provider_id")) @@ -196,9 +194,8 @@ class ProtectionManager(manager.Manager): checkpoint=checkpoint, provider=provider) except Exception: - LOG.exception( - _LE("Failed to create delete checkpoint flow, checkpoint:%s."), - checkpoint_id) + LOG.exception("Failed to create delete checkpoint flow," + "checkpoint:%s.", checkpoint_id) raise exception.KarborException(_( "Failed to create delete checkpoint flow." )) @@ -216,8 +213,7 @@ class ProtectionManager(manager.Manager): exception.CheckpointNotFound) def list_checkpoints(self, context, provider_id, marker=None, limit=None, sort_keys=None, sort_dirs=None, filters=None): - LOG.info(_LI("Starting list checkpoints. " - "provider_id:%s"), provider_id) + LOG.info("Starting list checkpoints. provider_id:%s", provider_id) plan_id = filters.get("plan_id", None) start_date = None end_date = None @@ -247,13 +243,12 @@ class ProtectionManager(manager.Manager): return checkpoint.to_dict() def list_protectable_types(self, context): - LOG.info(_LI("Start to list protectable types.")) + LOG.info("Start to list protectable types.") return self.protectable_registry.list_resource_types() @messaging.expected_exceptions(exception.ProtectableTypeNotFound) def show_protectable_type(self, context, protectable_type): - LOG.info(_LI("Start to show protectable type %s"), - protectable_type) + LOG.info("Start to show protectable type %s", protectable_type) plugin = self.protectable_registry.get_protectable_resource_plugin( protectable_type) @@ -285,16 +280,15 @@ class ProtectionManager(manager.Manager): filters=None, parameters=None): - LOG.info(_LI("Start to list protectable instances of type: %s"), + LOG.info("Start to list protectable instances of type: %s", protectable_type) try: resource_instances = self.protectable_registry.list_resources( context, protectable_type, parameters) except exception.ListProtectableResourceFailed as err: - LOG.error(_LE("List resources of type %(type)s failed: %(err)s"), - {'type': protectable_type, - 'err': six.text_type(err)}) + LOG.error("List resources of type %(type)s failed: %(err)s", + {'type': protectable_type, 'err': six.text_type(err)}) raise result = [] @@ -306,7 +300,7 @@ class ProtectionManager(manager.Manager): @messaging.expected_exceptions(exception.ListProtectableResourceFailed) def show_protectable_instance(self, context, protectable_type, protectable_id, parameters=None): - LOG.info(_LI("Start to show protectable instance of type: %s"), + LOG.info("Start to show protectable instance of type: %s", protectable_type) registry = self.protectable_registry @@ -318,8 +312,8 @@ class ProtectionManager(manager.Manager): parameters=parameters ) except exception.ListProtectableResourceFailed as err: - LOG.error(_LE("Show resources of type %(type)s id %(id)s " - "failed: %(err)s"), + LOG.error("Show resources of type %(type)s id %(id)s " + "failed: %(err)s", {'type': protectable_type, 'id': protectable_id, 'err': six.text_type(err)}) @@ -332,8 +326,8 @@ class ProtectionManager(manager.Manager): def list_protectable_dependents(self, context, protectable_id, protectable_type): - LOG.info(_LI("Start to list dependents of resource " - "(type:%(type)s, id:%(id)s)"), + LOG.info("Start to list dependents of resource (type:%(type)s, " + "id:%(id)s)", {'type': protectable_type, 'id': protectable_id}) @@ -345,8 +339,7 @@ class ProtectionManager(manager.Manager): dependent_resources = registry.fetch_dependent_resources( context, parent_resource) except exception.ListProtectableResourceFailed as err: - LOG.error(_LE("List dependent resources of (%(res)s) " - "failed: %(err)s"), + LOG.error("List dependent resources of (%(res)s) failed: %(err)s", {'res': parent_resource, 'err': six.text_type(err)}) raise diff --git a/karbor/services/protection/protectable_plugins/image.py b/karbor/services/protection/protectable_plugins/image.py index f0706e71..35b2e20a 100644 --- a/karbor/services/protection/protectable_plugins/image.py +++ b/karbor/services/protection/protectable_plugins/image.py @@ -14,7 +14,6 @@ import six from karbor.common import constants from karbor import exception -from karbor.i18n import _LE from karbor import resource from karbor.services.protection.client_factory import ClientFactory from karbor.services.protection import protectable_plugin @@ -51,7 +50,7 @@ class ImageProtectablePlugin(protectable_plugin.ProtectablePlugin): try: images = self._glance_client(context).images.list() except Exception as e: - LOG.exception(_LE("List all images from glance failed.")) + LOG.exception("List all images from glance failed.") raise exception.ListProtectableResourceFailed( type=self._SUPPORT_RESOURCE_TYPE, reason=six.text_type(e)) @@ -67,7 +66,7 @@ class ImageProtectablePlugin(protectable_plugin.ProtectablePlugin): try: server = self._nova_client(context).servers.get(parent_resource.id) except Exception as e: - LOG.exception(_LE("List all server from nova failed.")) + LOG.exception("List all server from nova failed.") raise exception.ListProtectableResourceFailed( type=self._SUPPORT_RESOURCE_TYPE, reason=six.text_type(e)) @@ -77,7 +76,7 @@ class ImageProtectablePlugin(protectable_plugin.ProtectablePlugin): try: image = self._glance_client(context).images.get(server.image['id']) except Exception as e: - LOG.exception(_LE("Getting image from glance failed.")) + LOG.exception("Getting image from glance failed.") raise exception.ListProtectableResourceFailed( type=self._SUPPORT_RESOURCE_TYPE, reason=six.text_type(e)) @@ -91,7 +90,7 @@ class ImageProtectablePlugin(protectable_plugin.ProtectablePlugin): try: images = self._glance_client(context).images.list() except Exception as e: - LOG.exception(_LE("List all images from glance failed.")) + LOG.exception("List all images from glance failed.") raise exception.ListProtectableResourceFailed( type=self._SUPPORT_RESOURCE_TYPE, reason=six.text_type(e)) @@ -107,7 +106,7 @@ class ImageProtectablePlugin(protectable_plugin.ProtectablePlugin): try: image = self._glance_client(context).images.get(resource_id) except Exception as e: - LOG.exception(_LE("Show a image from glance failed.")) + LOG.exception("Show a image from glance failed.") raise exception.ProtectableResourceNotFound( id=resource_id, type=self._SUPPORT_RESOURCE_TYPE, diff --git a/karbor/services/protection/protectable_plugins/server.py b/karbor/services/protection/protectable_plugins/server.py index 343e2705..97c5153a 100644 --- a/karbor/services/protection/protectable_plugins/server.py +++ b/karbor/services/protection/protectable_plugins/server.py @@ -14,7 +14,6 @@ import six from karbor.common import constants from karbor import exception -from karbor.i18n import _LE from karbor import resource from karbor.services.protection.client_factory import ClientFactory from karbor.services.protection import protectable_plugin @@ -48,7 +47,7 @@ class ServerProtectablePlugin(protectable_plugin.ProtectablePlugin): try: servers = self._client(context).servers.list(detailed=True) except Exception as e: - LOG.exception(_LE("List all servers from nova failed.")) + LOG.exception("List all servers from nova failed.") raise exception.ListProtectableResourceFailed( type=self._SUPPORT_RESOURCE_TYPE, reason=six.text_type(e)) @@ -63,7 +62,7 @@ class ServerProtectablePlugin(protectable_plugin.ProtectablePlugin): try: server = self._client(context).servers.get(resource_id) except Exception as e: - LOG.exception(_LE("Show a server from nova failed.")) + LOG.exception("Show a server from nova failed.") raise exception.ProtectableResourceNotFound( id=resource_id, type=self._SUPPORT_RESOURCE_TYPE, diff --git a/karbor/services/protection/protectable_plugins/volume.py b/karbor/services/protection/protectable_plugins/volume.py index c364d6a9..bb1542a0 100644 --- a/karbor/services/protection/protectable_plugins/volume.py +++ b/karbor/services/protection/protectable_plugins/volume.py @@ -14,7 +14,6 @@ import six from karbor.common import constants from karbor import exception -from karbor.i18n import _LE from karbor import resource from karbor.services.protection.client_factory import ClientFactory from karbor.services.protection import protectable_plugin @@ -48,8 +47,7 @@ class VolumeProtectablePlugin(protectable_plugin.ProtectablePlugin): try: volumes = self._client(context).volumes.list(detailed=True) except Exception as e: - LOG.exception(_LE("List all summary volumes " - "from cinder failed.")) + LOG.exception("List all summary volumes from cinder failed.") raise exception.ListProtectableResourceFailed( type=self._SUPPORT_RESOURCE_TYPE, reason=six.text_type(e)) @@ -63,8 +61,7 @@ class VolumeProtectablePlugin(protectable_plugin.ProtectablePlugin): try: volume = self._client(context).volumes.get(resource_id) except Exception as e: - LOG.exception(_LE("Show a summary volume " - "from cinder failed.")) + LOG.exception("Show a summary volume from cinder failed.") raise exception.ProtectableResourceNotFound( id=resource_id, type=self._SUPPORT_RESOURCE_TYPE, @@ -91,8 +88,7 @@ class VolumeProtectablePlugin(protectable_plugin.ProtectablePlugin): try: volumes = self._client(context).volumes.list(detailed=True) except Exception as e: - LOG.exception(_LE("List all detailed volumes " - "from cinder failed.")) + LOG.exception("List all detailed volumes from cinder failed.") raise exception.ListProtectableResourceFailed( type=self._SUPPORT_RESOURCE_TYPE, reason=six.text_type(e)) diff --git a/karbor/services/protection/protection_plugins/image/image_protection_plugin.py b/karbor/services/protection/protection_plugins/image/image_protection_plugin.py index 17f21a51..570cd73d 100644 --- a/karbor/services/protection/protection_plugins/image/image_protection_plugin.py +++ b/karbor/services/protection/protection_plugins/image/image_protection_plugin.py @@ -16,7 +16,6 @@ import os from io import BytesIO from karbor.common import constants from karbor import exception -from karbor.i18n import _LE, _LI from karbor.services.protection.client_factory import ClientFactory from karbor.services.protection import protection_plugin from karbor.services.protection.protection_plugins.image \ @@ -81,7 +80,7 @@ class ProtectOperation(protection_plugin.Operation): resource_definition = {"resource_id": image_id} glance_client = ClientFactory.create_client('glance', context) - LOG.info(_LI("Creating image backup, image_id: %s."), image_id) + LOG.info("Creating image backup, image_id: %s.", image_id) try: bank_section.update_object("status", constants.RESOURCE_STATUS_PROTECTING) @@ -95,7 +94,7 @@ class ProtectOperation(protection_plugin.Operation): 'deactivated', 'NotFound'} ) if is_success is not True: - LOG.error(_LE("The status of image (id: %s) is invalid."), + LOG.error("The status of image (id: %s) is invalid.", image_id) raise exception.CreateBackupFailed( reason="The status of image is invalid.", @@ -111,8 +110,7 @@ class ProtectOperation(protection_plugin.Operation): bank_section.update_object("metadata", resource_definition) except Exception as err: - LOG.error(_LE("Create image backup failed, image_id: %s."), - image_id) + LOG.error("Create image backup failed, image_id: %s.", image_id) bank_section.update_object("status", constants.RESOURCE_STATUS_ERROR) raise exception.CreateBackupFailed( @@ -160,11 +158,11 @@ class ProtectOperation(protection_plugin.Operation): # Update resource_definition backup_status bank_section.update_object("status", constants.RESOURCE_STATUS_AVAILABLE) - LOG.info(_LI('Protecting image (id: %s) to bank completed ' - 'successfully'), image_id) + LOG.info('Protecting image (id: %s) to bank completed ' + 'successfully', image_id) except Exception as err: # update resource_definition backup_status - LOG.exception(_LE('Protecting image (id: %s) to bank failed.'), + LOG.exception('Protecting image (id: %s) to bank failed.', image_id) bank_section.update_object("status", constants.RESOURCE_STATUS_ERROR) @@ -182,8 +180,7 @@ class DeleteOperation(protection_plugin.Operation): image_id = resource.id bank_section = checkpoint.get_resource_bank_section(image_id) - LOG.info(_LI("Deleting image backup failed, image_id: %s."), - image_id) + LOG.info("Deleting image backup failed, image_id: %s.", image_id) try: bank_section.update_object("status", constants.RESOURCE_STATUS_DELETING) @@ -195,8 +192,7 @@ class DeleteOperation(protection_plugin.Operation): bank_section.update_object("status", constants.RESOURCE_STATUS_DELETED) except Exception as err: - LOG.error(_LE("delete image backup failed, image_id: %s."), - image_id) + LOG.error("delete image backup failed, image_id: %s.", image_id) bank_section.update_object("status", constants.RESOURCE_STATUS_ERROR) raise exception.DeleteBackupFailed( @@ -215,8 +211,7 @@ class RestoreOperation(protection_plugin.Operation): heat_template = kwargs.get("heat_template") name = parameters.get("restore_name", "karbor-restore-image") - LOG.info(_LI("Restoring image backup, image_id: %s."), - original_image_id) + LOG.info("Restoring image backup, image_id: %s.", original_image_id) glance_client = ClientFactory.create_client('glance', context) bank_section = checkpoint.get_resource_bank_section(original_image_id) @@ -255,7 +250,7 @@ class RestoreOperation(protection_plugin.Operation): 'deactivated', 'not-found'} ) if is_success is not True: - LOG.error(_LE('The status of image is invalid. status:%s'), + LOG.error('The status of image is invalid. status:%s', image_info.status) raise exception.RestoreBackupFailed( resource_id=image_info.id, @@ -269,12 +264,12 @@ class RestoreOperation(protection_plugin.Operation): resource_type=constants.IMAGE_RESOURCE_TYPE) heat_template.put_parameter(original_image_id, image.id) except Exception as e: - LOG.error(_LE("Restore image backup failed, image_id: %s."), + LOG.error("Restore image backup failed, image_id: %s.", original_image_id) raise exception.RestoreBackupFailed( reason=e, resource_id=original_image_id, resource_type=constants.IMAGE_RESOURCE_TYPE) - LOG.info(_LI("Finish restoring image backup, image_id: %s."), + LOG.info("Finish restoring image backup, image_id: %s.", original_image_id) diff --git a/karbor/services/protection/protection_plugins/server/nova_protection_plugin.py b/karbor/services/protection/protection_plugins/server/nova_protection_plugin.py index 6a65661a..61cfa782 100644 --- a/karbor/services/protection/protection_plugins/server/nova_protection_plugin.py +++ b/karbor/services/protection/protection_plugins/server/nova_protection_plugin.py @@ -12,7 +12,6 @@ from karbor.common import constants from karbor import exception -from karbor.i18n import _LE, _LI from karbor.services.protection.client_factory import ClientFactory from karbor.services.protection import protection_plugin from karbor.services.protection.protection_plugins.server \ @@ -52,7 +51,7 @@ class ProtectOperation(protection_plugin.Operation): if resource.id == server_id: server_child_nodes = resource_node.child_nodes - LOG.info(_LI("Creating server backup, server_id: %s. "), server_id) + LOG.info("Creating server backup, server_id: %s. ", server_id) try: bank_section.update_object("status", constants.RESOURCE_STATUS_PROTECTING) @@ -132,11 +131,10 @@ class ProtectOperation(protection_plugin.Operation): # update resource_definition backup_status bank_section.update_object("status", constants.RESOURCE_STATUS_AVAILABLE) - LOG.info(_LI("Finish backup server, server_id: %s."), server_id) + LOG.info("Finish backup server, server_id: %s.", server_id) except Exception as err: # update resource_definition backup_status - LOG.exception(_LE("Create backup failed, server_id: %s."), - server_id) + LOG.exception("Create backup failed, server_id: %s.", server_id) bank_section.update_object("status", constants.RESOURCE_STATUS_ERROR) raise exception.CreateBackupFailed( @@ -153,7 +151,7 @@ class DeleteOperation(protection_plugin.Operation): resource_id = resource.id bank_section = checkpoint.get_resource_bank_section(resource_id) - LOG.info(_LI("deleting server backup, server_id: %s."), resource_id) + LOG.info("deleting server backup, server_id: %s.", resource_id) try: bank_section.update_object("status", @@ -165,10 +163,10 @@ class DeleteOperation(protection_plugin.Operation): bank_section.delete_object(obj) bank_section.update_object("status", constants.RESOURCE_STATUS_DELETED) - LOG.info(_LI("finish delete server, server_id: %s."), resource_id) + LOG.info("finish delete server, server_id: %s.", resource_id) except Exception as err: # update resource_definition backup_status - LOG.error(_LE("Delete backup failed, server_id: %s."), resource_id) + LOG.error("Delete backup failed, server_id: %s.", resource_id) bank_section.update_object("status", constants.RESOURCE_STATUS_ERROR) raise exception.DeleteBackupFailed( @@ -187,8 +185,7 @@ class RestoreOperation(protection_plugin.Operation): restore_name = parameters.get("restore_name", "karbor-restore-server") - LOG.info(_LI("Restoring server backup, server_id: %s."), - original_server_id) + LOG.info("Restoring server backup, server_id: %s.", original_server_id) bank_section = checkpoint.get_resource_bank_section(original_server_id) try: @@ -208,10 +205,10 @@ class RestoreOperation(protection_plugin.Operation): heat_template, original_server_id, resource_definition) LOG.debug("Restoring server backup, heat_template: %s.", heat_template) - LOG.info(_LI("Finish restore server, server_id: %s."), + LOG.info("Finish restore server, server_id: %s.", original_server_id) except Exception as e: - LOG.exception(_LE("restore server backup failed, server_id: %s."), + LOG.exception("restore server backup failed, server_id: %s.", original_server_id) raise exception.RestoreBackupFailed( reason=e, @@ -246,7 +243,7 @@ class RestoreOperation(protection_plugin.Operation): "boot_index": 0, }] else: - LOG.exception(_LE("Restore server backup failed, server_id: %s."), + LOG.exception("Restore server backup failed, server_id: %s.", original_id) raise exception.RestoreBackupFailed( reason="Can not find the boot device of the server.", diff --git a/karbor/services/protection/protection_plugins/volume/cinder_protection_plugin.py b/karbor/services/protection/protection_plugins/volume/cinder_protection_plugin.py index 43d758ba..7b7de325 100644 --- a/karbor/services/protection/protection_plugins/volume/cinder_protection_plugin.py +++ b/karbor/services/protection/protection_plugins/volume/cinder_protection_plugin.py @@ -16,7 +16,6 @@ import six from cinderclient import exceptions as cinder_exc from karbor.common import constants from karbor import exception -from karbor.i18n import _LE, _LI, _LW from karbor.services.protection.client_factory import ClientFactory from karbor.services.protection import protection_plugin from karbor.services.protection.protection_plugins.volume \ @@ -119,8 +118,7 @@ class ProtectOperation(protection_plugin.Operation): return snapshot_id def _delete_snapshot(self, cinder_client, snapshot_id): - LOG.info(_LI('Cleaning up snapshot (snapshot_id: %s)'), - snapshot_id) + LOG.info('Cleaning up snapshot (snapshot_id: %s)', snapshot_id) cinder_client.volume_snapshots.delete(snapshot_id) return status_poll( partial(get_snapshot_status, cinder_client, snapshot_id), @@ -164,11 +162,11 @@ class ProtectOperation(protection_plugin.Operation): **kwargs): volume_id = resource.id if not self._backup_from_snapshot: - LOG.info(_LI('Skipping taking snapshot of volume %s - backing up ' - 'directly'), volume_id) + LOG.info('Skipping taking snapshot of volume %s - backing up ' + 'directly', volume_id) return - LOG.info(_LI('Taking snapshot of volume %s'), volume_id) + LOG.info('Taking snapshot of volume %s', volume_id) bank_section = checkpoint.get_resource_bank_section(volume_id) bank_section.update_object('status', constants.RESOURCE_STATUS_PROTECTING) @@ -188,7 +186,7 @@ class ProtectOperation(protection_plugin.Operation): volume_id = resource.id bank_section = checkpoint.get_resource_bank_section(volume_id) cinder_client = ClientFactory.create_client('cinder', context) - LOG.info(_LI('creating volume backup, volume_id: %s'), volume_id) + LOG.info('creating volume backup, volume_id: %s', volume_id) bank_section.update_object('status', constants.RESOURCE_STATUS_PROTECTING) resource_metadata = { @@ -218,15 +216,12 @@ class ProtectOperation(protection_plugin.Operation): backup_id = self._create_backup(cinder_client, volume_id, backup_name, self.snapshot_id) except Exception as e: - LOG.error( - _LE('Error creating backup (volume_id: %(volume_id)s ' - 'snapshot_id: %(snapshot_id)s): %(reason)s'), - { - 'volume_id': volume_id, - 'snapshot_id': self.snapshot_id, - 'reason': e, - } - ) + LOG.error('Error creating backup (volume_id: %(volume_id)s ' + 'snapshot_id: %(snapshot_id)s): %(reason)s', + {'volume_id': volume_id, + 'snapshot_id': self.snapshot_id, + 'reason': e} + ) bank_section.update_object('status', constants.RESOURCE_STATUS_ERROR) raise exception.CreateBackupFailed( @@ -237,28 +232,21 @@ class ProtectOperation(protection_plugin.Operation): resource_metadata['backup_id'] = backup_id bank_section.update_object('metadata', resource_metadata) - LOG.info( - _LI('Backed up volume (volume_id: %(volume_id)s snapshot_id: ' - '%(snapshot_id)s backup_id: %(backup_id)s) successfully'), - { - 'backup_id': backup_id, - 'snapshot_id': self.snapshot_id, - 'volume_id': volume_id - } - ) + LOG.info('Backed up volume (volume_id: %(volume_id)s snapshot_id: ' + '%(snapshot_id)s backup_id: %(backup_id)s) successfully', + {'backup_id': backup_id, + 'snapshot_id': self.snapshot_id, + 'volume_id': volume_id} + ) if self.snapshot_id: try: self._delete_snapshot(cinder_client, self.snapshot_id) except Exception as e: - LOG.warn( - _LW('Failed deleting snapshot: %(snapshot_id)s. ' - 'Reason: %(reason)s'), - { - 'snapshot_id': self.snapshot_id, - 'reason': e, - } - ) + LOG.warn('Failed deleting snapshot: %(snapshot_id)s. ' + 'Reason: %(reason)s', + {'snapshot_id': self.snapshot_id, 'reason': e} + ) class RestoreOperation(protection_plugin.Operation): @@ -303,7 +291,7 @@ class DeleteOperation(protection_plugin.Operation): backup = cinder_client.backups.get(backup_id) cinder_client.backups.delete(backup) except cinder_exc.NotFound: - LOG.info(_LI('Backup id: %s not found. Assuming deleted'), + LOG.info('Backup id: %s not found. Assuming deleted', backup_id) is_success = status_poll( partial(get_backup_status, cinder_client, backup_id), @@ -318,8 +306,7 @@ class DeleteOperation(protection_plugin.Operation): bank_section.update_object('status', constants.RESOURCE_STATUS_DELETED) except Exception as e: - LOG.error(_LE('delete volume backup failed, backup_id: %s'), - backup_id) + LOG.error('delete volume backup failed, backup_id: %s', backup_id) bank_section.update_object('status', constants.RESOURCE_STATUS_ERROR) raise exception.DeleteBackupFailed( diff --git a/karbor/services/protection/provider.py b/karbor/services/protection/provider.py index e27269c8..a79da67f 100644 --- a/karbor/services/protection/provider.py +++ b/karbor/services/protection/provider.py @@ -14,7 +14,7 @@ import os import six from karbor import exception -from karbor.i18n import _, _LE, _LI +from karbor.i18n import _ from karbor.services.protection import bank_plugin from karbor.services.protection.checkpoint import CheckpointCollection from karbor import utils @@ -115,8 +115,7 @@ class PluggableProtectionProvider(object): plugin = utils.load_plugin(PROTECTION_NAMESPACE, bank_name, self._config) except Exception: - LOG.exception(_LE("Load bank plugin: '%s' failed."), - bank_name) + LOG.exception("Load bank plugin: '%s' failed.", bank_name) raise else: self._bank_plugin = plugin @@ -125,8 +124,7 @@ class PluggableProtectionProvider(object): try: plugin = utils.load_class(PROTECTION_NAMESPACE, plugin_name) except Exception: - LOG.exception(_LE("Load protection plugin: '%s' failed."), - plugin_name) + LOG.exception("Load protection plugin: '%s' failed.", plugin_name) raise else: for resource in plugin.get_supported_resources_types(): @@ -178,12 +176,12 @@ class ProviderRegistry(object): try: provider = PluggableProtectionProvider(provider_config) except Exception as e: - LOG.error(_LE("Load provider: %(provider)s failed. " - "Reason: %(reason)s"), + LOG.error("Load provider: %(provider)s failed. " + "Reason: %(reason)s", {'provider': provider_config.provider.name, 'reason': e}) else: - LOG.info(_LI('Loaded provider: %s successully.'), + LOG.info('Loaded provider: %s successully.', provider_config.provider.name) self.providers[provider.id] = provider diff --git a/karbor/services/protection/resource_flow.py b/karbor/services/protection/resource_flow.py index 11d70602..cc042f8b 100644 --- a/karbor/services/protection/resource_flow.py +++ b/karbor/services/protection/resource_flow.py @@ -13,7 +13,6 @@ from collections import namedtuple from karbor.common import constants from karbor import exception -from karbor.i18n import _LI from karbor.services.protection import graph from oslo_log import log as logging @@ -164,7 +163,7 @@ class ResourceFlowGraphWalkerListener(graph.GraphWalkerListener): def build_resource_flow(operation_type, context, workflow_engine, plugins, resource_graph, parameters): - LOG.info(_LI("Build resource flow for operation %s"), operation_type) + LOG.info("Build resource flow for operation %s", operation_type) resource_graph_flow = workflow_engine.build_flow( 'ResourceGraphFlow_{}'.format(operation_type), diff --git a/karbor/services/protection/restore_heat.py b/karbor/services/protection/restore_heat.py index 6b6a8269..e71441ed 100644 --- a/karbor/services/protection/restore_heat.py +++ b/karbor/services/protection/restore_heat.py @@ -15,7 +15,6 @@ import json import yaml from karbor.exception import InvalidOriginalId -from karbor.i18n import _LE from oslo_log import log as logging LOG = logging.getLogger(__name__) @@ -64,7 +63,7 @@ class HeatTemplate(object): elif original_id in self._original_id_parameter_map: return self._original_id_parameter_map[original_id] else: - LOG.error(_LE("The reference is not found, original_id:%s"), + LOG.error("The reference is not found, original_id:%s", original_id) raise InvalidOriginalId diff --git a/karbor/tests/unit/protection/fakes.py b/karbor/tests/unit/protection/fakes.py index 3d2d2e1a..c5184146 100644 --- a/karbor/tests/unit/protection/fakes.py +++ b/karbor/tests/unit/protection/fakes.py @@ -19,7 +19,6 @@ import mock from oslo_config import cfg from oslo_log import log as logging -from karbor.i18n import _LE from karbor.resource import Resource from karbor.services.protection.bank_plugin import Bank from karbor.services.protection.bank_plugin import BankPlugin @@ -265,7 +264,7 @@ class FakeFlowEngine(object): def add_tasks(self, flow, *nodes, **kwargs): if flow is None: - LOG.error(_LE("The flow is None, get it first")) + LOG.error("The flow is None, get it first") flow.add(*nodes, **kwargs) def link_task(self, flow, u, v): @@ -277,12 +276,12 @@ class FakeFlowEngine(object): elif flow_type == 'graph': return graph_flow.Flow(flow_name) else: - LOG.error(_LE("unsupported flow type:%s"), flow_type) + LOG.error("unsupported flow type:%s", flow_type) return def get_engine(self, flow, **kwargs): if flow is None: - LOG.error(_LE("Flow is None, build it first")) + LOG.error("Flow is None, build it first") return executor = kwargs.get('executor', None) engine = kwargs.get('engine', None) @@ -299,13 +298,13 @@ class FakeFlowEngine(object): def run_engine(self, flow_engine): if flow_engine is None: - LOG.error(_LE("Flow engine is None,get it first")) + LOG.error("Flow engine is None,get it first") return flow_engine.run() def output(self, flow_engine, target=None): if flow_engine is None: - LOG.error(_LE("Flow engine is None,return nothing")) + LOG.error("Flow engine is None,return nothing") return if target: return flow_engine.storage.fetch(target) diff --git a/karbor/utils.py b/karbor/utils.py index 6e2ada8a..eaeeb8ff 100644 --- a/karbor/utils.py +++ b/karbor/utils.py @@ -22,7 +22,7 @@ from oslo_utils import strutils from oslo_utils import timeutils from karbor import exception -from karbor.i18n import _, _LE +from karbor.i18n import _ from stevedore import driver CONF = cfg.CONF @@ -112,8 +112,8 @@ def load_class(namespace, plugin_name): try: return importutils.import_class(plugin_name) except ImportError as e2: - LOG.error(_LE("Error loading plugin by name, %s"), e1) - LOG.error(_LE("Error loading plugin by class, %s"), e2) + LOG.error("Error loading plugin by name, %s", e1) + LOG.error("Error loading plugin by class, %s", e2) raise ImportError(_("Class not found.")) diff --git a/karbor/wsgi/common.py b/karbor/wsgi/common.py index e9b0ab14..279f713e 100644 --- a/karbor/wsgi/common.py +++ b/karbor/wsgi/common.py @@ -25,7 +25,7 @@ import webob.dec import webob.exc from karbor import exception -from karbor.i18n import _, _LE +from karbor.i18n import _ from karbor import utils CONF = cfg.CONF @@ -286,5 +286,5 @@ class Loader(object): try: return deploy.loadapp("config:%s" % self.config_path, name=name) except LookupError: - LOG.exception(_LE("Error loading app %s"), name) + LOG.exception("Error loading app %s", name) raise exception.PasteAppNotFound(name=name, path=self.config_path) diff --git a/karbor/wsgi/eventlet_server.py b/karbor/wsgi/eventlet_server.py index 51e941be..55813c81 100644 --- a/karbor/wsgi/eventlet_server.py +++ b/karbor/wsgi/eventlet_server.py @@ -31,7 +31,7 @@ from oslo_utils import netutils from karbor import exception -from karbor.i18n import _, _LE, _LI +from karbor.i18n import _ socket_opts = [ @@ -173,7 +173,7 @@ class Server(service.ServiceBase): {'host': host, 'port': port}) (self._host, self._port) = self._socket.getsockname()[0:2] - LOG.info(_LI("%(name)s listening on %(_host)s:%(_port)s"), + LOG.info("%(name)s listening on %(_host)s:%(_port)s", {'name': self.name, '_host': self._host, '_port': self._port}) def start(self): @@ -218,9 +218,8 @@ class Server(service.ServiceBase): **ssl_kwargs) except Exception: with excutils.save_and_reraise_exception(): - LOG.error(_LE("Failed to start %(name)s on %(_host)s: " - "%(_port)s with SSL " - "support."), self.__dict__) + LOG.error("Failed to start %(name)s on %(_host)s: " + "%(_port)s with SSL support.", self.__dict__) wsgi_kwargs = { 'func': eventlet.wsgi.server, @@ -252,7 +251,7 @@ class Server(service.ServiceBase): :returns: None """ - LOG.info(_LI("Stopping WSGI server.")) + LOG.info("Stopping WSGI server.") if self._server is not None: # Resize pool to stop new requests from being processed self._pool.resize(0) @@ -271,7 +270,7 @@ class Server(service.ServiceBase): self._pool.waitall() self._server.wait() except greenlet.GreenletExit: - LOG.info(_LI("WSGI server has stopped.")) + LOG.info("WSGI server has stopped.") def reset(self): """Reset server greenpool size to default.