diff --git a/doc/source/specification/murano-api.rst b/doc/source/specification/murano-api.rst index 34381d0fe..3f298fb18 100644 --- a/doc/source/specification/murano-api.rst +++ b/doc/source/specification/murano-api.rst @@ -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 ----------------------------------- diff --git a/murano/api/v1/services.py b/murano/api/v1/services.py index 3fbf168e6..7422fb2b0 100644 --- a/murano/api/v1/services.py +++ b/murano/api/v1/services.py @@ -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 '.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 '.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 '.format(environment_id, path)) delete_data = core_services.CoreServices.delete_data diff --git a/murano/api/v1/sessions.py b/murano/api/v1/sessions.py index 4d3345fc1..2308d8085 100644 --- a/murano/api/v1/sessions.py +++ b/murano/api/v1/sessions.py @@ -69,7 +69,9 @@ class Controller(object): raise exc.HTTPUnauthorized(explanation=msg) if not sessions.SessionServices.validate(session): - msg = _('Session is invalid').format(session_id) + msg = _('Session 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 is invalid').format(session_id) + msg = _('Session is invalid: environment has been ' + 'updated or updating right now with other session' + ).format(session_id) LOG.error(msg) raise exc.HTTPForbidden(explanation=msg) diff --git a/murano/tests/functional/api/v1/test_services.py b/murano/tests/functional/api/v1/test_services.py index 08f2de516..9cbcd321e 100644 --- a/murano/tests/functional/api/v1/test_services.py +++ b/murano/tests/functional/api/v1/test_services.py @@ -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'], "", diff --git a/murano/tests/functional/api/v1/test_sessions.py b/murano/tests/functional/api/v1/test_sessions.py index 65d4ca250..d4645f14b 100644 --- a/murano/tests/functional/api/v1/test_sessions.py +++ b/murano/tests/functional/api/v1/test_sessions.py @@ -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']) diff --git a/murano/utils.py b/murano/utils.py index 4ad42cfbc..1dc4cc742 100644 --- a/murano/utils.py +++ b/murano/utils.py @@ -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 ' - 'is not found').format(session_id)) - raise exc.HTTPForbidden() + msg = _('Session is not found').format(session_id) + LOG.error(msg) + raise exc.HTTPNotFound(explanation=msg) if not sessions.SessionServices.validate(session): - LOG.info(_LI('Session ' - 'is invalid').format(session_id)) - raise exc.HTTPForbidden() + msg = _('Session ' + '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 is already in ' - 'deployment state').format(session_id)) - raise exc.HTTPForbidden() + msg = _('Session is already in deployment state' + ).format(session_id) + raise exc.HTTPForbidden(explanation=msg) return func(self, request, *args, **kwargs) return __inner