From 3cfe054d42cbdc5fa731626b27ecaf9ac0baa31e Mon Sep 17 00:00:00 2001 From: Volker Theile Date: Thu, 10 Dec 2020 15:30:16 +0100 Subject: [PATCH] mgr/dashboard: The /rgw/status endpoint does not check for running service Fixes: https://tracker.ceph.com/issues/48542 Signed-off-by: Volker Theile --- src/pybind/mgr/dashboard/controllers/rgw.py | 2 ++ src/pybind/mgr/dashboard/tests/test_rgw.py | 16 +++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/pybind/mgr/dashboard/controllers/rgw.py b/src/pybind/mgr/dashboard/controllers/rgw.py index 984c8622d9bd1..a6bab3dba3785 100644 --- a/src/pybind/mgr/dashboard/controllers/rgw.py +++ b/src/pybind/mgr/dashboard/controllers/rgw.py @@ -49,6 +49,8 @@ class Rgw(BaseController): def status(self): status = {'available': False, 'message': None} try: + if not CephService.get_service_list('rgw'): + raise LookupError('No RGW service is running.') instance = RgwClient.admin_instance() # Check if the service is online. if not instance.is_service_online(): # pragma: no cover - no complexity there diff --git a/src/pybind/mgr/dashboard/tests/test_rgw.py b/src/pybind/mgr/dashboard/tests/test_rgw.py index 05a7bbbc5db8a..1a99db59287cd 100644 --- a/src/pybind/mgr/dashboard/tests/test_rgw.py +++ b/src/pybind/mgr/dashboard/tests/test_rgw.py @@ -3,10 +3,24 @@ except ImportError: import unittest.mock as mock -from ..controllers.rgw import RgwUser +from .. import mgr +from ..controllers.rgw import Rgw, RgwUser from . import ControllerTestCase # pylint: disable=no-name-in-module +class RgwControllerTestCase(ControllerTestCase): + @classmethod + def setup_server(cls): + Rgw._cp_config['tools.authenticate.on'] = False # pylint: disable=protected-access + cls.setup_controllers([Rgw], '/test') + + def test_status_no_service(self): + mgr.list_servers.return_value = [] + self._get('/test/api/rgw/status') + self.assertStatus(200) + self.assertJsonBody({'available': False, 'message': 'No RGW service is running.'}) + + class RgwUserControllerTestCase(ControllerTestCase): @classmethod def setup_server(cls):