Print the traceback if there was an exception in run()

In case run() method fails, all we get is a terse "Unable to run Guru
Meditation Report!" message on stderr.

This patch also prints the traceback for easier debugging in the
unlikely event that GMR fails.

Change-Id: I99d4e0f1ed3ea608aa285f34314339b0939c5651
This commit is contained in:
Nikola Dipanov 2015-12-18 23:47:01 +00:00
parent 6681a45b6a
commit ebc7a844ad
2 changed files with 15 additions and 0 deletions

View File

@ -64,6 +64,7 @@ import logging
import os
import signal
import sys
import traceback
from oslo_utils import timeutils
@ -178,6 +179,7 @@ class GuruMeditation(object):
try:
res = cls(version, frame).run()
except Exception:
traceback.print_exc(file=sys.stderr)
print("Unable to run Guru Meditation Report!",
file=sys.stderr)
else:

View File

@ -180,6 +180,19 @@ class TestGuruMeditationReport(base.BaseTestCase):
log_dir, "fake-service_gurumeditation_20140101120000")) as df:
self.assertIn('Guru Meditation', df.read())
@mock.patch.object(gmr.TextGuruMeditation, 'run')
def test_fail_prints_traceback(self, run_mock):
class RunFail(Exception):
pass
run_mock.side_effect = RunFail()
gmr.TextGuruMeditation.setup_autorun(FakeVersionObj())
self.old_stderr = sys.stderr
sys.stderr = six.StringIO()
os.kill(os.getpid(), signal.SIGUSR2)
self.assertIn('RunFail', sys.stderr.getvalue())
def tearDown(self):
super(TestGuruMeditationReport, self).tearDown()
if self.old_stderr is not None: