diff --git a/muranoapi/api/middleware/context.py b/muranoapi/api/middleware/context.py index ddf5e5c2..924666bc 100644 --- a/muranoapi/api/middleware/context.py +++ b/muranoapi/api/middleware/context.py @@ -18,8 +18,8 @@ import muranoapi.context import muranoapi.openstack.common.log as logging from muranoapi.openstack.common import wsgi -CONF = cfg.CONF LOG = logging.getLogger(__name__) +CONF = cfg.CONF class ContextMiddleware(wsgi.Middleware): diff --git a/muranoapi/api/v1/deployments.py b/muranoapi/api/v1/deployments.py index 4d47dc82..7e411490 100644 --- a/muranoapi/api/v1/deployments.py +++ b/muranoapi/api/v1/deployments.py @@ -23,8 +23,7 @@ from muranoapi.openstack.common.gettextutils import _ # noqa from muranoapi.openstack.common import log as logging from muranoapi.openstack.common import wsgi - -log = logging.getLogger(__name__) +LOG = logging.getLogger(__name__) API_NAME = 'Deployments' @@ -72,11 +71,11 @@ class Controller(object): def verify_and_get_env(db_session, environment_id, request): environment = db_session.query(models.Environment).get(environment_id) if not environment: - log.info(_('Environment with id {0} not found'.format(environment_id))) + LOG.info(_('Environment with id {0} not found'.format(environment_id))) raise exc.HTTPNotFound if environment.tenant_id != request.context.tenant: - log.info(_('User is not authorized to access this tenant resources.')) + LOG.info(_('User is not authorized to access this tenant resources.')) raise exc.HTTPUnauthorized return environment @@ -84,10 +83,10 @@ def verify_and_get_env(db_session, environment_id, request): def verify_and_get_deployment(db_session, environment_id, deployment_id): deployment = db_session.query(models.Deployment).get(deployment_id) if not deployment: - log.info(_('Deployment with id {0} not found'.format(deployment_id))) + LOG.info(_('Deployment with id {0} not found'.format(deployment_id))) raise exc.HTTPNotFound if deployment.environment_id != environment_id: - log.info(_('Deployment with id {0} not found' + LOG.info(_('Deployment with id {0} not found' ' in environment {1}'.format(deployment_id, environment_id))) raise exc.HTTPBadRequest diff --git a/muranoapi/api/v1/environments.py b/muranoapi/api/v1/environments.py index 4bdf7459..ea7439c3 100644 --- a/muranoapi/api/v1/environments.py +++ b/muranoapi/api/v1/environments.py @@ -26,8 +26,8 @@ from muranoapi.openstack.common.gettextutils import _ # noqa from muranoapi.openstack.common import log as logging from muranoapi.openstack.common import wsgi +LOG = logging.getLogger(__name__) -log = logging.getLogger(__name__) API_NAME = 'Environments' @@ -35,7 +35,7 @@ class Controller(object): @statistics.stats_count(API_NAME, 'Index') def index(self, request): - log.debug(_('Environments:List')) + LOG.debug(_('Environments:List')) #Only environments from same tenant as user should be returned filters = {'tenant_id': request.context.tenant} @@ -46,7 +46,7 @@ class Controller(object): @statistics.stats_count(API_NAME, 'Create') def create(self, request, body): - log.debug(_('Environments:Create '.format(body))) + LOG.debug(_('Environments:Create '.format(body))) environment = envs.EnvironmentServices.create(body.copy(), request.context.tenant) @@ -55,18 +55,18 @@ class Controller(object): @statistics.stats_count(API_NAME, 'Show') def show(self, request, environment_id): - log.debug(_('Environments:Show '.format(environment_id))) + LOG.debug(_('Environments:Show '.format(environment_id))) session = db_session.get_session() environment = session.query(models.Environment).get(environment_id) if environment is None: - log.info('Environment is not found' + LOG.info('Environment is not found' .format(environment_id)) raise exc.HTTPNotFound if environment.tenant_id != request.context.tenant: - log.info(_('User is not authorized to access ' + LOG.info(_('User is not authorized to access ' 'this tenant resources.')) raise exc.HTTPUnauthorized @@ -85,19 +85,19 @@ class Controller(object): @statistics.stats_count(API_NAME, 'Update') def update(self, request, environment_id, body): - log.debug(_('Environments:Update '.format(environment_id, body))) session = db_session.get_session() environment = session.query(models.Environment).get(environment_id) if environment is None: - log.info(_('Environment is not ' + LOG.info(_('Environment is not ' 'found'.format(environment_id))) raise exc.HTTPNotFound if environment.tenant_id != request.context.tenant: - log.info(_('User is not authorized to access ' + LOG.info(_('User is not authorized to access ' 'this tenant resources.')) raise exc.HTTPUnauthorized @@ -108,18 +108,18 @@ class Controller(object): @statistics.stats_count(API_NAME, 'Delete') def delete(self, request, environment_id): - log.debug(_('Environments:Delete '.format(environment_id))) + LOG.debug(_('Environments:Delete '.format(environment_id))) unit = db_session.get_session() environment = unit.query(models.Environment).get(environment_id) if environment is None: - log.info(_('Environment ' + LOG.info(_('Environment ' 'is not found'.format(environment_id))) raise exc.HTTPNotFound if environment.tenant_id != request.context.tenant: - log.info(_('User is not authorized to access ' + LOG.info(_('User is not authorized to access ' 'this tenant resources.')) raise exc.HTTPUnauthorized diff --git a/muranoapi/api/v1/services.py b/muranoapi/api/v1/services.py index 58634083..67cc9d07 100644 --- a/muranoapi/api/v1/services.py +++ b/muranoapi/api/v1/services.py @@ -25,7 +25,7 @@ from muranoapi.openstack.common import wsgi from muranoapi import utils from muranocommon.helpers import token_sanitizer -log = logging.getLogger(__name__) +LOG = logging.getLogger(__name__) API_NAME = 'Services' @@ -48,7 +48,7 @@ class Controller(object): @utils.verify_env @normalize_path def get(self, request, environment_id, path): - log.debug(_('Services:Get '.format(environment_id, path))) session_id = None @@ -69,7 +69,7 @@ class Controller(object): @normalize_path def post(self, request, environment_id, path, body): secure_data = token_sanitizer.TokenSanitizer().sanitize(body) - log.debug(_('Services:Post '.format(environment_id, secure_data, path))) post_data = core_services.CoreServices.post_data @@ -85,7 +85,7 @@ class Controller(object): @utils.verify_env @normalize_path def put(self, request, environment_id, path, body): - log.debug(_('Services:Put '.format(environment_id, body, path))) put_data = core_services.CoreServices.put_data @@ -102,7 +102,7 @@ class Controller(object): @utils.verify_env @normalize_path def delete(self, request, environment_id, path): - log.debug(_('Services:Put '.format(environment_id, path))) delete_data = core_services.CoreServices.delete_data diff --git a/muranoapi/api/v1/sessions.py b/muranoapi/api/v1/sessions.py index 2963cabb..6b34a946 100644 --- a/muranoapi/api/v1/sessions.py +++ b/muranoapi/api/v1/sessions.py @@ -25,32 +25,32 @@ from muranoapi.openstack.common import log as logging from muranoapi.openstack.common import wsgi -log = logging.getLogger(__name__) +LOG = logging.getLogger(__name__) API_NAME = 'Sessions' class Controller(object): @statistics.stats_count(API_NAME, 'Create') def configure(self, request, environment_id): - log.debug(_('Session:Configure '.format(environment_id))) + LOG.debug(_('Session:Configure '.format(environment_id))) unit = db_session.get_session() environment = unit.query(models.Environment).get(environment_id) if environment is None: - log.info(_('Environment ' + LOG.info(_('Environment ' 'is not found'.format(environment_id))) raise exc.HTTPNotFound if environment.tenant_id != request.context.tenant: - log.info(_('User is not authorized to access ' + LOG.info(_('User is not authorized to access ' 'this tenant resources.')) raise exc.HTTPUnauthorized # no new session can be opened if environment has deploying status env_status = envs.EnvironmentServices.get_status(environment_id) if env_status == envs.EnvironmentStatus.deploying: - log.info(_('Could not open session for environment ,' + LOG.info(_('Could not open session for environment ,' 'environment has deploying ' 'status.'.format(environment_id))) raise exc.HTTPForbidden() @@ -62,29 +62,29 @@ class Controller(object): @statistics.stats_count(API_NAME, 'Index') def show(self, request, environment_id, session_id): - log.debug(_('Session:Show '.format(session_id))) + LOG.debug(_('Session:Show '.format(session_id))) unit = db_session.get_session() session = unit.query(models.Session).get(session_id) if session is None: - log.error(_('Session ' + LOG.error(_('Session ' 'is not found'.format(session_id))) raise exc.HTTPNotFound() if session.environment_id != environment_id: - log.error(_('Session is not tied with Environment ' + LOG.error(_('Session is not tied with Environment ' ''.format(session_id, environment_id))) raise exc.HTTPNotFound() user_id = request.context.user if session.user_id != user_id: - log.error(_('User is not authorized to access session' + LOG.error(_('User is not authorized to access session' '.'.format(user_id, session_id))) raise exc.HTTPUnauthorized() if not sessions.SessionServices.validate(session): - log.error(_('Session ' + LOG.error(_('Session ' 'is invalid'.format(session_id))) raise exc.HTTPForbidden() @@ -92,29 +92,29 @@ class Controller(object): @statistics.stats_count(API_NAME, 'Delete') def delete(self, request, environment_id, session_id): - log.debug(_('Session:Delete '.format(session_id))) + LOG.debug(_('Session:Delete '.format(session_id))) unit = db_session.get_session() session = unit.query(models.Session).get(session_id) if session is None: - log.error(_('Session ' + LOG.error(_('Session ' 'is not found'.format(session_id))) raise exc.HTTPNotFound() if session.environment_id != environment_id: - log.error(_('Session is not tied with Environment ' + LOG.error(_('Session is not tied with Environment ' ''.format(session_id, environment_id))) raise exc.HTTPNotFound() user_id = request.context.user if session.user_id != user_id: - log.error(_('User is not authorized to access session' + LOG.error(_('User is not authorized to access session' '.'.format(user_id, session_id))) raise exc.HTTPUnauthorized() if session.state == sessions.SessionState.deploying: - log.error(_('Session is in deploying state and ' + LOG.error(_('Session is in deploying state and ' 'could not be deleted'.format(session_id))) raise exc.HTTPForbidden() @@ -125,28 +125,28 @@ class Controller(object): @statistics.stats_count(API_NAME, 'Deploy') def deploy(self, request, environment_id, session_id): - log.debug(_('Session:Deploy '.format(session_id))) + LOG.debug(_('Session:Deploy '.format(session_id))) unit = db_session.get_session() session = unit.query(models.Session).get(session_id) if session is None: - log.error(_('Session ' + LOG.error(_('Session ' 'is not found'.format(session_id))) raise exc.HTTPNotFound() if session.environment_id != environment_id: - log.error(_('Session is not tied with Environment ' + LOG.error(_('Session is not tied with Environment ' ''.format(session_id, environment_id))) raise exc.HTTPNotFound() if not sessions.SessionServices.validate(session): - log.error(_('Session ' + LOG.error(_('Session ' 'is invalid'.format(session_id))) raise exc.HTTPForbidden() if session.state != sessions.SessionState.open: - log.error(_('Session is already deployed or ' + LOG.error(_('Session is already deployed or ' 'deployment is in progress'.format(session_id))) raise exc.HTTPForbidden() diff --git a/muranoapi/api/v1/statistics.py b/muranoapi/api/v1/statistics.py index e8f8dbcd..ab4b77d8 100644 --- a/muranoapi/api/v1/statistics.py +++ b/muranoapi/api/v1/statistics.py @@ -17,7 +17,7 @@ import time from muranoapi.api import v1 from muranoapi.openstack.common import log as logging -log = logging.getLogger(__name__) +LOG = logging.getLogger(__name__) class StatisticsCollection(object): @@ -67,7 +67,7 @@ def stats_count(api, method): def update_count(api, method, ex_time, tenant=None): - log.debug("Updating count stats for %s, %s on object %s" % (api, + LOG.debug("Updating count stats for %s, %s on object %s" % (api, method, v1.stats)) v1.stats.add_api_request(tenant, ex_time) @@ -75,7 +75,7 @@ def update_count(api, method, ex_time, tenant=None): def update_error_count(api, method, ex_time, tenant=None): - log.debug("Updating count stats for %s, %s on object %s" % (api, + LOG.debug("Updating count stats for %s, %s on object %s" % (api, method, v1.stats)) v1.stats.add_api_error(tenant, ex_time) diff --git a/muranoapi/common/server.py b/muranoapi/common/server.py index f45a16d5..02cc347b 100644 --- a/muranoapi/common/server.py +++ b/muranoapi/common/server.py @@ -32,18 +32,18 @@ from muranocommon.helpers import token_sanitizer RPC_SERVICE = None NOTIFICATION_SERVICE = None -log = logging.getLogger(__name__) +LOG = logging.getLogger(__name__) class ResultEndpoint(object): @staticmethod def process_result(context, result): secure_result = token_sanitizer.TokenSanitizer().sanitize(result) - log.debug(_('Got result from orchestration ' + LOG.debug(_('Got result from orchestration ' 'engine:\n{0}'.format(secure_result))) if 'deleted' in result: - log.debug(_('Result for environment {0} is dropped. Environment ' + LOG.debug(_('Result for environment {0} is dropped. Environment ' 'is deleted'.format(result['id']))) return @@ -51,7 +51,7 @@ class ResultEndpoint(object): environment = unit.query(models.Environment).get(result['id']) if not environment: - log.warning(_('Environment result could not be handled, specified ' + LOG.warning(_('Environment result could not be handled, specified ' 'environment was not found in database')) return @@ -93,7 +93,7 @@ class ResultEndpoint(object): class ReportNotificationEndpoint(object): @staticmethod def report_notification(context, report): - log.debug(_('Got report from orchestration ' + LOG.debug(_('Got report from orchestration ' 'engine:\n{0}'.format(report))) report['entity_id'] = report['id'] diff --git a/muranoapi/common/statservice.py b/muranoapi/common/statservice.py index 5fda13c7..f9b27580 100644 --- a/muranoapi/common/statservice.py +++ b/muranoapi/common/statservice.py @@ -27,8 +27,8 @@ from muranoapi.openstack.common import log as logging from muranoapi.openstack.common import service -conf = config.CONF.stats -log = logging.getLogger(__name__) +CONF_STATS = config.CONF.stats +LOG = logging.getLogger(__name__) class StatsCollectingService(service.Service): @@ -47,15 +47,15 @@ class StatsCollectingService(service.Service): self(StatsCollectingService, self).stop() def _collect_stats_loop(self): - period = conf.period * 60 + period = CONF_STATS.period * 60 while True: self.update_stats() eventlet.sleep(period) def update_stats(self): - log.debug(_("Updating statistic information.")) - log.debug("Stats object: %s" % v1.stats) - log.debug("Stats: Requests:%s Errors: %s Ave.Res.Time %2.4f\n" + LOG.debug(_("Updating statistic information.")) + LOG.debug("Stats object: %s" % v1.stats) + LOG.debug("Stats: Requests:%s Errors: %s Ave.Res.Time %2.4f\n" "Per tenant: %s" % (v1.stats.request_count, v1.stats.error_count, @@ -87,5 +87,5 @@ class StatsCollectingService(service.Service): stats.errors_per_second = errors_per_second self._stats_db.update(self._hostname, stats) except Exception as e: - log.error(_("Failed to get statistics object " + LOG.error(_("Failed to get statistics object " "form a database. %s" % e)) diff --git a/muranoapi/common/utils.py b/muranoapi/common/utils.py index 86ab3c9d..cca827db 100644 --- a/muranoapi/common/utils.py +++ b/muranoapi/common/utils.py @@ -23,7 +23,7 @@ from muranoapi.openstack.common.gettextutils import _ # noqa from muranoapi.openstack.common import log as logging -log = logging.getLogger(__name__) +LOG = logging.getLogger(__name__) class TraverseHelper(object): @@ -183,8 +183,8 @@ def retry(ExceptionToCheck, tries=4, delay=3, backoff=2): return f(*args, **kwargs) except ExceptionToCheck as e: - log.exception(e) - log.info(_("Retrying in {0} seconds...".format(mdelay))) + LOG.exception(e) + LOG.info(_("Retrying in {0} seconds...".format(mdelay))) eventlet.sleep(mdelay) @@ -201,14 +201,14 @@ def retry(ExceptionToCheck, tries=4, delay=3, backoff=2): def handle(f): - """Handles exception in wrapped function and writes to log.""" + """Handles exception in wrapped function and writes to LOG.""" @func.wraps(f) def f_handle(*args, **kwargs): try: return f(*args, **kwargs) except Exception as e: - log.exception(e) + LOG.exception(e) return f_handle diff --git a/muranoapi/db/session.py b/muranoapi/db/session.py index 2905a89f..80e34f55 100644 --- a/muranoapi/db/session.py +++ b/muranoapi/db/session.py @@ -30,8 +30,7 @@ from muranoapi.openstack.common.db.sqlalchemy import session as db_session from muranoapi.openstack.common.gettextutils import _ # noqa from muranoapi.openstack.common import log as logging -log = logging.getLogger(__name__) - +LOG = logging.getLogger(__name__) CONF = config.CONF @@ -40,10 +39,10 @@ def get_session(autocommit=True, expire_on_commit=False): expire_on_commit=expire_on_commit) if s: if CONF.database.auto_create: - log.info(_('auto-creating DB')) + LOG.info(_('auto-creating DB')) _auto_create_db() else: - log.info(_('not auto-creating DB')) + LOG.info(_('not auto-creating DB')) return s diff --git a/muranoapi/utils.py b/muranoapi/utils.py index 6381003b..c7e47384 100644 --- a/muranoapi/utils.py +++ b/muranoapi/utils.py @@ -13,7 +13,6 @@ # under the License. import functools -import logging from webob import exc @@ -21,8 +20,9 @@ from muranoapi.db import models from muranoapi.db.services import sessions from muranoapi.db import session as db_session from muranoapi.openstack.common.gettextutils import _ # noqa +from muranoapi.openstack.common import log as logging -log = logging.getLogger(__name__) +LOG = logging.getLogger(__name__) def verify_env(func): @@ -31,13 +31,13 @@ def verify_env(func): unit = db_session.get_session() environment = unit.query(models.Environment).get(environment_id) if environment is None: - log.info(_("Environment with id '{0}'" + LOG.info(_("Environment with id '{0}'" " not found".format(environment_id))) raise exc.HTTPNotFound() if hasattr(request, 'context'): if environment.tenant_id != request.context.tenant: - log.info(_('User is not authorized to access' + LOG.info(_('User is not authorized to access' ' this tenant resources')) raise exc.HTTPUnauthorized() @@ -49,7 +49,7 @@ def verify_session(func): @functools.wraps(func) def __inner(self, request, *args, **kwargs): if hasattr(request, 'context') and not request.context.session: - log.info(_('Session is required for this call')) + LOG.info(_('Session is required for this call')) raise exc.HTTPForbidden() session_id = request.context.session @@ -58,17 +58,17 @@ def verify_session(func): session = unit.query(models.Session).get(session_id) if session is None: - log.info(_('Session ' + LOG.info(_('Session ' 'is not found'.format(session_id))) raise exc.HTTPForbidden() if not sessions.SessionServices.validate(session): - log.info(_('Session ' + LOG.info(_('Session ' 'is invalid'.format(session_id))) raise exc.HTTPForbidden() if session.state == sessions.SessionState.deploying: - log.info(_('Session is already in ' + LOG.info(_('Session is already in ' 'deployment state'.format(session_id))) raise exc.HTTPForbidden() return func(self, request, *args, **kwargs)