From f95b079c213edf1cce247ef185522ad77fc4c0e4 Mon Sep 17 00:00:00 2001 From: John Spray Date: Thu, 23 Nov 2017 10:49:51 -0500 Subject: [PATCH] qa/mgr: add test for command execution errors Signed-off-by: John Spray --- qa/tasks/mgr/test_module_selftest.py | 43 ++++++++++++++++++++++++++++ src/pybind/mgr/selftest/module.py | 7 ++++- 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/qa/tasks/mgr/test_module_selftest.py b/qa/tasks/mgr/test_module_selftest.py index 5bb4602aefc..cd85a3e0d0a 100644 --- a/qa/tasks/mgr/test_module_selftest.py +++ b/qa/tasks/mgr/test_module_selftest.py @@ -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) diff --git a/src/pybind/mgr/selftest/module.py b/src/pybind/mgr/selftest/module.py index e289aee94f6..401ff1eede6 100644 --- a/src/pybind/mgr/selftest/module.py +++ b/src/pybind/mgr/selftest/module.py @@ -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() -- 2.39.5