]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/cephadm: add commands to set services to managed/unmanaged 50100/head
authorAdam King <adking@redhat.com>
Mon, 13 Feb 2023 20:01:59 +0000 (15:01 -0500)
committerAdam King <adking@redhat.com>
Mon, 13 Feb 2023 20:13:36 +0000 (15:13 -0500)
Fixes: https://tracker.ceph.com/issues/58713
Signed-off-by: Adam King <adking@redhat.com>
doc/cephadm/services/index.rst
src/pybind/mgr/cephadm/inventory.py
src/pybind/mgr/cephadm/module.py
src/pybind/mgr/cephadm/tests/test_cephadm.py
src/pybind/mgr/orchestrator/_interface.py
src/pybind/mgr/orchestrator/module.py

index ab87326c1196d1b4f16a3583f464a3d9c9093a02..6596a8acdb452d9de0734b4b2a6e309bc134fed5 100644 (file)
@@ -686,6 +686,22 @@ To disable the automatic management of dameons, set ``unmanaged=True`` in the
 
    ceph orch apply -i mgr.yaml
 
+Cephadm also supports setting the unmanaged parameter to true or false
+using the ``ceph orch set-unmanaged`` and ``ceph orch set-managed`` commands.
+The commands take the service name (as reported in ``ceph orch ls``) as
+the only argument. For example,
+
+.. prompt:: bash #
+
+   ceph orch set-unmanaged mon
+
+would set ``unmanaged: true`` for the mon service and
+
+.. prompt:: bash #
+
+   ceph orch set-managed mon
+
+would set ``unmanaged: false`` for the mon service
 
 .. note::
 
@@ -693,6 +709,13 @@ To disable the automatic management of dameons, set ``unmanaged=True`` in the
   longer deploy any new daemons (even if the placement specification matches
   additional hosts).
 
+.. note::
+
+  The "osd" service used to track OSDs that are not tied to any specific
+  service spec is special and will always be marked unmanaged. Attempting
+  to modify it with ``ceph orch set-unmanaged`` or ``ceph orch set-managed``
+  will result in a message ``No service of name osd found. Check "ceph orch ls" for all known services``
+
 Deploying a daemon on a host manually
 -------------------------------------
 
index bb7be85f67ff5ebe71c87a6569baa017402f3eda..ad6f02f8ffedd0965b2283cbf5fabc6bf36bdd1c 100644 (file)
@@ -326,6 +326,15 @@ class SpecStore():
     def get_created(self, spec: ServiceSpec) -> Optional[datetime.datetime]:
         return self.spec_created.get(spec.service_name())
 
+    def set_unmanaged(self, service_name: str, value: bool) -> str:
+        if service_name not in self._specs:
+            return f'No service of name {service_name} found. Check "ceph orch ls" for all known services'
+        if self._specs[service_name].unmanaged == value:
+            return f'Service {service_name}{" already " if value else " not "}marked unmanaged. No action taken.'
+        self._specs[service_name].unmanaged = value
+        self.save(self._specs[service_name])
+        return f'Set unmanaged to {str(value)} for service {service_name}'
+
 
 class ClientKeyringSpec(object):
     """
index d60ee8b55fcea648d825a76036cc53d3d060f639..cfd1dfcdfd9c5d3cc9d652344078b8f34e9d2d2a 100644 (file)
@@ -2946,6 +2946,10 @@ Then run the following:
     def apply_snmp_gateway(self, spec: ServiceSpec) -> str:
         return self._apply(spec)
 
+    @handle_orch_error
+    def set_unmanaged(self, service_name: str, value: bool) -> str:
+        return self.spec_store.set_unmanaged(service_name, value)
+
     @handle_orch_error
     def upgrade_check(self, image: str, version: str) -> str:
         if self.inventory.get_host_with_state("maintenance"):
index 0d8f3201ab114454b757cb043622c289894fd227..4d8ed6c68d3a6136bd4a9323526325f294082817 100644 (file)
@@ -2139,3 +2139,11 @@ Traceback (most recent call last):
                 cephadm_module.inventory.all_specs = mock.Mock(
                     return_value=[mock.Mock().hostname, mock.Mock().hostname])
                 cephadm_module._validate_tuned_profile_spec(spec)
+
+    def test_set_unmanaged(self, cephadm_module):
+        cephadm_module.spec_store._specs['crash'] = ServiceSpec('crash', unmanaged=False)
+        assert not cephadm_module.spec_store._specs['crash'].unmanaged
+        cephadm_module.spec_store.set_unmanaged('crash', True)
+        assert cephadm_module.spec_store._specs['crash'].unmanaged
+        cephadm_module.spec_store.set_unmanaged('crash', False)
+        assert not cephadm_module.spec_store._specs['crash'].unmanaged
index 2972d92aa188863263f7497c2284ab6cfb9468c5..4ba2051231ef3cf17a624b63f96e43bbe3efeb2a 100644 (file)
@@ -502,6 +502,14 @@ class Orchestrator(object):
             return OrchResult(l_res)
         return raise_if_exception(reduce(merge, [fns[spec.service_type](spec) for spec in specs], OrchResult([])))
 
+    def set_unmanaged(self, service_name: str, value: bool) -> OrchResult[str]:
+        """
+        Set unmanaged parameter to True/False for a given service
+
+        :return: None
+        """
+        raise NotImplementedError()
+
     def plan(self, spec: Sequence["GenericSpec"]) -> OrchResult[List]:
         """
         Plan (Dry-run, Preview) a List of Specs.
index cc97612ad6a8e4052f1f8d874306e85929ea8757..bbfbcb4602355a65bdb8b28f281fca5407644fbb 100644 (file)
@@ -1431,6 +1431,22 @@ Usage:
         specs: List[ServiceSpec] = spec.get_tracing_specs()
         return self._apply_misc(specs, dry_run, format, no_overwrite)
 
+    @_cli_write_command('orch set-unmanaged')
+    def _set_unmanaged(self, service_name: str) -> HandleCommandResult:
+        """Set 'unmanaged: true' for the given service name"""
+        completion = self.set_unmanaged(service_name, True)
+        raise_if_exception(completion)
+        out = completion.result_str()
+        return HandleCommandResult(stdout=out)
+
+    @_cli_write_command('orch set-managed')
+    def _set_managed(self, service_name: str) -> HandleCommandResult:
+        """Set 'unmanaged: false' for the given service name"""
+        completion = self.set_unmanaged(service_name, False)
+        raise_if_exception(completion)
+        out = completion.result_str()
+        return HandleCommandResult(stdout=out)
+
     @_cli_write_command('orch set backend')
     def _set_backend(self, module_name: Optional[str] = None) -> HandleCommandResult:
         """