From cccef1838baf26795bbfba914d30243cca704707 Mon Sep 17 00:00:00 2001 From: "Bryn M. Reeves" Date: Wed, 16 Apr 2014 21:28:27 +0100 Subject: Handle fatal file system errors in SoSReport.*report() Out-of-space and read-only file system errors while writing the XML, plain-text, or HTML reports should be treated as fatal and cause the run to end. Partial fix for Issue #266. Signed-off-by: Bryn M. Reeves --- sos/sosreport.py | 40 ++++++++++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/sos/sosreport.py b/sos/sosreport.py index 6b5220d2..9b068a90 100644 --- a/sos/sosreport.py +++ b/sos/sosreport.py @@ -1001,8 +1001,15 @@ class SoSReport(object): except: pass - self.xml_report.serialize_to_file( - os.path.join(self.rptdir, "sosreport.xml")) + try: + self.xml_report.serialize_to_file(os.path.join(self.rptdir, "sosreport.xml")) + except OSError as e: + if e.errno in fatal_fs_errors: + self.ui_log.error("") + self.ui_log.error(" %s while writing report data" + % e.strerror) + self.ui_log.error(" %s" % e.filename) + self._exit(1) def plain_report(self): @@ -1029,14 +1036,31 @@ class SoSReport(object): section.add(CreatedFile(name=f)) report.add(section) - - fd = self.get_temp_file() - fd.write(str(PlainTextReport(report))) - fd.flush() - self.archive.add_file(fd.name, dest=os.path.join('sos_reports', 'sos.txt')) - + try: + fd = self.get_temp_file() + fd.write(str(PlainTextReport(report))) + fd.flush() + self.archive.add_file(fd.name, dest=os.path.join('sos_reports', 'sos.txt')) + except OSError as e: + if e.errno in fatal_fs_errors: + self.ui_log.error("") + self.ui_log.error(" %s while writing text report" + % e.strerror) + self.ui_log.error(" %s" % e.filename) + self._exit(1) def html_report(self): + try: + self._html_report() + except OSError as e: + if e.errno in fatal_fs_errors: + self.ui_log.error("") + self.ui_log.error(" %s while writing HTML report" + % e.strerror) + self.ui_log.error(" %s" % e.filename) + self._exit(1) + + def _html_report(self): # Generate the header for the html output file rfd = self.get_temp_file() rfd.write(""" -- cgit