From 7304516a0555e4e5ad7f467fd274b95e23026710 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Thu, 13 Feb 2020 08:17:58 -0600 Subject: [PATCH] mgr/orch: break out apply_$type() in orchestrator.py interface Also clean up the method descriptions. Signed-off-by: Sage Weil --- src/pybind/mgr/cephadm/module.py | 23 ++------- src/pybind/mgr/cephadm/tests/test_cephadm.py | 8 +-- src/pybind/mgr/orchestrator.py | 51 ++++++++++++++------ src/pybind/mgr/orchestrator_cli/module.py | 12 ++--- src/pybind/mgr/rook/module.py | 16 ++---- 5 files changed, 54 insertions(+), 56 deletions(-) diff --git a/src/pybind/mgr/cephadm/module.py b/src/pybind/mgr/cephadm/module.py index 53cb3596eec..cea6c6b3b4c 100644 --- a/src/pybind/mgr/cephadm/module.py +++ b/src/pybind/mgr/cephadm/module.py @@ -1490,19 +1490,6 @@ class CephadmOrchestrator(MgrModule, orchestrator.OrchestratorClientMixin): return self._remove_daemon(args) return self._get_daemons(daemon_type=service_type).then(_filter) - def service_apply(self, spec): - if spec.service_type == 'mgr': - return self.update_mgrs(spec) - if spec.service_type == 'mon': - return self.update_mons(spec) - if spec.service_type == 'mds': - return self.update_mds(spec) - if spec.service_type == 'rgw': - return self.update_rgw(spec) - if spec.service_type == 'rbd-mirror': - return self.update_rbd_mirror(spec) - raise NotImplementedError() - def get_inventory(self, node_filter=None, refresh=False): """ Return the storage inventory of nodes matching the given filter. @@ -1899,7 +1886,7 @@ class CephadmOrchestrator(MgrModule, orchestrator.OrchestratorClientMixin): return self._get_daemons('mon').then(add_mons) - def update_mons(self, spec): + def apply_mon(self, spec): # type: (orchestrator.ServiceSpec) -> orchestrator.Completion """ Adjust the number of cluster managers. @@ -1975,7 +1962,7 @@ class CephadmOrchestrator(MgrModule, orchestrator.OrchestratorClientMixin): return self._add_new_daemon('mgr', daemons, spec, self._create_mgr) @with_daemons('mgr') - def update_mgrs(self, spec, daemons): + def apply_mgr(self, spec, daemons): # type: (orchestrator.ServiceSpec, List[orchestrator.DaemonDescription]) -> orchestrator.Completion """ Adjust the number of cluster managers. @@ -2071,7 +2058,7 @@ class CephadmOrchestrator(MgrModule, orchestrator.OrchestratorClientMixin): return self._get_daemons('mds').then(_add_mds) - def update_mds(self, spec): + def apply_mds(self, spec): # type: (orchestrator.ServiceSpec) -> AsyncCompletion spec = NodeAssignment(spec=spec, get_hosts_func=self._get_hosts, service_type='mds').load() @@ -2122,7 +2109,7 @@ class CephadmOrchestrator(MgrModule, orchestrator.OrchestratorClientMixin): }) return self._create_daemon('rgw', rgw_id, host, keyring=keyring) - def update_rgw(self, spec): + def apply_rgw(self, spec): spec = NodeAssignment(spec=spec, get_hosts_func=self._get_hosts, service_type='rgw').load() return self._update_service('rgw', self.add_rgw, spec) @@ -2147,7 +2134,7 @@ class CephadmOrchestrator(MgrModule, orchestrator.OrchestratorClientMixin): return self._create_daemon('rbd-mirror', daemon_id, host, keyring=keyring) - def update_rbd_mirror(self, spec): + def apply_rbd_mirror(self, spec): spec = NodeAssignment(spec=spec, get_hosts_func=self._get_hosts, service_type='rbd-mirror').load() return self._update_service('rbd-mirror', self.add_rbd_mirror, spec) diff --git a/src/pybind/mgr/cephadm/tests/test_cephadm.py b/src/pybind/mgr/cephadm/tests/test_cephadm.py index e201c5b29b9..929edf3c599 100644 --- a/src/pybind/mgr/cephadm/tests/test_cephadm.py +++ b/src/pybind/mgr/cephadm/tests/test_cephadm.py @@ -110,7 +110,7 @@ class TestCephadm(object): def test_mon_update(self, _send_command, _get_connection, cephadm_module): with self._with_host(cephadm_module, 'test'): ps = PlacementSpec(hosts=['test:0.0.0.0=a'], count=1) - c = cephadm_module.update_mons(ServiceSpec(placement=ps)) + c = cephadm_module.apply_mon(ServiceSpec(placement=ps)) assert wait(cephadm_module, c) == ["Deployed mon.a on host 'test'"] @mock.patch("cephadm.module.CephadmOrchestrator._run_cephadm", _run_cephadm('[]')) @@ -120,7 +120,7 @@ class TestCephadm(object): def test_mgr_update(self, _send_command, _get_connection, cephadm_module): with self._with_host(cephadm_module, 'test'): ps = PlacementSpec(hosts=['test:0.0.0.0=a'], count=1) - c = cephadm_module.update_mgrs(ServiceSpec(placement=ps)) + c = cephadm_module.apply_mgr(ServiceSpec(placement=ps)) [out] = wait(cephadm_module, c) match_glob(out, "Deployed mgr.* on host 'test'") @@ -193,7 +193,7 @@ class TestCephadm(object): match_glob(out, "Deployed rgw.realm.zone1.host1.* on host 'host1'") ps = PlacementSpec(hosts=['host1', 'host2'], count=2) - c = cephadm_module.update_rgw(RGWSpec('realm', 'zone1', placement=ps)) + c = cephadm_module.apply_rgw(RGWSpec('realm', 'zone1', placement=ps)) [out] = wait(cephadm_module, c) match_glob(out, "Deployed rgw.realm.zone1.host2.* on host 'host2'") @@ -217,7 +217,7 @@ class TestCephadm(object): with pytest.raises(OrchestratorError): ps = PlacementSpec(hosts=['host1', 'host2'], count=2) - c = cephadm_module.update_rgw(RGWSpec('realm', 'zone1', placement=ps)) + c = cephadm_module.apply_rgw(RGWSpec('realm', 'zone1', placement=ps)) [out] = wait(cephadm_module, c) diff --git a/src/pybind/mgr/orchestrator.py b/src/pybind/mgr/orchestrator.py index 08868c7f8ce..6a6ae995961 100644 --- a/src/pybind/mgr/orchestrator.py +++ b/src/pybind/mgr/orchestrator.py @@ -922,15 +922,6 @@ class Orchestrator(object): #assert action in ["start", "stop", "reload, "restart", "redeploy"] raise NotImplementedError() - def service_apply(self, spec): - # type: (ServiceSpec) -> Completion - """ - Create or update a service. - - :pram spec: a ServiceSpec (or derivative type) - """ - raise NotImplementedError() - def create_osds(self, drive_groups): # type: (List[DriveGroupSpec]) -> Completion """ @@ -962,32 +953,62 @@ class Orchestrator(object): def add_mon(self, spec): # type: (ServiceSpec) -> Completion - """Create a new mon daemon""" + """Create mon daemon(s)""" + raise NotImplementedError() + + def apply_mon(self, spec): + # type: (ServiceSpec) -> Completion + """Update mon cluster""" raise NotImplementedError() def add_mgr(self, spec): # type: (ServiceSpec) -> Completion - """Create a new mgr daemon""" + """Create mgr daemon(s)""" + raise NotImplementedError() + + def apply_mgr(self, spec): + # type: (ServiceSpec) -> Completion + """Update mgr cluster""" raise NotImplementedError() def add_mds(self, spec): # type: (ServiceSpec) -> Completion - """Create a new MDS cluster""" + """Create MDS daemon(s)""" + raise NotImplementedError() + + def apply_mds(self, spec): + # type: (ServiceSpec) -> Completion + """Update MDS cluster""" raise NotImplementedError() def add_rbd_mirror(self, spec): # type: (ServiceSpec) -> Completion - """Create rbd-mirror cluster""" + """Create rbd-mirror daemon(s)""" + raise NotImplementedError() + + def apply_rbd_mirror(self, spec): + # type: (ServiceSpec) -> Completion + """Update rbd-mirror cluster""" raise NotImplementedError() def add_nfs(self, spec): # type: (NFSServiceSpec) -> Completion - """Create a new MDS cluster""" + """Create NFS daemon(s)""" + raise NotImplementedError() + + def apply_nfs(self, spec): + # type: (NFSServiceSpec) -> Completion + """Update NFS cluster""" raise NotImplementedError() def add_rgw(self, spec): # type: (RGWSpec) -> Completion - """Create a new MDS zone""" + """Create RGW daemon(s)""" + raise NotImplementedError() + + def apply_rgw(self, spec): + # type: (RGWSpec) -> Completion + """Update RGW cluster""" raise NotImplementedError() def upgrade_check(self, image, version): diff --git a/src/pybind/mgr/orchestrator_cli/module.py b/src/pybind/mgr/orchestrator_cli/module.py index 66031bf9cf1..09762d21b66 100644 --- a/src/pybind/mgr/orchestrator_cli/module.py +++ b/src/pybind/mgr/orchestrator_cli/module.py @@ -574,7 +574,7 @@ Usage: spec = orchestrator.ServiceSpec(placement=placement) - completion = self.service_apply(spec) + completion = self.apply_mgr(spec) self._orchestrator_wait([completion]) orchestrator.raise_if_exception(completion) return HandleCommandResult(stdout=completion.result_str()) @@ -594,7 +594,7 @@ Usage: spec = orchestrator.ServiceSpec(placement=placement) - completion = self.service_apply(spec) + completion = self.apply_mon(spec) self._orchestrator_wait([completion]) orchestrator.raise_if_exception(completion) return HandleCommandResult(stdout=completion.result_str()) @@ -614,7 +614,7 @@ Usage: fs_name, placement=placement) - completion = self.service_apply(spec) + completion = self.apply_mds(spec) self._orchestrator_wait([completion]) orchestrator.raise_if_exception(completion) return HandleCommandResult(stdout=completion.result_str()) @@ -628,7 +628,7 @@ Usage: def _apply_rbd_mirror(self, num, label=None, hosts=[]): spec = orchestrator.ServiceSpec( placement=orchestrator.PlacementSpec(hosts=hosts, count=num, label=label)) - completion = self.service_apply(spec) + completion = self.apply_rbd_mirror(spec) self._orchestrator_wait([completion]) orchestrator.raise_if_exception(completion) return HandleCommandResult(stdout=completion.result_str()) @@ -646,7 +646,7 @@ Usage: rgw_realm=realm_name, rgw_zone=zone_name, placement=orchestrator.PlacementSpec(hosts=hosts, label=label, count=num)) - completion = self.service_apply(spec) + completion = self.apply_rgw(spec) self._orchestrator_wait([completion]) orchestrator.raise_if_exception(completion) return HandleCommandResult(stdout=completion.result_str()) @@ -664,7 +664,7 @@ Usage: svc_id, placement=orchestrator.PlacementSpec(label=label, hosts=hosts, count=num), ) - completion = self.service_apply(spec) + completion = self.apply_nfs(spec) self._orchestrator_wait([completion]) return HandleCommandResult(stdout=completion.result_str()) diff --git a/src/pybind/mgr/rook/module.py b/src/pybind/mgr/rook/module.py index 37ff39b1874..f5f4a2fa63e 100644 --- a/src/pybind/mgr/rook/module.py +++ b/src/pybind/mgr/rook/module.py @@ -340,17 +340,7 @@ class RookOrchestrator(MgrModule, orchestrator.Orchestrator): 'NFS', service_name, lambda: self.rook_cluster.rm_service('cephnfses', service_name) ) - def service_apply(self, spec): - if spec.service_type == 'mon': - return self.update_mons(spec) - if spec.service_type == 'mgr': - raise NotImplementedError() - if spec.service_type == 'mds': - return self.update_mds(spec) - if spec.service_type == 'nfs': - return self.update_nfs(spec) - - def update_mons(self, spec): + def apply_mon(self, spec): # type: (orchestrator.ServiceSpec) -> RookCompletion if spec.placement.hosts or spec.placement.label: raise RuntimeError("Host list or label is not supported by rook.") @@ -361,7 +351,7 @@ class RookOrchestrator(MgrModule, orchestrator.Orchestrator): mgr=self ) - def update_mds(self, spec): + def apply_mds(self, spec): # type: (orchestrator.ServiceSpec) -> RookCompletion num = spec.count return write_completion( @@ -370,7 +360,7 @@ class RookOrchestrator(MgrModule, orchestrator.Orchestrator): mgr=self ) - def update_nfs(self, spec): + def apply_nfs(self, spec): # type: (orchestrator.NFSServiceSpec) -> RookCompletion num = spec.count return write_completion( -- 2.39.5