]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/telemetry: catch exception during requests.put
authorSage Weil <sage@redhat.com>
Tue, 4 Feb 2020 18:59:32 +0000 (12:59 -0600)
committerSage Weil <sage@redhat.com>
Tue, 4 Feb 2020 18:59:32 +0000 (12:59 -0600)
Sometimes requests.put throws an exception.  When that happens, generate
an appropriate error but don't crash the module.

Fixes: https://tracker.ceph.com/issues/43963
Signed-off-by: Sage Weil <sage@redhat.com>
src/pybind/mgr/telemetry/module.py

index 97b353538931373aac7ad1244019793e6f7058c6..ae3454e29489a96f1a8408845d1e7931894e73a3 100644 (file)
@@ -673,16 +673,23 @@ class Module(MgrModule):
         for e in endpoint:
             if e == 'ceph':
                 self.log.info('Sending ceph report to: %s', self.url)
-                resp = requests.put(url=self.url, json=report, proxies=proxies)
-                if not resp.ok:
-                    self.log.error("Report send failed: %d %s %s" %
-                                   (resp.status_code, resp.reason, resp.text))
-                    failed.append('Failed to send report to %s: %d %s %s' % (
-                        self.url,
-                        resp.status_code,
-                        resp.reason,
-                        resp.text
-                    ))
+                fail_reason = None
+                try:
+                    resp = requests.put(url=self.url, json=report,
+                                        proxies=proxies)
+                    if not resp.ok:
+                        fail_reason = 'Failed to send report to %s: %d %s %s' % (
+                            self.url,
+                            resp.status_code,
+                            resp.reason,
+                            resp.text
+                        )
+                except Exception as e:
+                    fail_reason = 'Failed to send report to %s: %s' % (
+                        self.url, str(e))
+                if fail_reason:
+                    self.log.error(fail_reason)
+                    failed.append(fail_reason)
                 else:
                     now = int(time.time())
                     self.last_upload = now