]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/influx: enable self-test without dependencies
authorJohn Spray <john.spray@redhat.com>
Tue, 12 Sep 2017 10:51:21 +0000 (06:51 -0400)
committerJohn Spray <john.spray@redhat.com>
Wed, 1 Nov 2017 23:03:25 +0000 (23:03 +0000)
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 <john.spray@redhat.com>
(cherry picked from commit 125294ab9d6e99aa4c960fea147a4e86624b869e)

src/pybind/mgr/influx/module.py

index 912b581388d8ce7849b9d71a44bf63e60267d10f..7268394425b4db94b0c0340f0b849528718c21d5 100644 (file)
@@ -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()