Merge "Update response codes to expected ones"
This commit is contained in:
commit
490c63f8c9
|
@ -414,6 +414,8 @@ With this request all local changes made within the environment start to deploy
|
||||||
+----------------+-----------------------------------------------------------+
|
+----------------+-----------------------------------------------------------+
|
||||||
| 403 | Session is already deployed or deployment is in progress |
|
| 403 | Session is already deployed or deployment is in progress |
|
||||||
+----------------+-----------------------------------------------------------+
|
+----------------+-----------------------------------------------------------+
|
||||||
|
| 404 | Not found. Specified session doesn`t exist |
|
||||||
|
+----------------+-----------------------------------------------------------+
|
||||||
|
|
||||||
Get session details
|
Get session details
|
||||||
-------------------
|
-------------------
|
||||||
|
@ -451,6 +453,8 @@ Get session details
|
||||||
+----------------+-----------------------------------------------------------+
|
+----------------+-----------------------------------------------------------+
|
||||||
| 403 | Session is invalid |
|
| 403 | Session is invalid |
|
||||||
+----------------+-----------------------------------------------------------+
|
+----------------+-----------------------------------------------------------+
|
||||||
|
| 404 | Not found. Specified session doesn`t exist |
|
||||||
|
+----------------+-----------------------------------------------------------+
|
||||||
|
|
||||||
Delete session
|
Delete session
|
||||||
--------------
|
--------------
|
||||||
|
@ -475,6 +479,8 @@ Delete session
|
||||||
+----------------+-----------------------------------------------------------+
|
+----------------+-----------------------------------------------------------+
|
||||||
| 403 | Session is in deploying state and could not be deleted |
|
| 403 | Session is in deploying state and could not be deleted |
|
||||||
+----------------+-----------------------------------------------------------+
|
+----------------+-----------------------------------------------------------+
|
||||||
|
| 404 | Not found. Specified session doesn`t exist |
|
||||||
|
+----------------+-----------------------------------------------------------+
|
||||||
|
|
||||||
Environment deployments API
|
Environment deployments API
|
||||||
===========================
|
===========================
|
||||||
|
@ -692,6 +698,20 @@ Created application returned
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
+----------------+-----------------------------------------------------------+
|
||||||
|
| Code | Description |
|
||||||
|
+================+===========================================================+
|
||||||
|
| 200 | Session is deleted successfully |
|
||||||
|
+----------------+-----------------------------------------------------------+
|
||||||
|
| 401 | User is not authorized to access this session |
|
||||||
|
+----------------+-----------------------------------------------------------+
|
||||||
|
| 403 | Session is in deploying state and could not be deleted |
|
||||||
|
+----------------+-----------------------------------------------------------+
|
||||||
|
| 404 | Not found. Specified session doesn`t exist |
|
||||||
|
+----------------+-----------------------------------------------------------+
|
||||||
|
| 400 | Required header or body are not provided |
|
||||||
|
+----------------+-----------------------------------------------------------+
|
||||||
|
|
||||||
Delete application from environment
|
Delete application from environment
|
||||||
-----------------------------------
|
-----------------------------------
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,7 @@ from webob import exc
|
||||||
|
|
||||||
from murano.api.v1 import request_statistics
|
from murano.api.v1 import request_statistics
|
||||||
from murano.common.helpers import token_sanitizer
|
from murano.common.helpers import token_sanitizer
|
||||||
|
from murano.common.i18n import _
|
||||||
from murano.common import wsgi
|
from murano.common import wsgi
|
||||||
from murano.db.services import core_services
|
from murano.db.services import core_services
|
||||||
from murano import utils
|
from murano import utils
|
||||||
|
@ -66,7 +67,12 @@ class Controller(object):
|
||||||
@utils.verify_session
|
@utils.verify_session
|
||||||
@utils.verify_env
|
@utils.verify_env
|
||||||
@normalize_path
|
@normalize_path
|
||||||
def post(self, request, environment_id, path, body):
|
def post(self, request, environment_id, path, body=None):
|
||||||
|
if not body:
|
||||||
|
msg = _('Request body is empty: please, provide'
|
||||||
|
' application object model')
|
||||||
|
LOG.error(msg)
|
||||||
|
raise exc.HTTPBadRequest(msg)
|
||||||
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))
|
||||||
|
@ -83,7 +89,12 @@ class Controller(object):
|
||||||
@utils.verify_session
|
@utils.verify_session
|
||||||
@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=None):
|
||||||
|
if not body:
|
||||||
|
msg = _('Request body is empty: please, provide'
|
||||||
|
' application object model')
|
||||||
|
LOG.error(msg)
|
||||||
|
raise exc.HTTPBadRequest(msg)
|
||||||
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))
|
||||||
|
|
||||||
|
@ -101,7 +112,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:Delete <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
|
||||||
|
|
|
@ -69,7 +69,9 @@ class Controller(object):
|
||||||
raise exc.HTTPUnauthorized(explanation=msg)
|
raise exc.HTTPUnauthorized(explanation=msg)
|
||||||
|
|
||||||
if not sessions.SessionServices.validate(session):
|
if not sessions.SessionServices.validate(session):
|
||||||
msg = _('Session <SessionId {0}> is invalid').format(session_id)
|
msg = _('Session <SessionId {0}> is invalid: environment has been'
|
||||||
|
' updated or updating right now with other session'
|
||||||
|
).format(session_id)
|
||||||
LOG.error(msg)
|
LOG.error(msg)
|
||||||
raise exc.HTTPForbidden(explanation=msg)
|
raise exc.HTTPForbidden(explanation=msg)
|
||||||
|
|
||||||
|
@ -112,7 +114,9 @@ class Controller(object):
|
||||||
check_session(request, environment_id, session, session_id)
|
check_session(request, environment_id, session, session_id)
|
||||||
|
|
||||||
if not sessions.SessionServices.validate(session):
|
if not sessions.SessionServices.validate(session):
|
||||||
msg = _('Session <SessionId {0}> is invalid').format(session_id)
|
msg = _('Session <SessionId {0}> is invalid: environment has been '
|
||||||
|
'updated or updating right now with other session'
|
||||||
|
).format(session_id)
|
||||||
LOG.error(msg)
|
LOG.error(msg)
|
||||||
raise exc.HTTPForbidden(explanation=msg)
|
raise exc.HTTPForbidden(explanation=msg)
|
||||||
|
|
||||||
|
|
|
@ -120,7 +120,7 @@ class TestServices(base.TestCase):
|
||||||
|
|
||||||
self.client.create_session(env['id'])
|
self.client.create_session(env['id'])
|
||||||
|
|
||||||
self.assertRaises(exceptions.Forbidden,
|
self.assertRaises(exceptions.BadRequest,
|
||||||
self.create_demo_service,
|
self.create_demo_service,
|
||||||
env['id'],
|
env['id'],
|
||||||
"")
|
"")
|
||||||
|
@ -149,7 +149,7 @@ class TestServices(base.TestCase):
|
||||||
|
|
||||||
service = self.create_demo_service(env['id'], sess['id'])[1]
|
service = self.create_demo_service(env['id'], sess['id'])[1]
|
||||||
|
|
||||||
self.assertRaises(exceptions.Forbidden,
|
self.assertRaises(exceptions.BadRequest,
|
||||||
self.client.delete_service,
|
self.client.delete_service,
|
||||||
env['id'],
|
env['id'],
|
||||||
"",
|
"",
|
||||||
|
|
|
@ -57,7 +57,7 @@ class TestSessions(base.TestCase):
|
||||||
|
|
||||||
sess = self.client.create_session(env['id'])[1]
|
sess = self.client.create_session(env['id'])[1]
|
||||||
|
|
||||||
self.assertRaises(exceptions.NotFound,
|
self.assertRaises(exceptions.BadRequest,
|
||||||
self.client.delete_session,
|
self.client.delete_session,
|
||||||
None,
|
None,
|
||||||
sess['id'])
|
sess['id'])
|
||||||
|
@ -81,7 +81,7 @@ class TestSessions(base.TestCase):
|
||||||
|
|
||||||
sess = self.client.create_session(env['id'])[1]
|
sess = self.client.create_session(env['id'])[1]
|
||||||
|
|
||||||
self.assertRaises(exceptions.NotFound,
|
self.assertRaises(exceptions.BadRequest,
|
||||||
self.client.get_session,
|
self.client.get_session,
|
||||||
None,
|
None,
|
||||||
sess['id'])
|
sess['id'])
|
||||||
|
|
|
@ -57,7 +57,7 @@ def check_session(request, environment_id, session, session_id):
|
||||||
session_id=session_id,
|
session_id=session_id,
|
||||||
environment_id=environment_id)
|
environment_id=environment_id)
|
||||||
LOG.error(msg)
|
LOG.error(msg)
|
||||||
raise exc.HTTPNotFound(explanation=msg)
|
raise exc.HTTPBadRequest(explanation=msg)
|
||||||
|
|
||||||
check_env(request, environment_id)
|
check_env(request, environment_id)
|
||||||
|
|
||||||
|
@ -94,8 +94,10 @@ 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(_LI('Session is required for this call'))
|
msg = _('X-Configuration-Session header which indicates'
|
||||||
raise exc.HTTPForbidden()
|
' to the session is missed')
|
||||||
|
LOG.error(msg)
|
||||||
|
raise exc.HTTPBadRequest(explanation=msg)
|
||||||
|
|
||||||
session_id = request.context.session
|
session_id = request.context.session
|
||||||
|
|
||||||
|
@ -103,18 +105,20 @@ 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(_LI('Session <SessionId {0}> '
|
msg = _('Session <SessionId {0}> is not found').format(session_id)
|
||||||
'is not found').format(session_id))
|
LOG.error(msg)
|
||||||
raise exc.HTTPForbidden()
|
raise exc.HTTPNotFound(explanation=msg)
|
||||||
|
|
||||||
if not sessions.SessionServices.validate(session):
|
if not sessions.SessionServices.validate(session):
|
||||||
LOG.info(_LI('Session <SessionId {0}> '
|
msg = _('Session <SessionId {0}> '
|
||||||
'is invalid').format(session_id))
|
'is invalid: environment has been updated or '
|
||||||
raise exc.HTTPForbidden()
|
'updating right now with other session').format(session_id)
|
||||||
|
LOG.error(msg)
|
||||||
|
raise exc.HTTPForbidden(explanation=msg)
|
||||||
|
|
||||||
if session.state == states.SessionState.DEPLOYING:
|
if session.state == states.SessionState.DEPLOYING:
|
||||||
LOG.info(_LI('Session <SessionId {0}> is already in '
|
msg = _('Session <SessionId {0}> is already in deployment state'
|
||||||
'deployment state').format(session_id))
|
).format(session_id)
|
||||||
raise exc.HTTPForbidden()
|
raise exc.HTTPForbidden(explanation=msg)
|
||||||
return func(self, request, *args, **kwargs)
|
return func(self, request, *args, **kwargs)
|
||||||
return __inner
|
return __inner
|
||||||
|
|
Loading…
Reference in New Issue