]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/cephadm: fix tuned profiles getting removed if name has dashes 47936/head
authorAdam King <adking@redhat.com>
Thu, 1 Sep 2022 17:08:13 +0000 (13:08 -0400)
committerAdam King <adking@redhat.com>
Tue, 13 Sep 2022 12:52:10 +0000 (08:52 -0400)
Previously, due to the way it was just splitting the file name on
dashes to try and get the profile name, any profile name with dashes
was not getting properly matched and would therefore get marked
stray and removed. This new strategy instead tries to match the actual
expected file name.

Fixes: https://tracker.ceph.com/issues/57405
Signed-off-by: Adam King <adking@redhat.com>
src/pybind/mgr/cephadm/tuned_profiles.py

index 3f617956846ba62471702526db38c710a150c27d..5e5189f629f5b651e11836741842ae7e3529a183 100644 (file)
@@ -47,16 +47,39 @@ class TunedProfileUtils():
             self._write_tuned_profiles(host, profiles)
 
     def _remove_stray_tuned_profiles(self, host: str, profiles: List[Dict[str, str]]) -> None:
+        """
+        this function looks at the contents of /etc/sysctl.d/ for profiles we have written
+        that should now be removed. It assumes any file with "-cephadm-tuned-profile.conf" in
+        it is written by us any without that are not. Only files written by us are considered
+        candidates for removal. The "profiles" parameter is a list of dictionaries that map
+        profile names to the file contents to actually be written to the
+        /etc/sysctl.d/<profile-name>-cephadm-tuned-profile.conf. For example
+        [
+            {
+                'profile1': 'setting1: value1\nsetting2: value2'
+            },
+            {
+                'profile2': 'setting3: value3'
+            }
+        ]
+        what we want to end up doing is going through the keys of the dicts and appending
+        -cephadm-tuned-profile.conf to the profile names to build our list of profile files that
+        SHOULD be on the host. Then if we see any file names that don't match this, but
+        DO include "-cephadm-tuned-profile.conf" (implying they're from us), remove them.
+        """
         if host in self.mgr.offline_hosts:
             return
         cmd = ['ls', SYSCTL_DIR]
         found_files = self.mgr.ssh.check_execute_command(host, cmd).split('\n')
         found_files = [s.strip() for s in found_files]
+        profile_names: List[str] = sum([[*p] for p in profiles], [])  # extract all profiles names
+        profile_names = list(set(profile_names))  # remove duplicates
+        expected_files = [p + '-cephadm-tuned-profile.conf' for p in profile_names]
         updated = False
         for file in found_files:
             if '-cephadm-tuned-profile.conf' not in file:
                 continue
-            if not any(file.split('-')[0] in p.keys() for p in profiles):
+            if file not in expected_files:
                 logger.info(f'Removing stray tuned profile file {file}')
                 cmd = ['rm', '-f', f'{SYSCTL_DIR}/{file}']
                 self.mgr.ssh.check_execute_command(host, cmd)