]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/dashboard: Modify RGW proxy response of errors to display a detailed message... 20869/head
authorVolker Theile <vtheile@suse.com>
Fri, 13 Apr 2018 08:12:12 +0000 (10:12 +0200)
committerVolker Theile <vtheile@suse.com>
Thu, 19 Apr 2018 09:35:13 +0000 (11:35 +0200)
Signed-off-by: Volker Theile <vtheile@suse.com>
qa/tasks/mgr/dashboard/test_rgw.py
src/pybind/mgr/dashboard/controllers/rgw.py

index 4e780fabfb37b8a97d7a0051c2c27c287f5f9a16..81eced2f6d0823c988d068fa7d661c46a5b1400d 100644 (file)
@@ -43,8 +43,8 @@ class RgwProxyExceptionsTest(DashboardTestCase):
     @authenticate
     def test_no_credentials_exception(self):
         resp = self._get('/api/rgw/proxy/status')
-        self.assertStatus(401)
-        self.assertIn('message', resp)
+        self.assertStatus(500)
+        self.assertIn('detail', resp)
 
 
 class RgwProxyTest(DashboardTestCase):
@@ -115,12 +115,13 @@ class RgwProxyTest(DashboardTestCase):
         self.assertStatus(200)
 
         self._delete('/api/rgw/proxy/user', params={'uid': 'teuth-test-user'})
-        self.assertStatus(404)
+        self.assertStatus(500)
         resp = self._resp.json()
-        self.assertIn('Code', resp)
-        self.assertIn('HostId', resp)
-        self.assertIn('RequestId', resp)
-        self.assertEqual(resp['Code'], 'NoSuchUser')
+        self.assertIn('detail', resp)
+        self.assertIn('failed request with status code 404', resp['detail'])
+        self.assertIn('"Code":"NoSuchUser"', resp['detail'])
+        self.assertIn('"HostId"', resp['detail'])
+        self.assertIn('"RequestId"', resp['detail'])
 
     @authenticate
     def test_rgw_proxy(self):
index d43e9e476b94688b216f263604f6be3b062ac2f9..e7cdaa3939073b7443232af01423cabb008f0002 100644 (file)
@@ -8,8 +8,6 @@ from . import ApiController, BaseController, RESTController, AuthRequired
 from .. import logger
 from ..services.ceph_service import CephService
 from ..services.rgw_client import RgwClient
-from ..rest_client import RequestException
-from ..exceptions import NoCredentialsException
 
 
 @ApiController('rgw')
@@ -73,19 +71,17 @@ class RgwProxy(BaseController):
         try:
             rgw_client = RgwClient.admin_instance()
 
-        except NoCredentialsException as e:
-            cherrypy.response.headers['Content-Type'] = 'application/json'
-            cherrypy.response.status = 401
-            return json.dumps({'message': str(e)}).encode('utf-8')
-
-        method = cherrypy.request.method
-        data = None
+            method = cherrypy.request.method
+            data = None
 
-        if cherrypy.request.body.length:
-            data = cherrypy.request.body.read()
+            if cherrypy.request.body.length:
+                data = cherrypy.request.body.read()
 
-        try:
             return rgw_client.proxy(method, path, params, data)
-        except RequestException as e:
-            cherrypy.response.status = e.status_code
-            return e.content
+        except Exception as e:  # pylint: disable=broad-except
+            # Always use status code 500 and NOT the status that may delivered
+            # by the exception. That's because we do not want to forward e.g.
+            # 401 or 404 that may trigger unwanted actions in the UI.
+            cherrypy.response.headers['Content-Type'] = 'application/json'
+            cherrypy.response.status = 500
+            return json.dumps({'detail': str(e)}).encode('utf-8')