From fa6cd8ae657c3c24c1e6d31e63c33bde4ce527ff Mon Sep 17 00:00:00 2001 From: Tim Serong Date: Fri, 21 Dec 2018 17:06:57 +1100 Subject: [PATCH] mgr/orchestrator_cli: Add service and service-instance start/stop/reload Signed-off-by: Tim Serong --- qa/tasks/mgr/test_orchestrator_cli.py | 10 ++++++ src/pybind/mgr/orchestrator_cli/module.py | 42 ++++++++++++++++++++++ src/pybind/mgr/test_orchestrator/module.py | 6 ++++ 3 files changed, 58 insertions(+) diff --git a/qa/tasks/mgr/test_orchestrator_cli.py b/qa/tasks/mgr/test_orchestrator_cli.py index b6a4cc61e541b..c8964f25fac9a 100644 --- a/qa/tasks/mgr/test_orchestrator_cli.py +++ b/qa/tasks/mgr/test_orchestrator_cli.py @@ -31,3 +31,13 @@ class TestOrchestratorCli(MgrTestCase): def test_service_ls(self): ret = self._orch_cmd("service", "ls") self.assertIn("ceph-mgr", ret) + + def test_service_action(self): + self._orch_cmd("service", "reload", "mds", "cephfs") + self._orch_cmd("service", "stop", "mds", "cephfs") + self._orch_cmd("service", "start", "mds", "cephfs") + + def test_service_instance_action(self): + self._orch_cmd("service-instance", "reload", "mds", "a") + self._orch_cmd("service-instance", "stop", "mds", "a") + self._orch_cmd("service-instance", "start", "mds", "a") diff --git a/src/pybind/mgr/orchestrator_cli/module.py b/src/pybind/mgr/orchestrator_cli/module.py index 3caff801191a2..51b06a6c83766 100644 --- a/src/pybind/mgr/orchestrator_cli/module.py +++ b/src/pybind/mgr/orchestrator_cli/module.py @@ -89,6 +89,24 @@ class OrchestratorCli(orchestrator.OrchestratorClientMixin, MgrModule): "desc": "Remove an NFS service", "perm": "rw" }, + { + 'cmd': "orchestrator service " + "name=action,type=CephChoices," + "strings=start|stop|reload " + "name=svc_type,type=CephString " + "name=svc_name,type=CephString", + "desc": "Start, stop or reload an entire service (i.e. all daemons)", + "perm": "rw" + }, + { + 'cmd': "orchestrator service-instance " + "name=action,type=CephChoices," + "strings=start|stop|reload " + "name=svc_type,type=CephString " + "name=svc_id,type=CephString", + "desc": "Start, stop or reload a specific service instance", + "perm": "rw" + }, { 'cmd': "orchestrator set backend " "name=module,type=CephString,req=true", @@ -255,6 +273,26 @@ class OrchestratorCli(orchestrator.OrchestratorClientMixin, MgrModule): def _nfs_rm(self, cmd): return self._rm_stateless_svc("nfs", cmd['svc_id']) + def _service_action(self, cmd): + action = cmd['action'] + svc_type = cmd['svc_type'] + svc_name = cmd['svc_name'] + + completion = self.service_action(action, svc_type, service_name=svc_name) + self._orchestrator_wait([completion]) + + return HandleCommandResult() + + def _service_instance_action(self, cmd): + action = cmd['action'] + svc_type = cmd['svc_type'] + svc_id = cmd['svc_id'] + + completion = self.service_action(action, svc_type, service_id=svc_id) + self._orchestrator_wait([completion]) + + return HandleCommandResult() + def _set_backend(self, cmd): """ We implement a setter command instead of just having the user @@ -352,6 +390,10 @@ class OrchestratorCli(orchestrator.OrchestratorClientMixin, MgrModule): return self._nfs_add(cmd) elif cmd['prefix'] == "orchestrator nfs rm": return self._nfs_rm(cmd) + elif cmd['prefix'] == "orchestrator service": + return self._service_action(cmd) + elif cmd['prefix'] == "orchestrator service-instance": + return self._service_instance_action(cmd) elif cmd['prefix'] == "orchestrator set backend": return self._set_backend(cmd) elif cmd['prefix'] == "orchestrator status": diff --git a/src/pybind/mgr/test_orchestrator/module.py b/src/pybind/mgr/test_orchestrator/module.py index 41162b6db9000..88b3391acd107 100644 --- a/src/pybind/mgr/test_orchestrator/module.py +++ b/src/pybind/mgr/test_orchestrator/module.py @@ -249,3 +249,9 @@ class TestOrchestrator(MgrModule, orchestrator.Orchestrator): def create_osds(self, spec): raise NotImplementedError(str(spec)) + def service_action(self, action, service_type, service_name=None, service_id=None): + return TestWriteCompletion( + lambda: True, None, + "Pretending to {} service {} (name={}, id={})".format( + action, service_type, service_name, service_id)) + -- 2.39.5