From aef7a3dab112690e5172d137decb93dc28056471 Mon Sep 17 00:00:00 2001 From: Joe Cropper Date: Fri, 4 Mar 2016 15:22:30 -0600 Subject: [PATCH] Dump metric exception text to logs This patch simply adds the exception text to the logs so that we don't lose the troubleshooting data. Without this patch, it's much more difficult to troubleshoot when something goes wrong as the root exception text is garbled up and lost. Change-Id: Ib432fddc9b31fb6f906f6828d52098c9dd059aa2 Closes-Bug: 1553319 --- nova/compute/resource_tracker.py | 6 ++++-- nova/tests/unit/compute/test_resource_tracker.py | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/nova/compute/resource_tracker.py b/nova/compute/resource_tracker.py index f0089ccdb2b6..c1345dbdac9d 100644 --- a/nova/compute/resource_tracker.py +++ b/nova/compute/resource_tracker.py @@ -465,8 +465,10 @@ class ResourceTracker(object): for monitor in self.monitors: try: monitor.add_metrics_to_list(metrics) - except Exception: - LOG.warning(_LW("Cannot get the metrics from %s."), monitor) + except Exception as exc: + LOG.warning(_LW("Cannot get the metrics from %(mon)s; " + "error: %(exc)s"), + {'mon': monitor, 'exc': exc}) # TODO(jaypipes): Remove this when compute_node.metrics doesn't need # to be populated as a JSON-ified string. metrics = metrics.to_list() diff --git a/nova/tests/unit/compute/test_resource_tracker.py b/nova/tests/unit/compute/test_resource_tracker.py index c2a0ab65d9d2..5d668fe078ef 100644 --- a/nova/tests/unit/compute/test_resource_tracker.py +++ b/nova/tests/unit/compute/test_resource_tracker.py @@ -1211,7 +1211,7 @@ class ComputeMonitorTestCase(BaseTestCase): metrics = self.tracker._get_host_metrics(self.context, self.node_name) mock_LOG_warning.assert_called_once_with( - u'Cannot get the metrics from %s.', mock.ANY) + u'Cannot get the metrics from %(mon)s; error: %(exc)s', mock.ANY) self.assertEqual(0, len(metrics)) def test_get_host_metrics(self):