From e6f130d47023c24f8a9c742f145abd34d7320cd8 Mon Sep 17 00:00:00 2001 From: Volker Theile Date: Tue, 6 Nov 2018 14:00:24 +0100 Subject: [PATCH] mgr/dashboard: backend api tests: tasks.mgr.dashboard.test_osd.OsdTest failures - Fix bug in Dashboard QA unit test framework. Don't set the application type header manually, this is done by the requests library if required. - Enhance QA unit test helper: Print the response of the API request if it fails. This should help to identify the problem more easily. - Fix bug in the OSD controller. A parameter needs to be converted to integer. - Take care that the params of the request object are not modified. The issue was introduced by PR https://github.com/ceph/ceph/pull/24475. The CherryPy json_in plugin disclosed the errorneous unit test helper implementation. Fixes: https://tracker.ceph.com/issues/36708 Signed-off-by: Volker Theile --- qa/tasks/mgr/dashboard/helper.py | 9 +++++---- src/pybind/mgr/dashboard/controllers/osd.py | 4 ++-- src/pybind/mgr/dashboard/tools.py | 3 +-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/qa/tasks/mgr/dashboard/helper.py b/qa/tasks/mgr/dashboard/helper.py index 08e8783b40ce..73031c450f7c 100644 --- a/qa/tasks/mgr/dashboard/helper.py +++ b/qa/tasks/mgr/dashboard/helper.py @@ -162,10 +162,8 @@ class DashboardTestCase(MgrTestCase): @classmethod def _request(cls, url, method, data=None, params=None): url = "{}{}".format(cls._base_uri, url) - log.info("request %s to %s", method, url) - headers = { - 'Content-Type': 'application/json' - } + log.info("Request %s to %s", method, url) + headers = {} if cls._token: headers['Authorization'] = "Bearer {}".format(cls._token) @@ -184,6 +182,9 @@ class DashboardTestCase(MgrTestCase): else: assert False try: + if not cls._resp.ok: + # Output response for easier debugging. + log.error("Request response: %s", cls._resp.text) content_type = cls._resp.headers['content-type'] if content_type == 'application/json' and cls._resp.text and cls._resp.text != "": return cls._resp.json() diff --git a/src/pybind/mgr/dashboard/controllers/osd.py b/src/pybind/mgr/dashboard/controllers/osd.py index 9dd63b261ca5..685f2e60042e 100644 --- a/src/pybind/mgr/dashboard/controllers/osd.py +++ b/src/pybind/mgr/dashboard/controllers/osd.py @@ -133,10 +133,10 @@ class Osd(RESTController): :return: """ result = CephService.send_command( - 'mon', 'osd create', id=svc_id, uuid=uuid) + 'mon', 'osd create', id=int(svc_id), uuid=uuid) return { 'result': result, - 'svc_id': svc_id, + 'svc_id': int(svc_id), 'uuid': uuid, } diff --git a/src/pybind/mgr/dashboard/tools.py b/src/pybind/mgr/dashboard/tools.py index ee8de3b96584..1aa5b93167fd 100644 --- a/src/pybind/mgr/dashboard/tools.py +++ b/src/pybind/mgr/dashboard/tools.py @@ -47,8 +47,7 @@ class RequestLoggingTool(cherrypy.Tool): msg = '[DASHBOARD] from=\'{}\' path=\'{}\' method=\'{}\' ' \ 'user=\'{}\''.format(url, req.path_info, req.method, user) if Settings.AUDIT_API_LOG_PAYLOAD: - params = req.params if req.params else {} - params.update(get_request_body_params(req)) + params = dict(req.params or {}, **get_request_body_params(req)) # Hide sensitive data like passwords, secret keys, ... # Extend the list of patterns to search for if necessary. # Currently parameters like this are processed: -- 2.47.3