From f6d028dfa0c24d43c33670f1bb4547a6310963ea Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Wed, 8 Apr 2020 20:21:25 +0800 Subject: [PATCH] mgr/telegraf: catch FileNotFoundError exception 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 --- qa/suites/rados/mgr/tasks/module_selftest.yaml | 1 + src/pybind/mgr/telegraf/module.py | 10 ++++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/qa/suites/rados/mgr/tasks/module_selftest.yaml b/qa/suites/rados/mgr/tasks/module_selftest.yaml index 17fa6b395c69f..9fa956b7e8c2e 100644 --- a/qa/suites/rados/mgr/tasks/module_selftest.yaml +++ b/qa/suites/rados/mgr/tasks/module_selftest.yaml @@ -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 diff --git a/src/pybind/mgr/telegraf/module.py b/src/pybind/mgr/telegraf/module.py index 8283dc0a5b123..8264fdf325730 100644 --- a/src/pybind/mgr/telegraf/module.py +++ b/src/pybind/mgr/telegraf/module.py @@ -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') -- 2.39.5