]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
qa/mgr: add test for command execution errors
authorJohn Spray <john.spray@redhat.com>
Thu, 23 Nov 2017 15:49:51 +0000 (10:49 -0500)
committerJohn Spray <john.spray@redhat.com>
Wed, 24 Jan 2018 18:08:20 +0000 (13:08 -0500)
Signed-off-by: John Spray <john.spray@redhat.com>
qa/tasks/mgr/test_module_selftest.py
src/pybind/mgr/selftest/module.py

index 5bb4602aefc9ad7e510753b88990d848cfe52638..cd85a3e0d0aee646b4eacbc47c063ebf150fa0fc 100644 (file)
@@ -1,6 +1,8 @@
 
 import time
 import requests
+import errno
+from teuthology.exceptions import CommandFailedError
 
 from tasks.mgr.mgr_test_case import MgrTestCase
 
@@ -76,3 +78,44 @@ class TestModuleSelftest(MgrTestCase):
         # Check that all mgr daemons are still running
         self.assertEqual(original_active, self.mgr_cluster.get_active_id())
         self.assertEqual(original_standbys, self.mgr_cluster.get_standby_ids())
+
+    def test_module_commands(self):
+        """
+        That module-handled commands have appropriate  behavior on
+        disabled/failed/recently-enabled modules.
+        """
+
+        self._load_module("selftest")
+
+        # Calling a command on a disabled module should return the proper
+        # error code.
+        self.mgr_cluster.mon_manager.raw_cluster_cmd(
+            "mgr", "module", "disable", "status")
+        with self.assertRaises(CommandFailedError) as exc_raised:
+            self.mgr_cluster.mon_manager.raw_cluster_cmd(
+                "osd", "status")
+
+        self.assertEqual(exc_raised.exception.exitstatus, errno.EOPNOTSUPP)
+
+        # Calling a command that really doesn't exist should give me EINVAL.
+        with self.assertRaises(CommandFailedError) as exc_raised:
+            self.mgr_cluster.mon_manager.raw_cluster_cmd(
+                "osd", "albatross")
+
+        self.assertEqual(exc_raised.exception.exitstatus, errno.EINVAL)
+
+        # Enabling a module and then immediately using ones of its commands
+        # should work (#21683)
+        self.mgr_cluster.mon_manager.raw_cluster_cmd(
+            "mgr", "module", "enable", "status")
+        self.mgr_cluster.mon_manager.raw_cluster_cmd("osd", "status")
+
+        # Calling a command for a failed module should return the proper
+        # error code.
+        self.mgr_cluster.mon_manager.raw_cluster_cmd(
+            "mgr", "self-test", "background", "start", "throw_exception")
+        with self.assertRaises(CommandFailedError) as exc_raised:
+            self.mgr_cluster.mon_manager.raw_cluster_cmd(
+                "mgr", "self-test", "run"
+            )
+        self.assertEqual(exc_raised.exception.exitstatus, errno.EIO)
index e289aee94f6ffebc4b240fb736cce41943dcd254..401ff1eede60f0333ca256e2ac1b6700f6fb9eeb 100644 (file)
@@ -17,10 +17,13 @@ class Module(MgrModule):
     activities in its serve() thread.
     """
 
+    # These workloads are things that can be requested to run inside the
+    # serve() function
     WORKLOAD_COMMAND_SPAM = "command_spam"
+    WORKLOAD_THROW_EXCEPTION = "throw_exception"
     SHUTDOWN = "shutdown"
 
-    WORKLOADS = (WORKLOAD_COMMAND_SPAM, )
+    WORKLOADS = (WORKLOAD_COMMAND_SPAM, WORKLOAD_THROW_EXCEPTION)
 
     COMMANDS = [
             {
@@ -211,6 +214,8 @@ class Module(MgrModule):
             elif self._workload == self.SHUTDOWN:
                 self.log.info("Shutting down...")
                 break
+            elif self._workload == self.WORKLOAD_THROW_EXCEPTION:
+                raise RuntimeError("Synthetic exception in serve")
             else:
                 self.log.info("Waiting for workload request...")
                 self._event.wait()