]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
cephadm/mgr: adding logic to handle -no-overwrite for tuned profiles
authorRedouane Kachach <rkachach@redhat.com>
Fri, 26 Aug 2022 10:31:45 +0000 (12:31 +0200)
committerRedouane Kachach <rkachach@redhat.com>
Tue, 30 Aug 2022 14:24:52 +0000 (16:24 +0200)
Fixes: https://tracker.ceph.com/issues/57032
Signed-off-by: Redouane Kachach <rkachach@redhat.com>
doc/cephadm/host-management.rst
src/pybind/mgr/cephadm/inventory.py
src/pybind/mgr/cephadm/module.py
src/pybind/mgr/orchestrator/_interface.py
src/pybind/mgr/orchestrator/module.py

index f3cc7e6d2902bfc6afcc2b4ab2496fe64217d159..fee286e3a72a225aaf4936928aeb63f2eb1dc8bf 100644 (file)
@@ -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
   ``<profile-name>-cephadm-tuned-profile.conf`` where <profile-name>
@@ -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
 ----------------
index bf0dbb534101e0dafa4d60b7f5b33c93e4ee7e9e..04385a4fa81cc8e31b420133fcc487bb7b27ecbe 100644 (file)
@@ -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))
index e5d0752d6a8c63bdca1629d4abf91c2129d1b10d..e3d90f13aebd24b5efaea19e43c7a4dc406ba2c5 100644 (file)
@@ -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)
 
index 4f7a961af47f4625e3c99325449a59dcb215af7d..3b92e50f927bfd780f3b01147301aeacce241b0a 100644 (file)
@@ -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()
 
index a11d87cb08c2b3fba6a6bdb8c51ab796c70777f4..fe975ff0c3dc805a2a6ec9e7ecf92aaf5338424f 100644 (file)
@@ -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)