From 95ecaad0d5ffb8ddc74f58bf7ebe6ab46e5bea81 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Tue, 11 Feb 2020 09:05:55 -0600 Subject: [PATCH] mgr/orch: split out daemon_action from service_action Signed-off-by: Sage Weil --- doc/mgr/orchestrator_cli.rst | 8 +-- qa/tasks/cephadm.py | 8 +-- qa/tasks/mgr/test_orchestrator_cli.py | 6 +-- src/pybind/mgr/cephadm/module.py | 54 ++++++++++++-------- src/pybind/mgr/cephadm/tests/test_cephadm.py | 6 +-- src/pybind/mgr/orchestrator.py | 29 ++++++----- src/pybind/mgr/orchestrator_cli/module.py | 16 +++--- 7 files changed, 71 insertions(+), 56 deletions(-) diff --git a/doc/mgr/orchestrator_cli.rst b/doc/mgr/orchestrator_cli.rst index e5950b67d1b79..4f8dac2b071fc 100644 --- a/doc/mgr/orchestrator_cli.rst +++ b/doc/mgr/orchestrator_cli.rst @@ -252,7 +252,7 @@ Discover the status of a particular service:: Query the status of a particular service instance (mon, osd, mds, rgw). For OSDs the id is the numeric OSD ID, for MDS services it is the file system name:: - ceph orch service-instance status  [--refresh] + ceph orch daemon status  [--refresh] @@ -283,7 +283,7 @@ Start/stop/reload:: ceph orch service {stop,start,reload} - ceph orch service-instance {start,stop,reload} + ceph orch daemon {start,stop,reload} Current Implementation Status @@ -301,11 +301,11 @@ This is an overview of the current implementation status of the orchestrators. mon update ✔ ✔ osd create ✔ ✔ osd rm ⚪ ✔ + daemon status ⚪ ✔ + daemon {stop,start,...} ⚪ ✔ device {ident,fault}-(on,off} ⚪ ✔ device ls ✔ ✔ service ls ✔ ✔ - service-instance status ⚪ ✔ - service-instance {stop,start,...} ⚪ ✔ iscsi add ⚪ ⚪ iscsi rm ⚪ ⚪ iscsi update ⚪ ⚪ diff --git a/qa/tasks/cephadm.py b/qa/tasks/cephadm.py index acc3871a593df..7fa3026bbda67 100644 --- a/qa/tasks/cephadm.py +++ b/qa/tasks/cephadm.py @@ -499,12 +499,12 @@ def ceph_mons(ctx, config): if teuthology.is_type('mon', cluster_name)(r)]: c_, _, id_ = teuthology.split_role(mon) _shell(ctx, cluster_name, remote, [ - 'ceph', 'orch', 'service-instance', 'reconfig', - 'mon', id_, + 'ceph', 'orch', 'daemon', 'reconfig', + 'mon.' + id_, ]) _shell(ctx, cluster_name, ctx.ceph[cluster_name].bootstrap_remote, [ - 'ceph', 'orch', 'service-instance', 'reconfig', - 'mgr', ctx.ceph[cluster_name].first_mgr, + 'ceph', 'orch', 'daemon', 'reconfig', + 'mgr.' + ctx.ceph[cluster_name].first_mgr, ]) yield diff --git a/qa/tasks/mgr/test_orchestrator_cli.py b/qa/tasks/mgr/test_orchestrator_cli.py index 86c5b61bebdb7..3473896ab42a3 100644 --- a/qa/tasks/mgr/test_orchestrator_cli.py +++ b/qa/tasks/mgr/test_orchestrator_cli.py @@ -77,9 +77,9 @@ class TestOrchestratorCli(MgrTestCase): self._orch_cmd("service", "start", "mds", "cephfs") def test_service_instance_action(self): - self._orch_cmd("service-instance", "restart", "mds", "a") - self._orch_cmd("service-instance", "stop", "mds", "a") - self._orch_cmd("service-instance", "start", "mds", "a") + self._orch_cmd("daemon", "restart", "mds", "a") + self._orch_cmd("daemon", "stop", "mds", "a") + self._orch_cmd("daemon", "start", "mds", "a") def test_osd_create(self): self._orch_cmd("osd", "create", "*:device") diff --git a/src/pybind/mgr/cephadm/module.py b/src/pybind/mgr/cephadm/module.py index 442da3a5164fe..c062bb2ab09c0 100644 --- a/src/pybind/mgr/cephadm/module.py +++ b/src/pybind/mgr/cephadm/module.py @@ -579,7 +579,7 @@ class CephadmOrchestrator(MgrModule, orchestrator.OrchestratorClientMixin): 'value': target_name, 'who': daemon_type + '.' + d.service_instance, }) - return self._service_action([( + return self._daemon_action([( d.service_type, d.service_instance, d.nodename, @@ -1387,41 +1387,32 @@ class CephadmOrchestrator(MgrModule, orchestrator.OrchestratorClientMixin): refresh=refresh) return result - def service_action(self, action, service_type, - service_name=None, - service_id=None): - self.log.debug('service_action action %s type %s name %s id %s' % ( - action, service_type, service_name, service_id)) + def service_action(self, action, service_type, service_name): + self.log.debug('service_action action %s type %s name %s' % ( + action, service_type, service_name)) def _proc_daemons(daemons): - if service_name is None and service_id is None: - raise ValueError('service_name or service_id required') args = [] for d in daemons: args.append((d.service_type, d.service_instance, d.nodename, action)) if not args: - if service_name: - n = service_name + '-*' - else: - n = service_id raise orchestrator.OrchestratorError( - 'Unable to find %s.%s daemon(s)' % ( - service_type, n)) - return self._service_action(args) + 'Unable to find %s.%s.* daemon(s)' % ( + service_type, service_name)) + return self._daemon_action(args) return self._get_services( service_type, - service_name=service_name, - service_id=service_id).then(_proc_daemons) + service_name=service_name).then(_proc_daemons) @async_map_completion - def _service_action(self, service_type, service_id, host, action): + def _daemon_action(self, daemon_type, daemon_id, host, action): if action == 'redeploy': # stop, recreate the container+unit, then restart - return self._create_daemon(service_type, service_id, host) + return self._create_daemon(daemon_type, daemon_id, host) elif action == 'reconfig': - return self._create_daemon(service_type, service_id, host, + return self._create_daemon(daemon_type, daemon_id, host, reconfig=True) actions = { @@ -1429,16 +1420,35 @@ class CephadmOrchestrator(MgrModule, orchestrator.OrchestratorClientMixin): 'stop': ['stop'], 'restart': ['reset-failed', 'restart'], } - name = '%s.%s' % (service_type, service_id) + name = '%s.%s' % (daemon_type, daemon_id) for a in actions[action]: out, err, code = self._run_cephadm( host, name, 'unit', ['--name', name, a], error_ok=True) self.service_cache.invalidate(host) - self.log.debug('_service_action code %s out %s' % (code, out)) + self.log.debug('_daemon_action code %s out %s' % (code, out)) return "{} {} from host '{}'".format(action, name, host) + def daemon_action(self, action, daemon_type, daemon_id): + self.log.debug('daemon_action action %s type %s id %s' % ( + action, daemon_type, daemon_id)) + + def _proc_daemons(daemons): + args = [] + for d in daemons: + args.append((d.service_type, d.service_instance, + d.nodename, action)) + if not args: + raise orchestrator.OrchestratorError( + 'Unable to find %s.%s daemon(s)' % ( + daemon_type, daemon_id)) + return self._daemon_action(args) + + return self._get_services( + service_type=daemon_type, + service_id=daemon_id).then(_proc_daemons) + def get_inventory(self, node_filter=None, refresh=False): """ Return the storage inventory of nodes matching the given filter. diff --git a/src/pybind/mgr/cephadm/tests/test_cephadm.py b/src/pybind/mgr/cephadm/tests/test_cephadm.py index e4a02a170c27c..6e1643c888528 100644 --- a/src/pybind/mgr/cephadm/tests/test_cephadm.py +++ b/src/pybind/mgr/cephadm/tests/test_cephadm.py @@ -90,16 +90,16 @@ class TestCephadm(object): @mock.patch("cephadm.module.CephadmOrchestrator.send_command") @mock.patch("cephadm.module.CephadmOrchestrator.mon_command", mon_command) @mock.patch("cephadm.module.CephadmOrchestrator._get_connection") - def test_service_action(self, _send_command, _get_connection, cephadm_module): + def test_daemon_action(self, _send_command, _get_connection, cephadm_module): cephadm_module.service_cache_timeout = 10 with self._with_host(cephadm_module, 'test'): c = cephadm_module.describe_service(refresh=True) wait(cephadm_module, c) - c = cephadm_module.service_action('redeploy', 'rgw', service_id='myrgw.foobar') + c = cephadm_module.daemon_action('redeploy', 'rgw', 'myrgw.foobar') assert wait(cephadm_module, c) == ["Deployed rgw.myrgw.foobar on host 'test'"] for what in ('start', 'stop', 'restart'): - c = cephadm_module.service_action(what, 'rgw', service_id='myrgw.foobar') + c = cephadm_module.daemon_action(what, 'rgw', 'myrgw.foobar') assert wait(cephadm_module, c) == [what + " rgw.myrgw.foobar from host 'test'"] diff --git a/src/pybind/mgr/orchestrator.py b/src/pybind/mgr/orchestrator.py index 16d941e6d00e6..90c6d349566d5 100644 --- a/src/pybind/mgr/orchestrator.py +++ b/src/pybind/mgr/orchestrator.py @@ -868,27 +868,30 @@ class Orchestrator(object): """ raise NotImplementedError() - def service_action(self, action, service_type, service_name=None, service_id=None): - # type: (str, str, Optional[str], Optional[str]) -> Completion + def service_action(self, action, service_type, service_name): + # type: (str, str, str) -> Completion """ - Perform an action (start/stop/reload) on a service. - - Either service_name or service_id must be specified: - - * If using service_name, perform the action on that entire logical - service (i.e. all daemons providing that named service). - * If using service_id, perform the action on a single specific daemon - instance. + Perform an action (start/stop/reload) on a service (i.e., all daemons + providing the logical service). :param action: one of "start", "stop", "restart", "redeploy", "reconfig" :param service_type: e.g. "mds", "rgw", ... :param service_name: name of logical service ("cephfs", "us-east", ...) - :param service_id: service daemon instance (usually a short hostname) :rtype: Completion """ #assert action in ["start", "stop", "reload, "restart", "redeploy"] - #assert service_name or service_id - #assert not (service_name and service_id) + raise NotImplementedError() + + def daemon_action(self, action, daemon_type, daemon_id): + # type: (str, str, str) -> Completion + """ + Perform an action (start/stop/reload) on a daemon. + + :param action: one of "start", "stop", "restart", "redeploy", "reconfig" + :param name: name of daemon + :rtype: Completion + """ + #assert action in ["start", "stop", "reload, "restart", "redeploy"] raise NotImplementedError() def create_osds(self, drive_groups): diff --git a/src/pybind/mgr/orchestrator_cli/module.py b/src/pybind/mgr/orchestrator_cli/module.py index 870c0c37a4c91..4722dd3f9b7b4 100644 --- a/src/pybind/mgr/orchestrator_cli/module.py +++ b/src/pybind/mgr/orchestrator_cli/module.py @@ -602,19 +602,21 @@ Usage: "name=svc_name,type=CephString", 'Start, stop, restart, redeploy, or reconfig an entire service (i.e. all daemons)') def _service_action(self, action, svc_type, svc_name): - completion = self.service_action(action, svc_type, service_name=svc_name) + completion = self.service_action(action, svc_type, svc_name) self._orchestrator_wait([completion]) orchestrator.raise_if_exception(completion) return HandleCommandResult(stdout=completion.result_str()) @orchestrator._cli_write_command( - 'orch service-instance', + 'orch daemon', "name=action,type=CephChoices,strings=start|stop|restart|redeploy|reconfig " - "name=svc_type,type=CephString " - "name=svc_id,type=CephString", - 'Start, stop, restart, redeploy, or reconfig a specific service instance') - def _service_instance_action(self, action, svc_type, svc_id): - completion = self.service_action(action, svc_type, service_id=svc_id) + "name=name,type=CephString ", + 'Start, stop, restart, redeploy, or reconfig a specific daemon') + def _service_instance_action(self, action, name): + if '.' not in name: + raise orchestrator.OrchestratorError('%s is not a valid daemon name' % name) + (daemon_type, daemon_id) = name.split('.', 1) + completion = self.daemon_action(action, daemon_type, daemon_id) self._orchestrator_wait([completion]) orchestrator.raise_if_exception(completion) return HandleCommandResult(stdout=completion.result_str()) -- 2.39.5