]>
git.proxmox.com Git - ceph.git/blob - ceph/qa/tasks/mgr/test_module_selftest.py
7 from teuthology
.exceptions
import CommandFailedError
9 from .mgr_test_case
import MgrTestCase
12 log
= logging
.getLogger(__name__
)
15 class TestModuleSelftest(MgrTestCase
):
17 That modules with a self-test command can be loaded and execute it
20 This is not a substitute for really testing the modules, but it
21 is quick and is designed to catch regressions that could occur
22 if data structures change in a way that breaks how the modules
28 super(TestModuleSelftest
, self
).setUp()
31 def _selftest_plugin(self
, module_name
):
32 self
._load
_module
("selftest")
33 self
._load
_module
(module_name
)
35 # Execute the module's self_test() method
36 self
.mgr_cluster
.mon_manager
.raw_cluster_cmd(
37 "mgr", "self-test", "module", module_name
)
39 def test_zabbix(self
):
40 # Set these mandatory config fields so that the zabbix module
41 # won't trigger health/log errors on load/serve.
42 self
.mgr_cluster
.set_module_conf("zabbix", "zabbix_host", "localhost")
43 self
.mgr_cluster
.set_module_conf("zabbix", "identifier", "foo")
44 self
._selftest
_plugin
("zabbix")
46 def test_prometheus(self
):
47 self
._assign
_ports
("prometheus", "server_port", min_port
=8100)
48 self
._selftest
_plugin
("prometheus")
50 def test_influx(self
):
51 self
._selftest
_plugin
("influx")
53 def test_diskprediction_local(self
):
54 self
._load
_module
("selftest")
55 python_version
= self
.mgr_cluster
.mon_manager
.raw_cluster_cmd(
56 "mgr", "self-test", "python-version")
57 if tuple(int(v
) for v
in python_version
.split('.')) == (3, 8):
58 # https://tracker.ceph.com/issues/45147
59 self
.skipTest(f
'python {python_version} not compatible with '
60 'diskprediction_local')
61 self
._selftest
_plugin
("diskprediction_local")
63 def test_telegraf(self
):
64 self
._selftest
_plugin
("telegraf")
66 def test_iostat(self
):
67 self
._selftest
_plugin
("iostat")
69 def test_devicehealth(self
):
70 self
._selftest
_plugin
("devicehealth")
72 def test_selftest_run(self
):
73 self
._load
_module
("selftest")
74 self
.mgr_cluster
.mon_manager
.raw_cluster_cmd("mgr", "self-test", "run")
76 def test_telemetry(self
):
77 self
._selftest
_plugin
("telemetry")
80 self
._selftest
_plugin
("crash")
82 def test_orchestrator(self
):
83 self
._selftest
_plugin
("orchestrator")
86 def test_selftest_config_update(self
):
88 That configuration updates are seen by running mgr modules
90 self
._load
_module
("selftest")
93 return self
.mgr_cluster
.mon_manager
.raw_cluster_cmd(
94 "mgr", "self-test", "config", "get", "testkey").strip()
96 self
.assertEqual(get_value(), "None")
97 self
.mgr_cluster
.mon_manager
.raw_cluster_cmd(
98 "config", "set", "mgr", "mgr/selftest/testkey", "foo")
99 self
.wait_until_equal(get_value
, "foo", timeout
=10)
101 def get_localized_value():
102 return self
.mgr_cluster
.mon_manager
.raw_cluster_cmd(
103 "mgr", "self-test", "config", "get_localized", "testkey").strip()
105 self
.assertEqual(get_localized_value(), "foo")
106 self
.mgr_cluster
.mon_manager
.raw_cluster_cmd(
107 "config", "set", "mgr", "mgr/selftest/{}/testkey".format(
108 self
.mgr_cluster
.get_active_id()),
110 self
.wait_until_equal(get_localized_value
, "bar", timeout
=10)
113 def test_selftest_command_spam(self
):
114 # Use the selftest module to stress the mgr daemon
115 self
._load
_module
("selftest")
117 # Use the dashboard to test that the mgr is still able to do its job
118 self
._assign
_ports
("dashboard", "ssl_server_port")
119 self
._load
_module
("dashboard")
120 self
.mgr_cluster
.mon_manager
.raw_cluster_cmd("dashboard",
121 "create-self-signed-cert")
123 original_active
= self
.mgr_cluster
.get_active_id()
124 original_standbys
= self
.mgr_cluster
.get_standby_ids()
126 self
.mgr_cluster
.mon_manager
.raw_cluster_cmd("mgr", "self-test",
127 "background", "start",
130 dashboard_uri
= self
._get
_uri
("dashboard")
134 for i
in range(0, periods
):
136 # Check that an HTTP module remains responsive
137 r
= requests
.get(dashboard_uri
, verify
=False)
138 self
.assertEqual(r
.status_code
, 200)
140 # Check that a native non-module command remains responsive
141 self
.mgr_cluster
.mon_manager
.raw_cluster_cmd("osd", "df")
143 time
.sleep(delay
- (time
.time() - t1
))
145 self
.mgr_cluster
.mon_manager
.raw_cluster_cmd("mgr", "self-test",
146 "background", "stop")
148 # Check that all mgr daemons are still running
149 self
.assertEqual(original_active
, self
.mgr_cluster
.get_active_id())
150 self
.assertEqual(original_standbys
, self
.mgr_cluster
.get_standby_ids())
152 def test_module_commands(self
):
154 That module-handled commands have appropriate behavior on
155 disabled/failed/recently-enabled modules.
158 # Calling a command on a disabled module should return the proper
160 self
._load
_module
("selftest")
161 self
.mgr_cluster
.mon_manager
.raw_cluster_cmd(
162 "mgr", "module", "disable", "selftest")
163 with self
.assertRaises(CommandFailedError
) as exc_raised
:
164 self
.mgr_cluster
.mon_manager
.raw_cluster_cmd(
165 "mgr", "self-test", "run")
167 self
.assertEqual(exc_raised
.exception
.exitstatus
, errno
.EOPNOTSUPP
)
169 # Calling a command that really doesn't exist should give me EINVAL.
170 with self
.assertRaises(CommandFailedError
) as exc_raised
:
171 self
.mgr_cluster
.mon_manager
.raw_cluster_cmd(
174 self
.assertEqual(exc_raised
.exception
.exitstatus
, errno
.EINVAL
)
176 # Enabling a module and then immediately using ones of its commands
177 # should work (#21683)
178 self
._load
_module
("selftest")
179 self
.mgr_cluster
.mon_manager
.raw_cluster_cmd(
180 "mgr", "self-test", "config", "get", "testkey")
182 # Calling a command for a failed module should return the proper
184 self
.mgr_cluster
.mon_manager
.raw_cluster_cmd(
185 "mgr", "self-test", "background", "start", "throw_exception")
186 with self
.assertRaises(CommandFailedError
) as exc_raised
:
187 self
.mgr_cluster
.mon_manager
.raw_cluster_cmd(
188 "mgr", "self-test", "run"
190 self
.assertEqual(exc_raised
.exception
.exitstatus
, errno
.EIO
)
192 # A health alert should be raised for a module that has thrown
193 # an exception from its serve() method
194 self
.wait_for_health(
195 "Module 'selftest' has failed: Synthetic exception in serve",
197 # prune the crash reports, so that the health report is back to
199 self
.mgr_cluster
.mon_manager
.raw_cluster_cmd(
200 "crash", "prune", "0")
201 self
.mgr_cluster
.mon_manager
.raw_cluster_cmd(
202 "mgr", "module", "disable", "selftest")
204 self
.wait_for_health_clear(timeout
=30)
206 def test_module_remote(self
):
208 Use the selftest module to exercise inter-module communication
210 self
._load
_module
("selftest")
211 # The "self-test remote" operation just happens to call into
213 self
._load
_module
("influx")
215 self
.mgr_cluster
.mon_manager
.raw_cluster_cmd(
216 "mgr", "self-test", "remote")
218 def test_selftest_cluster_log(self
):
220 Use the selftest module to test the cluster/audit log interface.
228 self
._load
_module
("selftest")
229 for priority
in priority_map
.keys():
230 message
= "foo bar {}".format(priority
)
231 log_message
= "[{}] {}".format(priority_map
[priority
], message
)
232 # Check for cluster/audit logs:
233 # 2018-09-24 09:37:10.977858 mgr.x [INF] foo bar info
234 # 2018-09-24 09:37:10.977860 mgr.x [SEC] foo bar security
235 # 2018-09-24 09:37:10.977863 mgr.x [WRN] foo bar warning
236 # 2018-09-24 09:37:10.977866 mgr.x [ERR] foo bar error
237 with self
.assert_cluster_log(log_message
):
238 self
.mgr_cluster
.mon_manager
.raw_cluster_cmd(
239 "mgr", "self-test", "cluster-log", "cluster",
241 with self
.assert_cluster_log(log_message
, watch_channel
="audit"):
242 self
.mgr_cluster
.mon_manager
.raw_cluster_cmd(
243 "mgr", "self-test", "cluster-log", "audit",
246 def test_selftest_cluster_log_unknown_channel(self
):
248 Use the selftest module to test the cluster/audit log interface.
250 with self
.assertRaises(CommandFailedError
) as exc_raised
:
251 self
.mgr_cluster
.mon_manager
.raw_cluster_cmd(
252 "mgr", "self-test", "cluster-log", "xyz",
253 "ERR", "The channel does not exist")
254 self
.assertEqual(exc_raised
.exception
.exitstatus
, errno
.EOPNOTSUPP
)