]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
qa: fixing failures in TestShellOpts 69031/head
authorNeeraj Pratap Singh <Neeraj.Pratap.Singh1@ibm.com>
Wed, 20 May 2026 17:23:09 +0000 (22:53 +0530)
committerNeeraj Pratap Singh <Neeraj.Pratap.Singh1@ibm.com>
Wed, 20 May 2026 17:23:09 +0000 (22:53 +0530)
We were seeing failures in TestShellOpts again
and again due the (newline added within the output)
output structure change with the cmd2 releases.
Now, we directly extract the final output of 'set editor'
command and use it, instead of traversing on complete output
through hardcoded indexes.This fix is better than earlier
hardcoded splitting/striping via indexes.

Fixes: https://tracker.ceph.com/issues/71795
Signed-off-by: Neeraj Pratap Singh <Neeraj.Pratap.Singh1@ibm.com>
qa/tasks/cephfs/test_cephfs_shell.py

index 0864c1e5a7999ed0cd51517d88ed97e1afb33950..0cc4dab776011153ea9e59681f5d715c5245b501 100644 (file)
@@ -1109,6 +1109,17 @@ class TestShellOpts(TestCephFSShell):
     Contains tests for shell options from conf file and shell prompt.
     """
 
+    def extract_set_editor_output(self, out):
+        res = None
+        for line in out.splitlines():
+            line_parts = line.split()
+            if len(line_parts) > 4 and line_parts[0] == "editor":
+                res = line_parts
+                break
+
+        self.assertIsNotNone(res, f"didn't find editor output in: {out}")
+        return res[1]
+
     def setUp(self):
         super(type(self), self).setUp()
 
@@ -1119,9 +1130,8 @@ class TestShellOpts(TestCephFSShell):
         # ====================================================================================================
         # editor  ?                               Program used by 'edit'
         self.editor_val = self.get_cephfs_shell_cmd_output(
-            'set editor ?, set editor').split('\n')[4]
-        self.editor_val = self.editor_val.split()[1].strip(). \
-            replace("'", "", 2)
+            'set editor ?, set editor')
+        self.editor_val = self.extract_set_editor_output(self.editor_val)
 
     def write_tempconf(self, confcontents):
         self.tempconfpath = self.mount_a.client_remote.mktemp(
@@ -1139,9 +1149,7 @@ class TestShellOpts(TestCephFSShell):
         # editor  ???                             Program used by 'edit'
         final_editor_val = self.get_cephfs_shell_cmd_output(
             cmd='set editor', shell_conf_path=self.tempconfpath)
-        final_editor_val = final_editor_val.split('\n')[2]
-        final_editor_val = final_editor_val.split()[1].strip(). \
-            replace("'", "", 2)
+        final_editor_val = self.extract_set_editor_output(final_editor_val)
 
         self.assertNotEqual(self.editor_val, final_editor_val)
 
@@ -1159,9 +1167,7 @@ class TestShellOpts(TestCephFSShell):
         # editor  ?                               Program used by 'edit'
         final_editor_val = self.get_cephfs_shell_cmd_output(
             cmd='set editor', shell_conf_path=self.tempconfpath)
-        final_editor_val = final_editor_val.split('\n')[2]
-        final_editor_val = final_editor_val.split()[1].strip(). \
-            replace("'", "", 2)
+        final_editor_val = self.extract_set_editor_output(final_editor_val)
 
         self.assertEqual(self.editor_val, final_editor_val)
 
@@ -1177,8 +1183,6 @@ class TestShellOpts(TestCephFSShell):
         final_editor_val = self.get_cephfs_shell_cmd_output(
             cmd='set editor %s, set editor' % self.editor_val,
             shell_conf_path=self.tempconfpath)
-        final_editor_val = final_editor_val.split('\n')[4]
-        final_editor_val = final_editor_val.split()[1].strip(). \
-            replace("'", "", 2)
+        final_editor_val = self.extract_set_editor_output(final_editor_val)
 
         self.assertEqual(self.editor_val, final_editor_val)