From 028cb031ddb72c1f37048c8568ecdf43f5b77b50 Mon Sep 17 00:00:00 2001 From: Redouane Kachach Date: Fri, 26 Aug 2022 12:31:45 +0200 Subject: [PATCH] cephadm/mgr: adding logic to handle -no-overwrite for tuned profiles Fixes: https://tracker.ceph.com/issues/57032 Signed-off-by: Redouane Kachach --- doc/cephadm/host-management.rst | 7 ++++++- src/pybind/mgr/cephadm/inventory.py | 3 +++ src/pybind/mgr/cephadm/module.py | 9 ++++++--- src/pybind/mgr/orchestrator/_interface.py | 2 +- src/pybind/mgr/orchestrator/module.py | 2 +- 5 files changed, 17 insertions(+), 6 deletions(-) diff --git a/doc/cephadm/host-management.rst b/doc/cephadm/host-management.rst index f3cc7e6d290..fee286e3a72 100644 --- a/doc/cephadm/host-management.rst +++ b/doc/cephadm/host-management.rst @@ -267,7 +267,7 @@ Then apply the tuning profile with:: This profile will then be written to ``/etc/sysctl.d/`` on each host matching the given placement and `sysctl --system` will be run on the host. -.. note:: +.. note:: The exact filename the profile will be written to is within ``/etc/sysctl.d/`` is ``-cephadm-tuned-profile.conf`` where @@ -281,6 +281,11 @@ given placement and `sysctl --system` will be run on the host. These settings are applied only at the host level, and are not specific to any certain daemon or container +.. note:: + + Applying tuned profiles is idempotent when the ``--no-overwrite`` option is passed. + In this case existing profiles with the same name are not overwritten. + Viewing Profiles ---------------- diff --git a/src/pybind/mgr/cephadm/inventory.py b/src/pybind/mgr/cephadm/inventory.py index bf0dbb53410..04385a4fa81 100644 --- a/src/pybind/mgr/cephadm/inventory.py +++ b/src/pybind/mgr/cephadm/inventory.py @@ -425,6 +425,9 @@ class TunedProfileStore(): self.profiles[k] = TunedProfileSpec.from_json(v) self.profiles[k]._last_updated = datetime_to_str(datetime_now()) + def exists(self, profile_name: str) -> bool: + return profile_name in self.profiles + def save(self) -> None: profiles_json = {k: v.to_json() for k, v in self.profiles.items()} self.mgr.set_store('tuned_profiles', json.dumps(profiles_json)) diff --git a/src/pybind/mgr/cephadm/module.py b/src/pybind/mgr/cephadm/module.py index e5d0752d6a8..e3d90f13aeb 100644 --- a/src/pybind/mgr/cephadm/module.py +++ b/src/pybind/mgr/cephadm/module.py @@ -2536,11 +2536,14 @@ Then run the following: return self._apply_service_spec(cast(ServiceSpec, spec)) @handle_orch_error - def apply_tuned_profiles(self, specs: List[TunedProfileSpec]) -> str: + def apply_tuned_profiles(self, specs: List[TunedProfileSpec], no_overwrite: bool = False) -> str: outs = [] for spec in specs: - self.tuned_profiles.add_profile(spec) - outs.append(f'Saved tuned profile {spec.profile_name}') + if no_overwrite and self.tuned_profiles.exists(spec.profile_name): + outs.append(f"Tuned profile '{spec.profile_name}' already exists (--no-overwrite was passed)") + else: + self.tuned_profiles.add_profile(spec) + outs.append(f'Saved tuned profile {spec.profile_name}') self._kick_serve_loop() return '\n'.join(outs) diff --git a/src/pybind/mgr/orchestrator/_interface.py b/src/pybind/mgr/orchestrator/_interface.py index 4f7a961af47..3b92e50f927 100644 --- a/src/pybind/mgr/orchestrator/_interface.py +++ b/src/pybind/mgr/orchestrator/_interface.py @@ -687,7 +687,7 @@ class Orchestrator(object): """Update an existing snmp gateway service""" raise NotImplementedError() - def apply_tuned_profiles(self, specs: List[TunedProfileSpec]) -> OrchResult[str]: + def apply_tuned_profiles(self, specs: List[TunedProfileSpec], no_overwrite: bool) -> OrchResult[str]: """Add or update an existing tuned profile""" raise NotImplementedError() diff --git a/src/pybind/mgr/orchestrator/module.py b/src/pybind/mgr/orchestrator/module.py index a11d87cb08c..fe975ff0c3d 100644 --- a/src/pybind/mgr/orchestrator/module.py +++ b/src/pybind/mgr/orchestrator/module.py @@ -1440,7 +1440,7 @@ Usage: tuned_profile_spec = TunedProfileSpec( profile_name=profile_name, placement=placement_spec, settings=settings_dict) specs = [tuned_profile_spec] - completion = self.apply_tuned_profiles(specs) + completion = self.apply_tuned_profiles(specs, no_overwrite) res = raise_if_exception(completion) return HandleCommandResult(stdout=res) -- 2.39.5