import random
import json
import errno
+import six
class Module(MgrModule):
"desc": "Run another module's self_test() method",
"perm": "rw"
},
+ {
+ "cmd": "mgr self-test health set name=checks,type=CephString",
+ "desc": "Set a health check from a JSON-formatted description.",
+ "perm": "rw"
+ },
+ {
+ "cmd": "mgr self-test health clear name=checks,type=CephString,n=N,req=False",
+ "desc": "Clear health checks by name. If no names provided, clear all.",
+ "perm": "rw"
+ },
]
def __init__(self, *args, **kwargs):
super(Module, self).__init__(*args, **kwargs)
self._event = threading.Event()
self._workload = None
+ self._health = {}
def handle_command(self, inbuf, command):
if command['prefix'] == 'mgr self-test run':
return -1, '', "Test failed: {0}".format(e.message)
else:
return 0, str(r), "Self-test OK"
+ elif command['prefix'] == 'mgr self-test health set':
+ return self._health_set(inbuf, command)
+ elif command['prefix'] == 'mgr self-test health clear':
+ return self._health_clear(inbuf, command)
else:
return (-errno.EINVAL, '',
"Command not found '{0}'".format(command['prefix']))
+ def _health_set(self, inbuf, command):
+ try:
+ checks = json.loads(command["checks"])
+ except Exception as e:
+ return -1, "", "Failed to decode JSON input: {}".format(e.message)
+
+ try:
+ for check, info in six.iteritems(checks):
+ self._health[check] = {
+ "severity": str(info["severity"]),
+ "summary": str(info["summary"]),
+ "detail": [str(m) for m in info["detail"]]
+ }
+ except Exception as e:
+ return -1, "", "Invalid health check format: {}".format(e.message)
+
+ self.set_health_checks(self._health)
+ return 0, "", ""
+
+ def _health_clear(self, inbuf, command):
+ if "checks" in command:
+ for check in command["checks"]:
+ if check in self._health:
+ del self._health[check]
+ else:
+ self._health = dict()
+
+ self.set_health_checks(self._health)
+ return 0, "", ""
+
def _self_test(self):
self.log.info("Running self-test procedure...")