]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/telegraf: catch FileNotFoundError exception 34264/head
authorKefu Chai <kchai@redhat.com>
Wed, 8 Apr 2020 12:21:25 +0000 (20:21 +0800)
committerKefu Chai <kchai@redhat.com>
Wed, 8 Apr 2020 13:07:07 +0000 (21:07 +0800)
in tasks/module_selftest.yaml, `TestModuleSelftest.test_telegraf()` is
called. but we fail to prepare a unix domain socket to which the telegraf
module can send stats. and telegraf module does not catch
FileNotFoundError exception, so the exception is populated to ceph-mgr
and is found by the test, hence the test is marked a failure whenever
telegraf is tested.

in this change,

* catch this exception, so it won't be caught by ceph-mgr
* whitelist the error message, so the test can pass

Signed-off-by: Kefu Chai <kchai@redhat.com>
qa/suites/rados/mgr/tasks/module_selftest.yaml
src/pybind/mgr/telegraf/module.py

index 17fa6b395c69fd08b21b089a8bc213a2c760a716..9fa956b7e8c2ed4cd9f94a9d7de27ba53f443db4 100644 (file)
@@ -18,6 +18,7 @@ tasks:
         - influxdb python module not found
         - \(MGR_ZABBIX_
         - foo bar
+        - Failed to open Telegraf
   - cephfs_test_runner:
       modules:
         - tasks.mgr.test_module_selftest
index 8283dc0a5b1232a803838b4ec9269daa141210f5..8264fdf32573075afd02c5f0016e03b90cdb651e 100644 (file)
@@ -240,8 +240,8 @@ class Module(MgrModule):
         sock = BaseSocket(url)
         self.log.debug('Sending data to Telegraf at %s', sock.address)
         now = self.now()
-        with sock as s:
-            try:
+        try:
+            with sock as s:
                 for measurement in self.gather_measurements():
                     self.log.debug(measurement)
                     line = Line(measurement['measurement'],
@@ -249,8 +249,10 @@ class Module(MgrModule):
                                 measurement['tags'], now)
                     self.log.debug(line.to_line_protocol())
                     s.send(line.to_line_protocol())
-            except (socket.error, RuntimeError, IOError, OSError):
-                self.log.exception('Failed to send statistics to Telegraf:')
+        except (socket.error, RuntimeError, IOError, OSError):
+            self.log.exception('Failed to send statistics to Telegraf:')
+        except FileNotFoundError:
+            self.log.exception('Failed to open Telegraf at: %s', url.geturl())
 
     def shutdown(self):
         self.log.info('Stopping Telegraf module')