From bda26fe0e707ec9e609be613805340dadd17e8f3 Mon Sep 17 00:00:00 2001 From: John Spray Date: Tue, 12 Sep 2017 06:51:21 -0400 Subject: [PATCH] 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) --- src/pybind/mgr/influx/module.py | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/src/pybind/mgr/influx/module.py b/src/pybind/mgr/influx/module.py index 912b581388d8c..7268394425b4d 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() -- 2.39.5