From: John Spray Date: Tue, 12 Sep 2017 10:51:21 +0000 (-0400) Subject: mgr/influx: enable self-test without dependencies X-Git-Tag: v12.2.2~61^2~60 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=bda26fe0e707ec9e609be613805340dadd17e8f3;p=ceph.git mgr/influx: enable self-test without dependencies The idea of self-test commands is that they're self contained and just exercise the module's calls to the Ceph-side. Signed-off-by: John Spray (cherry picked from commit 125294ab9d6e99aa4c960fea147a4e86624b869e) --- diff --git a/src/pybind/mgr/influx/module.py b/src/pybind/mgr/influx/module.py index 912b581388d8..7268394425b4 100644 --- a/src/pybind/mgr/influx/module.py +++ b/src/pybind/mgr/influx/module.py @@ -2,10 +2,17 @@ from datetime import datetime from threading import Event from ConfigParser import SafeConfigParser -from influxdb import InfluxDBClient +import json +import errno + from mgr_module import MgrModule from mgr_module import PERFCOUNTER_HISTOGRAM +try: + from influxdb import InfluxDBClient +except ImportError: + InfluxDBClient = None + class Module(MgrModule): COMMANDS = [ { @@ -128,13 +135,24 @@ class Module(MgrModule): def handle_command(self, cmd): if cmd['prefix'] == 'influx self-test': - self.send_to_influx() - return 0,' ', 'debugging module' + daemon_stats = self.get_daemon_stats() + assert len(daemon_stats) + df_stats = self.get_df_stats() + result = { + 'daemon_stats': daemon_stats, + 'df_stats': df_stats + } + return 0, json.dumps(result, indent=2), 'Self-test OK' else: - print('not found') - raise NotImplementedError(cmd['prefix']) + return (-errno.EINVAL, '', + "Command not found '{0}'".format(cmd['prefix'])) def serve(self): + if InfluxDBClient is None: + self.log.error("Cannot transmit statistics: influxdb python " + "module not found. Did you install it?") + return + self.log.info('Starting influx module') self.run = True config = SafeConfigParser()