]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
cephfs-shell: exit with non-zero on getting unrecognized cmd 45974/head
authorRishabh Dave <ridave@redhat.com>
Wed, 20 Apr 2022 16:00:14 +0000 (21:30 +0530)
committerRishabh Dave <ridave@redhat.com>
Fri, 22 Apr 2022 06:04:41 +0000 (11:34 +0530)
Right now cephfs-shell on receiving unrecognized command prints an
appropriate message on stderr but the return value is zero. This is a
serious problem for users as well as for tests. It must exit with
non-zero return value.

The return value chosen for this case is 127, same as bash.

Changes in test_cephfs_shell.py, besides addition of TestGeneric, are
tests that are buggy and the bug now changes the test's behaviour since
the cephfs-shell bug has now been fixed.

Fixes: https://tracker.ceph.com/issues/55399
Signed-off-by: Rishabh Dave <ridave@redhat.com>
qa/tasks/cephfs/test_cephfs_shell.py
src/tools/cephfs/cephfs-shell

index ac82a1584b741c1c8fc97a7db960877e9bd2dc33..dc0883e9d43a33563d59ee666ab04599982abca0 100644 (file)
@@ -159,6 +159,14 @@ class TestCephFSShell(CephFSTestCase):
             check_status=check_status).stdout.getvalue().strip())
 
 
+class TestGeneric(TestCephFSShell):
+
+    def test_mistyped_cmd(self):
+        with self.assertRaises(CommandFailedError) as cm:
+            self.run_cephfs_shell_cmd('lsx')
+        self.assertEqual(cm.exception.exitstatus, 127)
+
+
 class TestMkdir(TestCephFSShell):
     def test_mkdir(self):
         """
@@ -267,7 +275,14 @@ class TestRmdir(TestCephFSShell):
         """
         self.run_cephfs_shell_cmd("mkdir " + self.dir_name)
         self.run_cephfs_shell_cmd("put - test_dir/dumpfile", stdin="Valid File")
-        self.run_cephfs_shell_cmd("rmdir" + self.dir_name)
+        # see comment below
+        # with self.assertRaises(CommandFailedError) as cm:
+        with self.assertRaises(CommandFailedError):
+            self.run_cephfs_shell_cmd("rmdir " + self.dir_name)
+        # TODO: we need to check for exit code and error message as well.
+        # skipping it for not since error codes used by cephfs-shell are not
+        # standard and they may change soon.
+        # self.assertEqual(cm.exception.exitcode, 39)
         self.mount_a.stat(self.dir_name)
 
     def test_rmdir_existing_file(self):
index 1902521325cb023434a4cbdb21c440b9ae61906f..8e6b8bde7532553493415e901aee9cb0b41c3996 100755 (executable)
@@ -393,6 +393,7 @@ class CephFSShell(Cmd):
         self.umask = '2'
 
     def default(self, line):
+        self.exit_code = 127
         perror('Unrecognized command')
 
     def set_prompt(self):