Merge "Update response codes to expected ones"

This commit is contained in:
Jenkins 2015-09-09 17:21:43 +00:00 committed by Gerrit Code Review
commit 490c63f8c9
6 changed files with 60 additions and 21 deletions

View File

@ -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 |
+----------------+-----------------------------------------------------------+
| 404 | Not found. Specified session doesn`t exist |
+----------------+-----------------------------------------------------------+
Get session details
-------------------
@ -451,6 +453,8 @@ Get session details
+----------------+-----------------------------------------------------------+
| 403 | Session is invalid |
+----------------+-----------------------------------------------------------+
| 404 | Not found. Specified session doesn`t exist |
+----------------+-----------------------------------------------------------+
Delete session
--------------
@ -475,6 +479,8 @@ Delete session
+----------------+-----------------------------------------------------------+
| 403 | Session is in deploying state and could not be deleted |
+----------------+-----------------------------------------------------------+
| 404 | Not found. Specified session doesn`t exist |
+----------------+-----------------------------------------------------------+
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
-----------------------------------

View File

@ -19,6 +19,7 @@ from webob import exc
from murano.api.v1 import request_statistics
from murano.common.helpers import token_sanitizer
from murano.common.i18n import _
from murano.common import wsgi
from murano.db.services import core_services
from murano import utils
@ -66,7 +67,12 @@ class Controller(object):
@utils.verify_session
@utils.verify_env
@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)
LOG.debug('Services:Post <EnvId: {0}, Path: {2}, '
'Body: {1}>'.format(environment_id, secure_data, path))
@ -83,7 +89,12 @@ class Controller(object):
@utils.verify_session
@utils.verify_env
@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}, '
'Body: {1}>'.format(environment_id, body, path))
@ -101,7 +112,7 @@ class Controller(object):
@utils.verify_env
@normalize_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))
delete_data = core_services.CoreServices.delete_data

View File

@ -69,7 +69,9 @@ class Controller(object):
raise exc.HTTPUnauthorized(explanation=msg)
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)
raise exc.HTTPForbidden(explanation=msg)
@ -112,7 +114,9 @@ class Controller(object):
check_session(request, environment_id, session, session_id)
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)
raise exc.HTTPForbidden(explanation=msg)

View File

@ -120,7 +120,7 @@ class TestServices(base.TestCase):
self.client.create_session(env['id'])
self.assertRaises(exceptions.Forbidden,
self.assertRaises(exceptions.BadRequest,
self.create_demo_service,
env['id'],
"")
@ -149,7 +149,7 @@ class TestServices(base.TestCase):
service = self.create_demo_service(env['id'], sess['id'])[1]
self.assertRaises(exceptions.Forbidden,
self.assertRaises(exceptions.BadRequest,
self.client.delete_service,
env['id'],
"",

View File

@ -57,7 +57,7 @@ class TestSessions(base.TestCase):
sess = self.client.create_session(env['id'])[1]
self.assertRaises(exceptions.NotFound,
self.assertRaises(exceptions.BadRequest,
self.client.delete_session,
None,
sess['id'])
@ -81,7 +81,7 @@ class TestSessions(base.TestCase):
sess = self.client.create_session(env['id'])[1]
self.assertRaises(exceptions.NotFound,
self.assertRaises(exceptions.BadRequest,
self.client.get_session,
None,
sess['id'])

View File

@ -57,7 +57,7 @@ def check_session(request, environment_id, session, session_id):
session_id=session_id,
environment_id=environment_id)
LOG.error(msg)
raise exc.HTTPNotFound(explanation=msg)
raise exc.HTTPBadRequest(explanation=msg)
check_env(request, environment_id)
@ -94,8 +94,10 @@ def verify_session(func):
@functools.wraps(func)
def __inner(self, request, *args, **kwargs):
if hasattr(request, 'context') and not request.context.session:
LOG.info(_LI('Session is required for this call'))
raise exc.HTTPForbidden()
msg = _('X-Configuration-Session header which indicates'
' to the session is missed')
LOG.error(msg)
raise exc.HTTPBadRequest(explanation=msg)
session_id = request.context.session
@ -103,18 +105,20 @@ def verify_session(func):
session = unit.query(models.Session).get(session_id)
if session is None:
LOG.info(_LI('Session <SessionId {0}> '
'is not found').format(session_id))
raise exc.HTTPForbidden()
msg = _('Session <SessionId {0}> is not found').format(session_id)
LOG.error(msg)
raise exc.HTTPNotFound(explanation=msg)
if not sessions.SessionServices.validate(session):
LOG.info(_LI('Session <SessionId {0}> '
'is invalid').format(session_id))
raise exc.HTTPForbidden()
msg = _('Session <SessionId {0}> '
'is invalid: environment has been updated or '
'updating right now with other session').format(session_id)
LOG.error(msg)
raise exc.HTTPForbidden(explanation=msg)
if session.state == states.SessionState.DEPLOYING:
LOG.info(_LI('Session <SessionId {0}> is already in '
'deployment state').format(session_id))
raise exc.HTTPForbidden()
msg = _('Session <SessionId {0}> is already in deployment state'
).format(session_id)
raise exc.HTTPForbidden(explanation=msg)
return func(self, request, *args, **kwargs)
return __inner