]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
mgr/orchestrator: unify StatelessServiceSpec and StatefulServiceSpec
authorSebastian Wagner <sebastian.wagner@suse.com>
Mon, 10 Feb 2020 10:58:06 +0000 (11:58 +0100)
committerSebastian Wagner <sebastian.wagner@suse.com>
Mon, 10 Feb 2020 11:11:52 +0000 (12:11 +0100)
Both classes are essentially equal. Keeping both just makes thigs
more compicated.

Signed-off-by: Sebastian Wagner <sebastian.wagner@suse.com>
doc/mgr/orchestrator_modules.rst
src/pybind/mgr/cephadm/module.py
src/pybind/mgr/cephadm/tests/test_cephadm.py
src/pybind/mgr/orchestrator.py
src/pybind/mgr/orchestrator_cli/module.py
src/pybind/mgr/rook/module.py
src/pybind/mgr/rook/rook_cluster.py
src/pybind/mgr/test_orchestrator/module.py
src/pybind/mgr/volumes/fs/fs_util.py

index 0a03616dda00670eee4315809fece0df336f2711..9d6859e8fd9b786fb7ce91d18f2fd1255a9d0ff4 100644 (file)
@@ -242,6 +242,8 @@ Service Actions
 
 .. automethod:: Orchestrator.service_action
 
+.. autoclass:: ServiceSpec
+
 OSD management
 --------------
 
@@ -287,8 +289,6 @@ Phase two is a call to  :meth:`Orchestrator.create_osds` with a Drive Group with
 Stateless Services
 ------------------
 
-.. autoclass:: StatelessServiceSpec
-
 .. automethod:: Orchestrator.add_mds
 .. automethod:: Orchestrator.remove_mds
 .. automethod:: Orchestrator.update_mds
index 1a38ef0876c66d87b1f8ebc2088a2098485f9113..fcf0d941fe1848294eda68037b6e4727c8693e98 100644 (file)
@@ -1756,7 +1756,7 @@ class CephadmOrchestrator(MgrModule, orchestrator.OrchestratorClientMixin):
                                    extra_config=extra_config)
 
     def update_mons(self, spec):
-        # type: (orchestrator.StatefulServiceSpec) -> orchestrator.Completion
+        # type: (orchestrator.ServiceSpec) -> orchestrator.Completion
         """
         Adjust the number of cluster managers.
         """
@@ -1768,7 +1768,7 @@ class CephadmOrchestrator(MgrModule, orchestrator.OrchestratorClientMixin):
         return self._update_mons(spec)
 
     def _update_mons(self, spec):
-        # type: (orchestrator.StatefulServiceSpec) -> orchestrator.Completion
+        # type: (orchestrator.ServiceSpec) -> orchestrator.Completion
         """
         Adjust the number of cluster monitors.
         """
@@ -1826,7 +1826,7 @@ class CephadmOrchestrator(MgrModule, orchestrator.OrchestratorClientMixin):
 
     @with_services('mgr')
     def update_mgrs(self, spec, services):
-        # type: (orchestrator.StatefulServiceSpec, List[orchestrator.ServiceDescription]) -> orchestrator.Completion
+        # type: (orchestrator.ServiceSpec, List[orchestrator.ServiceDescription]) -> orchestrator.Completion
         """
         Adjust the number of cluster managers.
         """
@@ -2265,19 +2265,19 @@ class NodeAssignment(object):
     """
 
     def __init__(self,
-                 spec=None,  # type: Optional[orchestrator.StatefulServiceSpec]
+                 spec=None,  # type: Optional[orchestrator.ServiceSpec]
                  scheduler=None,  # type: Optional[BaseScheduler]
                  get_hosts_func=None,  # type: Optional[Callable]
                  service_type=None,  # type: Optional[str]
                  ):
         assert spec and get_hosts_func and service_type
-        self.spec = spec  # type: orchestrator.StatefulServiceSpec
+        self.spec = spec  # type: orchestrator.ServiceSpec
         self.scheduler = scheduler if scheduler else SimpleScheduler(self.spec.placement)
         self.get_hosts_func = get_hosts_func
         self.service_type = service_type
 
     def load(self):
-        # type: () -> orchestrator.StatefulServiceSpec
+        # type: () -> orchestrator.ServiceSpec
         """
         Load nodes into the spec.placement.nodes container.
         """
index a6d768be8a882b6389286b4edd9bb3d0de13c4df..52c5adc8a8c4c6e10a5e5e29a002653102b46b80 100644 (file)
@@ -10,7 +10,7 @@ except ImportError:
     pass
 
 from orchestrator import ServiceDescription, InventoryNode, \
-    StatelessServiceSpec, PlacementSpec, RGWSpec, StatefulServiceSpec, HostSpec
+    ServiceSpec, PlacementSpec, RGWSpec, HostSpec
 from tests import mock
 from .fixtures import cephadm_module, wait
 
@@ -105,7 +105,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(StatefulServiceSpec(placement=ps))
+            c = cephadm_module.update_mons(ServiceSpec(placement=ps))
             assert wait(cephadm_module, c) == ["Deployed mon.a on host 'test'"]
 
     @mock.patch("cephadm.module.CephadmOrchestrator._run_cephadm", _run_cephadm('[]'))
@@ -115,7 +115,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(StatefulServiceSpec(placement=ps))
+            c = cephadm_module.update_mgrs(ServiceSpec(placement=ps))
             [out] = wait(cephadm_module, c)
             assert "Deployed mgr." in out
             assert " on host 'test'" in out
@@ -157,7 +157,7 @@ class TestCephadm(object):
     def test_mds(self, _send_command, _get_connection, cephadm_module):
         with self._with_host(cephadm_module, 'test'):
             ps = PlacementSpec(hosts=['test'], count=1)
-            c = cephadm_module.add_mds(StatelessServiceSpec('name', placement=ps))
+            c = cephadm_module.add_mds(ServiceSpec('name', placement=ps))
             [out] = wait(cephadm_module, c)
             assert "Deployed mds.name." in out
             assert " on host 'test'" in out
@@ -202,7 +202,7 @@ class TestCephadm(object):
     def test_rbd_mirror(self, _send_command, _get_connection, cephadm_module):
         with self._with_host(cephadm_module, 'test'):
             ps = PlacementSpec(hosts=['test'], count=1)
-            c = cephadm_module.add_rbd_mirror(StatelessServiceSpec(name='name', placement=ps))
+            c = cephadm_module.add_rbd_mirror(ServiceSpec(name='name', placement=ps))
             [out] = wait(cephadm_module, c)
             assert "Deployed rbd-mirror." in out
             assert " on host 'test'" in out
index a295f42c3aaa0e88fc51552bbca1cae1837489eb..6e5c4120db86d1b949799c0af91fcefb3e182188 100644 (file)
@@ -907,7 +907,7 @@ class Orchestrator(object):
         raise NotImplementedError()
 
     def update_mgrs(self, spec):
-        # type: (StatefulServiceSpec) -> Completion
+        # type: (ServiceSpec) -> Completion
         """
         Update the number of cluster managers.
 
@@ -917,7 +917,7 @@ class Orchestrator(object):
         raise NotImplementedError()
 
     def update_mons(self, spec):
-        # type: (StatefulServiceSpec) -> Completion
+        # type: (ServiceSpec) -> Completion
         """
         Update the number of cluster monitors.
 
@@ -927,7 +927,7 @@ class Orchestrator(object):
         raise NotImplementedError()
 
     def add_mds(self, spec):
-        # type: (StatelessServiceSpec) -> Completion
+        # type: (ServiceSpec) -> Completion
         """Create a new MDS cluster"""
         raise NotImplementedError()
 
@@ -937,7 +937,7 @@ class Orchestrator(object):
         raise NotImplementedError()
 
     def update_mds(self, spec):
-        # type: (StatelessServiceSpec) -> Completion
+        # type: (ServiceSpec) -> Completion
         """
         Update / redeploy existing MDS cluster
         Like for example changing the number of service instances.
@@ -945,7 +945,7 @@ class Orchestrator(object):
         raise NotImplementedError()
 
     def add_rbd_mirror(self, spec):
-        # type: (StatelessServiceSpec) -> Completion
+        # type: (ServiceSpec) -> Completion
         """Create rbd-mirror cluster"""
         raise NotImplementedError()
 
@@ -955,7 +955,7 @@ class Orchestrator(object):
         raise NotImplementedError()
 
     def update_rbd_mirror(self, spec):
-        # type: (StatelessServiceSpec) -> Completion
+        # type: (ServiceSpec) -> Completion
         """
         Update / redeploy rbd-mirror cluster
         Like for example changing the number of service instances.
@@ -1200,51 +1200,39 @@ class ServiceDescription(object):
         return cls(**data)
 
 
-class StatefulServiceSpec(object):
-    """ Such as mgrs/mons
+class ServiceSpec(object):
     """
-    # TODO: create base class for Stateless/Stateful service specs and propertly inherit
-    def __init__(self, name=None, placement=None):
-        # type: (Optional[str], Optional[PlacementSpec]) -> None
-        self.placement = PlacementSpec() if placement is None else placement  # type: PlacementSpec
-        self.name = name
+    Details of service creation.
 
-        # for backwards-compatibility
-        if self.placement is not None and self.placement.count is not None:
-            self.count = self.placement.count
-        else:
-            self.count = 1
+    Request to the orchestrator for a cluster of daemons
+    such as MDS, RGW, iscsi gateway, MONs, MGRs, Prometheus
 
+    This structure is supposed to be enough information to
+    start the services.
 
-class StatelessServiceSpec(object):
-    # Request to orchestrator for a group of stateless services
-    # such as MDS, RGW, nfs gateway, iscsi gateway
     """
-    Details of stateless service creation.
 
-    Request to orchestrator for a group of stateless services
-    such as MDS, RGW or iscsi gateway
-    """
-    # This structure is supposed to be enough information to
-    # start the services.
-
-    def __init__(self, name, placement=None):
+    def __init__(self, name=None, placement=None):
+        # type: (Optional[str], Optional[PlacementSpec]) -> None
         self.placement = PlacementSpec() if placement is None else placement  # type: PlacementSpec
 
-        #: Give this set of statelss services a name: typically it would
+        #: Give this set of stateless services a name: typically it would
         #: be the name of a CephFS filesystem, RGW zone, etc.  Must be unique
-        #: within one ceph cluster.
-        self.name = name  # type: str
+        #: within one ceph cluster. Note: Not all clusters have a name
+        self.name = name  # type: Optional[str]
 
-        #: Count of service instances
-        self.count = self.placement.count if self.placement is not None else 1  # for backwards-compatibility
+        if self.placement is not None and self.placement.count is not None:
+            #: Count of service instances. Deprecated.
+            self.count = self.placement.count  # type: int
+        else:
+            self.count = 1
 
     def validate_add(self):
         if not self.name:
             raise OrchestratorValidationError('Cannot add Service: Name required')
 
 
-class NFSServiceSpec(StatelessServiceSpec):
+class NFSServiceSpec(ServiceSpec):
     def __init__(self, name, pool=None, namespace=None, placement=None):
         super(NFSServiceSpec, self).__init__(name, placement)
 
@@ -1261,7 +1249,7 @@ class NFSServiceSpec(StatelessServiceSpec):
             raise OrchestratorValidationError('Cannot add NFS: No Pool specified')
 
 
-class RGWSpec(StatelessServiceSpec):
+class RGWSpec(ServiceSpec):
     """
     Settings to configure a (multisite) Ceph RGW
 
index 66e3366a11a8505915d84e2f8e4fa5126b99abad..0ca04990c1fac37684d2ad3ad607d8658ff3d848 100644 (file)
@@ -408,7 +408,7 @@ Usage:
         "name=hosts,type=CephString,n=N,req=false",
         'Create an rbd-mirror service')
     def _rbd_mirror_add(self, num=None, hosts=None):
-        spec = orchestrator.StatelessServiceSpec(
+        spec = orchestrator.ServiceSpec(
             None,
             placement=orchestrator.PlacementSpec(hosts=hosts, count=num))
         completion = self.add_rbd_mirror(spec)
@@ -423,7 +423,7 @@ Usage:
         "name=label,type=CephString,req=false",
         'Update the number of rbd-mirror instances')
     def _rbd_mirror_update(self, num, label=None, hosts=[]):
-        spec = orchestrator.StatelessServiceSpec(
+        spec = orchestrator.ServiceSpec(
             None,
             placement=orchestrator.PlacementSpec(hosts=hosts, count=num, label=label))
         completion = self.update_rbd_mirror(spec)
@@ -448,7 +448,7 @@ Usage:
         "name=hosts,type=CephString,n=N,req=false",
         'Create an MDS service')
     def _mds_add(self, fs_name, num=None, hosts=None):
-        spec = orchestrator.StatelessServiceSpec(
+        spec = orchestrator.ServiceSpec(
             fs_name,
             placement=orchestrator.PlacementSpec(hosts=hosts, count=num))
         completion = self.add_mds(spec)
@@ -467,7 +467,7 @@ Usage:
         placement = orchestrator.PlacementSpec(label=label, count=num, hosts=hosts)
         placement.validate()
 
-        spec = orchestrator.StatelessServiceSpec(
+        spec = orchestrator.ServiceSpec(
             fs_name,
             placement=placement)
 
@@ -630,7 +630,7 @@ Usage:
         placement = orchestrator.PlacementSpec(label=label, count=num, hosts=hosts)
         placement.validate()
 
-        spec = orchestrator.StatefulServiceSpec(placement=placement)
+        spec = orchestrator.ServiceSpec(placement=placement)
 
         completion = self.update_mgrs(spec)
         self._orchestrator_wait([completion])
@@ -650,7 +650,7 @@ Usage:
         placement = orchestrator.PlacementSpec(label=label, count=num, hosts=hosts)
         placement.validate()
 
-        spec = orchestrator.StatefulServiceSpec(placement=placement)
+        spec = orchestrator.ServiceSpec(placement=placement)
 
         completion = self.update_mons(spec)
         self._orchestrator_wait([completion])
index 098a66e81ba7f00bcf7c376b4120e36d825d5e52..fcbbb0330c8dd8ede3303a6fe7da528686f77255 100644 (file)
@@ -304,7 +304,7 @@ class RookOrchestrator(MgrModule, orchestrator.Orchestrator):
         )
 
     def add_mds(self, spec):
-        # type: (orchestrator.StatelessServiceSpec) -> RookCompletion
+        # type: (orchestrator.ServiceSpec) -> RookCompletion
         return self._service_add_decorate('MDS', spec,
                                        self.rook_cluster.add_filesystem)
 
@@ -341,7 +341,7 @@ class RookOrchestrator(MgrModule, orchestrator.Orchestrator):
         )
 
     def update_mons(self, spec):
-        # type: (orchestrator.StatefulServiceSpec) -> RookCompletion
+        # type: (orchestrator.ServiceSpec) -> RookCompletion
         if spec.placement.hosts or spec.placement.label:
             raise RuntimeError("Host list or label is not supported by rook.")
 
@@ -352,7 +352,7 @@ class RookOrchestrator(MgrModule, orchestrator.Orchestrator):
         )
 
     def update_mds(self, spec):
-        # type: (orchestrator.StatelessServiceSpec) -> RookCompletion
+        # type: (orchestrator.ServiceSpec) -> RookCompletion
         num = spec.count
         return write_completion(
             lambda: self.rook_cluster.update_mds_count(spec.name, num),
index 78475d23b31e2a198f0573bb14c5f663e7d1d54d..040fe3bf401b3a9368d14ebf72676034a73b7670 100644 (file)
@@ -336,7 +336,7 @@ class RookCluster(object):
                 raise
 
     def add_filesystem(self, spec):
-        # type: (orchestrator.StatelessServiceSpec) -> None
+        # type: (orchestrator.ServiceSpec) -> None
         # TODO use spec.placement
         # TODO warn if spec.extended has entries we don't kow how
         #      to action.
index 7e712dc0170dcff9e0d42c2bba9bbabb7b630db4..99d1ed439012d46eaecacfa1bf96506e0b3e28c6 100644 (file)
@@ -284,14 +284,14 @@ class TestOrchestrator(MgrModule, orchestrator.Orchestrator):
 
     @deferred_write("update_mgrs")
     def update_mgrs(self, spec):
-        # type: (orchestrator.StatefulServiceSpec) -> None
+        # type: (orchestrator.ServiceSpec) -> None
 
         assert not spec.placement.hosts or len(spec.placement.hosts) == spec.placement.count
         assert all([isinstance(h, str) for h in spec.placement.hosts])
 
     @deferred_write("update_mons")
     def update_mons(self, spec):
-        # type: (orchestrator.StatefulServiceSpec) -> None
+        # type: (orchestrator.ServiceSpec) -> None
 
         assert not spec.placement.hosts or len(spec.placement.hosts) == spec.placement.count
         assert all([isinstance(h[0], str) for h in spec.placement.hosts])
index 3ac8c075c7597f95f7775b58510e8167233e37ff..2b201877dae0a0bad9a46c554ff5fc2a0ce2e1df 100644 (file)
@@ -34,7 +34,7 @@ def remove_filesystem(mgr, fs_name):
     return mgr.mon_command(command)
 
 def create_mds(mgr, fs_name):
-    spec = orchestrator.StatelessServiceSpec(fs_name)
+    spec = orchestrator.ServiceSpec(fs_name)
     try:
         completion = mgr.add_mds(spec)
         mgr._orchestrator_wait([completion])