]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
cephadm/mgr: adding logic to handle -no-overwrite for tuned profiles 47944/head
authorRedouane Kachach <rkachach@redhat.com>
Fri, 26 Aug 2022 10:31:45 +0000 (12:31 +0200)
committerAdam King <adking@redhat.com>
Sat, 3 Sep 2022 17:03:36 +0000 (13:03 -0400)
Fixes: https://tracker.ceph.com/issues/57032
Signed-off-by: Redouane Kachach <rkachach@redhat.com>
(cherry picked from commit 028cb031ddb72c1f37048c8568ecdf43f5b77b50)

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 7a88258f002dc401993f70a0ec309063c82b764c..4f94577a3a0c2637753ec7c50218aa4266b3dd1e 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 cd42c7b6e5d35e1ccaab86d1dd53a25f1c9b0f50..8c6b7b85ca856a82594fb5550640764ef9d16c9a 100644 (file)
@@ -2475,11 +2475,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 4f6c40f1d94943c605f71150b2840a40caf86c0f..6f0374ffede94dc1c0571981ee5af61ac10986aa 100644 (file)
@@ -679,7 +679,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 ed0c66aed14ee4748dc8f0169bc0890c2c7c7c64..f8d2d2d7b8760ce136040d75ce42e10e101924e4 100644 (file)
@@ -1401,7 +1401,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)