From: Jason Dillaman Date: Thu, 17 Oct 2019 18:01:11 +0000 (-0400) Subject: mgr/dashboard: new controller for RBD mirroring site name X-Git-Tag: v15.1.0~633^2~5 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=849b64d11aaba7a6fcc78dcaed481289aacfc9a7;p=ceph.git mgr/dashboard: new controller for RBD mirroring site name This allows setting and retrieving the current site name for RBD mirroring. This is a global property of the cluster. Signed-off-by: Jason Dillaman --- diff --git a/qa/tasks/mgr/dashboard/test_rbd_mirroring.py b/qa/tasks/mgr/dashboard/test_rbd_mirroring.py index df719a72601c..bb6e3d0be807 100644 --- a/qa/tasks/mgr/dashboard/test_rbd_mirroring.py +++ b/qa/tasks/mgr/dashboard/test_rbd_mirroring.py @@ -178,3 +178,12 @@ class RbdMirroringTest(DashboardTestCase): self.update_pool('rbd', 'disabled') self.assertStatus(200) + + def test_site_name(self): + expected_site_name = {'site_name': 'site-a'} + self._task_put('/api/block/mirroring/site_name', expected_site_name) + self.assertStatus(200) + + site_name = self._get('/api/block/mirroring/site_name') + self.assertStatus(200) + self.assertEqual(expected_site_name, site_name) diff --git a/src/pybind/mgr/dashboard/controllers/rbd_mirroring.py b/src/pybind/mgr/dashboard/controllers/rbd_mirroring.py index e8f2d84cb331..8d94b7090958 100644 --- a/src/pybind/mgr/dashboard/controllers/rbd_mirroring.py +++ b/src/pybind/mgr/dashboard/controllers/rbd_mirroring.py @@ -12,7 +12,7 @@ import cherrypy import rbd from . import ApiController, Endpoint, Task, BaseController, ReadPermission, \ - RESTController + UpdatePermission, RESTController from .rbd import _rbd_call from .. import mgr @@ -329,6 +329,26 @@ def _reset_view_cache(): _get_content_data.reset() +@ApiController('/block/mirroring', Scope.RBD_MIRRORING) +class RbdMirroring(BaseController): + + @Endpoint(method='GET', path='site_name') + @handle_rbd_mirror_error() + @ReadPermission + def get(self): + return self._get_site_name() + + @Endpoint(method='PUT', path='site_name') + @handle_rbd_mirror_error() + @UpdatePermission + def set(self, site_name): + rbd.RBD().mirror_site_name_set(mgr.rados, site_name) + return self._get_site_name() + + def _get_site_name(self): + return {'site_name': rbd.RBD().mirror_site_name_get(mgr.rados)} + + @ApiController('/block/mirroring/summary', Scope.RBD_MIRRORING) class RbdMirroringSummary(BaseController): diff --git a/src/pybind/mgr/dashboard/tests/test_rbd_mirroring.py b/src/pybind/mgr/dashboard/tests/test_rbd_mirroring.py index 605cc4cd5a51..39f70594308b 100644 --- a/src/pybind/mgr/dashboard/tests/test_rbd_mirroring.py +++ b/src/pybind/mgr/dashboard/tests/test_rbd_mirroring.py @@ -9,7 +9,7 @@ except ImportError: from . import ControllerTestCase from .. import mgr from ..controllers.summary import Summary -from ..controllers.rbd_mirroring import RbdMirroringSummary +from ..controllers.rbd_mirroring import RbdMirroring, RbdMirroringSummary from ..services import progress @@ -47,6 +47,37 @@ mock_osd_map = { } +class RbdMirroringControllerTest(ControllerTestCase): + + @classmethod + def setup_server(cls): + # pylint: disable=protected-access + RbdMirroring._cp_config['tools.authenticate.on'] = False + # pylint: enable=protected-access + + cls.setup_controllers([RbdMirroring]) + + @mock.patch('dashboard.controllers.rbd_mirroring.rbd.RBD') + def test_site_name(self, mock_rbd): + result = {'site_name': 'fsid'} + mock_rbd_instance = mock_rbd.return_value + mock_rbd_instance.mirror_site_name_get.return_value = \ + result['site_name'] + + self._get('/api/block/mirroring/site_name') + self.assertStatus(200) + self.assertJsonBody(result) + + result['site_name'] = 'site-a' + mock_rbd_instance.mirror_site_name_get.return_value = \ + result['site_name'] + self._put('/api/block/mirroring/site_name', result) + self.assertStatus(200) + self.assertJsonBody(result) + mock_rbd_instance.mirror_site_name_set.assert_called_with( + mock.ANY, result['site_name']) + + class RbdMirroringSummaryControllerTest(ControllerTestCase): @classmethod