Merge "Lead log spelling to the one style"

This commit is contained in:
Jenkins 2014-03-25 08:42:33 +00:00 committed by Gerrit Code Review
commit afdfcc65eb
11 changed files with 74 additions and 76 deletions

View File

@ -18,8 +18,8 @@ import muranoapi.context
import muranoapi.openstack.common.log as logging import muranoapi.openstack.common.log as logging
from muranoapi.openstack.common import wsgi from muranoapi.openstack.common import wsgi
CONF = cfg.CONF
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
CONF = cfg.CONF
class ContextMiddleware(wsgi.Middleware): class ContextMiddleware(wsgi.Middleware):

View File

@ -23,8 +23,7 @@ from muranoapi.openstack.common.gettextutils import _ # noqa
from muranoapi.openstack.common import log as logging from muranoapi.openstack.common import log as logging
from muranoapi.openstack.common import wsgi from muranoapi.openstack.common import wsgi
LOG = logging.getLogger(__name__)
log = logging.getLogger(__name__)
API_NAME = 'Deployments' API_NAME = 'Deployments'
@ -72,11 +71,11 @@ class Controller(object):
def verify_and_get_env(db_session, environment_id, request): def verify_and_get_env(db_session, environment_id, request):
environment = db_session.query(models.Environment).get(environment_id) environment = db_session.query(models.Environment).get(environment_id)
if not environment: 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 raise exc.HTTPNotFound
if environment.tenant_id != request.context.tenant: 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 raise exc.HTTPUnauthorized
return environment 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): def verify_and_get_deployment(db_session, environment_id, deployment_id):
deployment = db_session.query(models.Deployment).get(deployment_id) deployment = db_session.query(models.Deployment).get(deployment_id)
if not deployment: 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 raise exc.HTTPNotFound
if deployment.environment_id != environment_id: 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, ' in environment {1}'.format(deployment_id,
environment_id))) environment_id)))
raise exc.HTTPBadRequest raise exc.HTTPBadRequest

View File

@ -26,8 +26,8 @@ from muranoapi.openstack.common.gettextutils import _ # noqa
from muranoapi.openstack.common import log as logging from muranoapi.openstack.common import log as logging
from muranoapi.openstack.common import wsgi from muranoapi.openstack.common import wsgi
LOG = logging.getLogger(__name__)
log = logging.getLogger(__name__)
API_NAME = 'Environments' API_NAME = 'Environments'
@ -35,7 +35,7 @@ class Controller(object):
@statistics.stats_count(API_NAME, 'Index') @statistics.stats_count(API_NAME, 'Index')
def index(self, request): def index(self, request):
log.debug(_('Environments:List')) LOG.debug(_('Environments:List'))
#Only environments from same tenant as user should be returned #Only environments from same tenant as user should be returned
filters = {'tenant_id': request.context.tenant} filters = {'tenant_id': request.context.tenant}
@ -46,7 +46,7 @@ class Controller(object):
@statistics.stats_count(API_NAME, 'Create') @statistics.stats_count(API_NAME, 'Create')
def create(self, request, body): def create(self, request, body):
log.debug(_('Environments:Create <Body {0}>'.format(body))) LOG.debug(_('Environments:Create <Body {0}>'.format(body)))
environment = envs.EnvironmentServices.create(body.copy(), environment = envs.EnvironmentServices.create(body.copy(),
request.context.tenant) request.context.tenant)
@ -55,18 +55,18 @@ class Controller(object):
@statistics.stats_count(API_NAME, 'Show') @statistics.stats_count(API_NAME, 'Show')
def show(self, request, environment_id): def show(self, request, environment_id):
log.debug(_('Environments:Show <Id: {0}>'.format(environment_id))) LOG.debug(_('Environments:Show <Id: {0}>'.format(environment_id)))
session = db_session.get_session() session = db_session.get_session()
environment = session.query(models.Environment).get(environment_id) environment = session.query(models.Environment).get(environment_id)
if environment is None: if environment is None:
log.info('Environment <EnvId {0}> is not found' LOG.info('Environment <EnvId {0}> is not found'
.format(environment_id)) .format(environment_id))
raise exc.HTTPNotFound raise exc.HTTPNotFound
if environment.tenant_id != request.context.tenant: 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.')) 'this tenant resources.'))
raise exc.HTTPUnauthorized raise exc.HTTPUnauthorized
@ -85,19 +85,19 @@ class Controller(object):
@statistics.stats_count(API_NAME, 'Update') @statistics.stats_count(API_NAME, 'Update')
def update(self, request, environment_id, body): def update(self, request, environment_id, body):
log.debug(_('Environments:Update <Id: {0}, ' LOG.debug(_('Environments:Update <Id: {0}, '
'Body: {1}>'.format(environment_id, body))) 'Body: {1}>'.format(environment_id, body)))
session = db_session.get_session() session = db_session.get_session()
environment = session.query(models.Environment).get(environment_id) environment = session.query(models.Environment).get(environment_id)
if environment is None: if environment is None:
log.info(_('Environment <EnvId {0}> is not ' LOG.info(_('Environment <EnvId {0}> is not '
'found'.format(environment_id))) 'found'.format(environment_id)))
raise exc.HTTPNotFound raise exc.HTTPNotFound
if environment.tenant_id != request.context.tenant: 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.')) 'this tenant resources.'))
raise exc.HTTPUnauthorized raise exc.HTTPUnauthorized
@ -108,18 +108,18 @@ class Controller(object):
@statistics.stats_count(API_NAME, 'Delete') @statistics.stats_count(API_NAME, 'Delete')
def delete(self, request, environment_id): def delete(self, request, environment_id):
log.debug(_('Environments:Delete <Id: {0}>'.format(environment_id))) LOG.debug(_('Environments:Delete <Id: {0}>'.format(environment_id)))
unit = db_session.get_session() unit = db_session.get_session()
environment = unit.query(models.Environment).get(environment_id) environment = unit.query(models.Environment).get(environment_id)
if environment is None: if environment is None:
log.info(_('Environment <EnvId {0}> ' LOG.info(_('Environment <EnvId {0}> '
'is not found'.format(environment_id))) 'is not found'.format(environment_id)))
raise exc.HTTPNotFound raise exc.HTTPNotFound
if environment.tenant_id != request.context.tenant: 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.')) 'this tenant resources.'))
raise exc.HTTPUnauthorized raise exc.HTTPUnauthorized

View File

@ -25,7 +25,7 @@ from muranoapi.openstack.common import wsgi
from muranoapi import utils from muranoapi import utils
log = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
API_NAME = 'Services' API_NAME = 'Services'
@ -48,7 +48,7 @@ class Controller(object):
@utils.verify_env @utils.verify_env
@normalize_path @normalize_path
def get(self, request, environment_id, path): def get(self, request, environment_id, path):
log.debug(_('Services:Get <EnvId: {0}, ' LOG.debug(_('Services:Get <EnvId: {0}, '
'Path: {1}>'.format(environment_id, path))) 'Path: {1}>'.format(environment_id, path)))
session_id = None session_id = None
@ -69,7 +69,7 @@ class Controller(object):
@normalize_path @normalize_path
def post(self, request, environment_id, path, body): def post(self, request, environment_id, path, body):
secure_data = token_sanitizer.TokenSanitizer().sanitize(body) secure_data = token_sanitizer.TokenSanitizer().sanitize(body)
log.debug(_('Services:Post <EnvId: {0}, Path: {2}, ' LOG.debug(_('Services:Post <EnvId: {0}, Path: {2}, '
'Body: {1}>'.format(environment_id, secure_data, path))) 'Body: {1}>'.format(environment_id, secure_data, path)))
post_data = core_services.CoreServices.post_data post_data = core_services.CoreServices.post_data
@ -85,7 +85,7 @@ class Controller(object):
@utils.verify_env @utils.verify_env
@normalize_path @normalize_path
def put(self, request, environment_id, path, body): def put(self, request, environment_id, path, body):
log.debug(_('Services:Put <EnvId: {0}, Path: {2}, ' LOG.debug(_('Services:Put <EnvId: {0}, Path: {2}, '
'Body: {1}>'.format(environment_id, body, path))) 'Body: {1}>'.format(environment_id, body, path)))
put_data = core_services.CoreServices.put_data put_data = core_services.CoreServices.put_data
@ -102,7 +102,7 @@ class Controller(object):
@utils.verify_env @utils.verify_env
@normalize_path @normalize_path
def delete(self, request, environment_id, path): def delete(self, request, environment_id, path):
log.debug(_('Services:Put <EnvId: {0}, ' LOG.debug(_('Services:Put <EnvId: {0}, '
'Path: {1}>'.format(environment_id, path))) 'Path: {1}>'.format(environment_id, path)))
delete_data = core_services.CoreServices.delete_data delete_data = core_services.CoreServices.delete_data

View File

@ -25,32 +25,32 @@ from muranoapi.openstack.common import log as logging
from muranoapi.openstack.common import wsgi from muranoapi.openstack.common import wsgi
log = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
API_NAME = 'Sessions' API_NAME = 'Sessions'
class Controller(object): class Controller(object):
@statistics.stats_count(API_NAME, 'Create') @statistics.stats_count(API_NAME, 'Create')
def configure(self, request, environment_id): def configure(self, request, environment_id):
log.debug(_('Session:Configure <EnvId: {0}>'.format(environment_id))) LOG.debug(_('Session:Configure <EnvId: {0}>'.format(environment_id)))
unit = db_session.get_session() unit = db_session.get_session()
environment = unit.query(models.Environment).get(environment_id) environment = unit.query(models.Environment).get(environment_id)
if environment is None: if environment is None:
log.info(_('Environment <EnvId {0}> ' LOG.info(_('Environment <EnvId {0}> '
'is not found'.format(environment_id))) 'is not found'.format(environment_id)))
raise exc.HTTPNotFound raise exc.HTTPNotFound
if environment.tenant_id != request.context.tenant: 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.')) 'this tenant resources.'))
raise exc.HTTPUnauthorized raise exc.HTTPUnauthorized
# no new session can be opened if environment has deploying status # no new session can be opened if environment has deploying status
env_status = envs.EnvironmentServices.get_status(environment_id) env_status = envs.EnvironmentServices.get_status(environment_id)
if env_status == envs.EnvironmentStatus.deploying: if env_status == envs.EnvironmentStatus.deploying:
log.info(_('Could not open session for environment <EnvId: {0}>,' LOG.info(_('Could not open session for environment <EnvId: {0}>,'
'environment has deploying ' 'environment has deploying '
'status.'.format(environment_id))) 'status.'.format(environment_id)))
raise exc.HTTPForbidden() raise exc.HTTPForbidden()
@ -62,29 +62,29 @@ class Controller(object):
@statistics.stats_count(API_NAME, 'Index') @statistics.stats_count(API_NAME, 'Index')
def show(self, request, environment_id, session_id): def show(self, request, environment_id, session_id):
log.debug(_('Session:Show <SessionId: {0}>'.format(session_id))) LOG.debug(_('Session:Show <SessionId: {0}>'.format(session_id)))
unit = db_session.get_session() unit = db_session.get_session()
session = unit.query(models.Session).get(session_id) session = unit.query(models.Session).get(session_id)
if session is None: if session is None:
log.error(_('Session <SessionId {0}> ' LOG.error(_('Session <SessionId {0}> '
'is not found'.format(session_id))) 'is not found'.format(session_id)))
raise exc.HTTPNotFound() raise exc.HTTPNotFound()
if session.environment_id != environment_id: if session.environment_id != environment_id:
log.error(_('Session <SessionId {0}> is not tied with Environment ' LOG.error(_('Session <SessionId {0}> is not tied with Environment '
'<EnvId {1}>'.format(session_id, environment_id))) '<EnvId {1}>'.format(session_id, environment_id)))
raise exc.HTTPNotFound() raise exc.HTTPNotFound()
user_id = request.context.user user_id = request.context.user
if session.user_id != user_id: if session.user_id != user_id:
log.error(_('User <UserId {0}> is not authorized to access session' LOG.error(_('User <UserId {0}> is not authorized to access session'
'<SessionId {1}>.'.format(user_id, session_id))) '<SessionId {1}>.'.format(user_id, session_id)))
raise exc.HTTPUnauthorized() raise exc.HTTPUnauthorized()
if not sessions.SessionServices.validate(session): if not sessions.SessionServices.validate(session):
log.error(_('Session <SessionId {0}> ' LOG.error(_('Session <SessionId {0}> '
'is invalid'.format(session_id))) 'is invalid'.format(session_id)))
raise exc.HTTPForbidden() raise exc.HTTPForbidden()
@ -92,29 +92,29 @@ class Controller(object):
@statistics.stats_count(API_NAME, 'Delete') @statistics.stats_count(API_NAME, 'Delete')
def delete(self, request, environment_id, session_id): def delete(self, request, environment_id, session_id):
log.debug(_('Session:Delete <SessionId: {0}>'.format(session_id))) LOG.debug(_('Session:Delete <SessionId: {0}>'.format(session_id)))
unit = db_session.get_session() unit = db_session.get_session()
session = unit.query(models.Session).get(session_id) session = unit.query(models.Session).get(session_id)
if session is None: if session is None:
log.error(_('Session <SessionId {0}> ' LOG.error(_('Session <SessionId {0}> '
'is not found'.format(session_id))) 'is not found'.format(session_id)))
raise exc.HTTPNotFound() raise exc.HTTPNotFound()
if session.environment_id != environment_id: if session.environment_id != environment_id:
log.error(_('Session <SessionId {0}> is not tied with Environment ' LOG.error(_('Session <SessionId {0}> is not tied with Environment '
'<EnvId {1}>'.format(session_id, environment_id))) '<EnvId {1}>'.format(session_id, environment_id)))
raise exc.HTTPNotFound() raise exc.HTTPNotFound()
user_id = request.context.user user_id = request.context.user
if session.user_id != user_id: if session.user_id != user_id:
log.error(_('User <UserId {0}> is not authorized to access session' LOG.error(_('User <UserId {0}> is not authorized to access session'
'<SessionId {1}>.'.format(user_id, session_id))) '<SessionId {1}>.'.format(user_id, session_id)))
raise exc.HTTPUnauthorized() raise exc.HTTPUnauthorized()
if session.state == sessions.SessionState.deploying: if session.state == sessions.SessionState.deploying:
log.error(_('Session <SessionId: {0}> is in deploying state and ' LOG.error(_('Session <SessionId: {0}> is in deploying state and '
'could not be deleted'.format(session_id))) 'could not be deleted'.format(session_id)))
raise exc.HTTPForbidden() raise exc.HTTPForbidden()
@ -125,28 +125,28 @@ class Controller(object):
@statistics.stats_count(API_NAME, 'Deploy') @statistics.stats_count(API_NAME, 'Deploy')
def deploy(self, request, environment_id, session_id): def deploy(self, request, environment_id, session_id):
log.debug(_('Session:Deploy <SessionId: {0}>'.format(session_id))) LOG.debug(_('Session:Deploy <SessionId: {0}>'.format(session_id)))
unit = db_session.get_session() unit = db_session.get_session()
session = unit.query(models.Session).get(session_id) session = unit.query(models.Session).get(session_id)
if session is None: if session is None:
log.error(_('Session <SessionId {0}> ' LOG.error(_('Session <SessionId {0}> '
'is not found'.format(session_id))) 'is not found'.format(session_id)))
raise exc.HTTPNotFound() raise exc.HTTPNotFound()
if session.environment_id != environment_id: if session.environment_id != environment_id:
log.error(_('Session <SessionId {0}> is not tied with Environment ' LOG.error(_('Session <SessionId {0}> is not tied with Environment '
'<EnvId {1}>'.format(session_id, environment_id))) '<EnvId {1}>'.format(session_id, environment_id)))
raise exc.HTTPNotFound() raise exc.HTTPNotFound()
if not sessions.SessionServices.validate(session): if not sessions.SessionServices.validate(session):
log.error(_('Session <SessionId {0}> ' LOG.error(_('Session <SessionId {0}> '
'is invalid'.format(session_id))) 'is invalid'.format(session_id)))
raise exc.HTTPForbidden() raise exc.HTTPForbidden()
if session.state != sessions.SessionState.open: if session.state != sessions.SessionState.open:
log.error(_('Session <SessionId {0}> is already deployed or ' LOG.error(_('Session <SessionId {0}> is already deployed or '
'deployment is in progress'.format(session_id))) 'deployment is in progress'.format(session_id)))
raise exc.HTTPForbidden() raise exc.HTTPForbidden()

View File

@ -17,7 +17,7 @@ import time
from muranoapi.api import v1 from muranoapi.api import v1
from muranoapi.openstack.common import log as logging from muranoapi.openstack.common import log as logging
log = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
class StatisticsCollection(object): class StatisticsCollection(object):
@ -67,7 +67,7 @@ def stats_count(api, method):
def update_count(api, method, ex_time, tenant=None): 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, method,
v1.stats)) v1.stats))
v1.stats.add_api_request(tenant, ex_time) 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): 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, method,
v1.stats)) v1.stats))
v1.stats.add_api_error(tenant, ex_time) v1.stats.add_api_error(tenant, ex_time)

View File

@ -33,18 +33,18 @@ from muranoapi.openstack.common import timeutils
RPC_SERVICE = None RPC_SERVICE = None
NOTIFICATION_SERVICE = None NOTIFICATION_SERVICE = None
log = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
class ResultEndpoint(object): class ResultEndpoint(object):
@staticmethod @staticmethod
def process_result(context, result): def process_result(context, result):
secure_result = token_sanitizer.TokenSanitizer().sanitize(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))) 'engine:\n{0}'.format(secure_result)))
if 'deleted' in 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']))) 'is deleted'.format(result['id'])))
return return
@ -52,7 +52,7 @@ class ResultEndpoint(object):
environment = unit.query(models.Environment).get(result['id']) environment = unit.query(models.Environment).get(result['id'])
if not environment: 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')) 'environment was not found in database'))
return return
@ -94,7 +94,7 @@ class ResultEndpoint(object):
class ReportNotificationEndpoint(object): class ReportNotificationEndpoint(object):
@staticmethod @staticmethod
def report_notification(context, report): def report_notification(context, report):
log.debug(_('Got report from orchestration ' LOG.debug(_('Got report from orchestration '
'engine:\n{0}'.format(report))) 'engine:\n{0}'.format(report)))
report['entity_id'] = report['id'] report['entity_id'] = report['id']

View File

@ -27,8 +27,8 @@ from muranoapi.openstack.common import log as logging
from muranoapi.openstack.common import service from muranoapi.openstack.common import service
conf = config.CONF.stats CONF_STATS = config.CONF.stats
log = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
class StatsCollectingService(service.Service): class StatsCollectingService(service.Service):
@ -47,15 +47,15 @@ class StatsCollectingService(service.Service):
self(StatsCollectingService, self).stop() self(StatsCollectingService, self).stop()
def _collect_stats_loop(self): def _collect_stats_loop(self):
period = conf.period * 60 period = CONF_STATS.period * 60
while True: while True:
self.update_stats() self.update_stats()
eventlet.sleep(period) eventlet.sleep(period)
def update_stats(self): def update_stats(self):
log.debug(_("Updating statistic information.")) LOG.debug(_("Updating statistic information."))
log.debug("Stats object: %s" % v1.stats) LOG.debug("Stats object: %s" % v1.stats)
log.debug("Stats: Requests:%s Errors: %s Ave.Res.Time %2.4f\n" LOG.debug("Stats: Requests:%s Errors: %s Ave.Res.Time %2.4f\n"
"Per tenant: %s" % "Per tenant: %s" %
(v1.stats.request_count, (v1.stats.request_count,
v1.stats.error_count, v1.stats.error_count,
@ -87,5 +87,5 @@ class StatsCollectingService(service.Service):
stats.errors_per_second = errors_per_second stats.errors_per_second = errors_per_second
self._stats_db.update(self._hostname, stats) self._stats_db.update(self._hostname, stats)
except Exception as e: except Exception as e:
log.error(_("Failed to get statistics object " LOG.error(_("Failed to get statistics object "
"form a database. %s" % e)) "form a database. %s" % e))

View File

@ -23,7 +23,7 @@ from muranoapi.openstack.common.gettextutils import _ # noqa
from muranoapi.openstack.common import log as logging from muranoapi.openstack.common import log as logging
log = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
class TraverseHelper(object): class TraverseHelper(object):
@ -183,8 +183,8 @@ def retry(ExceptionToCheck, tries=4, delay=3, backoff=2):
return f(*args, **kwargs) return f(*args, **kwargs)
except ExceptionToCheck as e: except ExceptionToCheck as e:
log.exception(e) LOG.exception(e)
log.info(_("Retrying in {0} seconds...".format(mdelay))) LOG.info(_("Retrying in {0} seconds...".format(mdelay)))
eventlet.sleep(mdelay) eventlet.sleep(mdelay)
@ -201,14 +201,14 @@ def retry(ExceptionToCheck, tries=4, delay=3, backoff=2):
def handle(f): def handle(f):
"""Handles exception in wrapped function and writes to log.""" """Handles exception in wrapped function and writes to LOG."""
@func.wraps(f) @func.wraps(f)
def f_handle(*args, **kwargs): def f_handle(*args, **kwargs):
try: try:
return f(*args, **kwargs) return f(*args, **kwargs)
except Exception as e: except Exception as e:
log.exception(e) LOG.exception(e)
return f_handle return f_handle

View File

@ -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.gettextutils import _ # noqa
from muranoapi.openstack.common import log as logging from muranoapi.openstack.common import log as logging
log = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
CONF = config.CONF CONF = config.CONF
@ -40,10 +39,10 @@ def get_session(autocommit=True, expire_on_commit=False):
expire_on_commit=expire_on_commit) expire_on_commit=expire_on_commit)
if s: if s:
if CONF.database.auto_create: if CONF.database.auto_create:
log.info(_('auto-creating DB')) LOG.info(_('auto-creating DB'))
_auto_create_db() _auto_create_db()
else: else:
log.info(_('not auto-creating DB')) LOG.info(_('not auto-creating DB'))
return s return s

View File

@ -13,7 +13,6 @@
# under the License. # under the License.
import functools import functools
import logging
from webob import exc from webob import exc
@ -21,8 +20,9 @@ from muranoapi.db import models
from muranoapi.db.services import sessions from muranoapi.db.services import sessions
from muranoapi.db import session as db_session from muranoapi.db import session as db_session
from muranoapi.openstack.common.gettextutils import _ # noqa 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): def verify_env(func):
@ -31,13 +31,13 @@ def verify_env(func):
unit = db_session.get_session() unit = db_session.get_session()
environment = unit.query(models.Environment).get(environment_id) environment = unit.query(models.Environment).get(environment_id)
if environment is None: if environment is None:
log.info(_("Environment with id '{0}'" LOG.info(_("Environment with id '{0}'"
" not found".format(environment_id))) " not found".format(environment_id)))
raise exc.HTTPNotFound() raise exc.HTTPNotFound()
if hasattr(request, 'context'): if hasattr(request, 'context'):
if environment.tenant_id != request.context.tenant: 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')) ' this tenant resources'))
raise exc.HTTPUnauthorized() raise exc.HTTPUnauthorized()
@ -49,7 +49,7 @@ def verify_session(func):
@functools.wraps(func) @functools.wraps(func)
def __inner(self, request, *args, **kwargs): def __inner(self, request, *args, **kwargs):
if hasattr(request, 'context') and not request.context.session: 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() raise exc.HTTPForbidden()
session_id = request.context.session session_id = request.context.session
@ -58,17 +58,17 @@ def verify_session(func):
session = unit.query(models.Session).get(session_id) session = unit.query(models.Session).get(session_id)
if session is None: if session is None:
log.info(_('Session <SessionId {0}> ' LOG.info(_('Session <SessionId {0}> '
'is not found'.format(session_id))) 'is not found'.format(session_id)))
raise exc.HTTPForbidden() raise exc.HTTPForbidden()
if not sessions.SessionServices.validate(session): if not sessions.SessionServices.validate(session):
log.info(_('Session <SessionId {0}> ' LOG.info(_('Session <SessionId {0}> '
'is invalid'.format(session_id))) 'is invalid'.format(session_id)))
raise exc.HTTPForbidden() raise exc.HTTPForbidden()
if session.state == sessions.SessionState.deploying: if session.state == sessions.SessionState.deploying:
log.info(_('Session <SessionId {0}> is already in ' LOG.info(_('Session <SessionId {0}> is already in '
'deployment state'.format(session_id))) 'deployment state'.format(session_id)))
raise exc.HTTPForbidden() raise exc.HTTPForbidden()
return func(self, request, *args, **kwargs) return func(self, request, *args, **kwargs)