aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAbhijeet Kasurde <akasurde@redhat.com>2016-01-21 13:06:56 +0530
committerBryn M. Reeves <bmr@redhat.com>2016-02-05 16:20:04 +0000
commit8ef27fa80589fcda452fc1c27c1fc6a0fb385b4a (patch)
tree7a208fcc5de84c498f985d3d8eaf50099b385910
parenta30a4181d85985d2d7bbb4e4d31cf2b857954643 (diff)
downloadsos-8ef27fa80589fcda452fc1c27c1fc6a0fb385b4a.tar.gz
[sosreport] Added error handling in Config Parsing
Closes: #739. Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
-rw-r--r--sos/sosreport.py17
1 files changed, 12 insertions, 5 deletions
diff --git a/sos/sosreport.py b/sos/sosreport.py
index f61ea4a4..f2f30ae8 100644
--- a/sos/sosreport.py
+++ b/sos/sosreport.py
@@ -49,9 +49,9 @@ from six.moves import zip, input
from six import print_
if six.PY3:
- from configparser import ConfigParser
+ from configparser import ConfigParser, ParsingError, Error
else:
- from ConfigParser import ConfigParser
+ from ConfigParser import ConfigParser, ParsingError, Error
# file system errors that should terminate a run
fatal_fs_errors = (errno.ENOSPC, errno.EROFS)
@@ -817,10 +817,17 @@ class SoSReport(object):
config_file = self.opts.config_file
else:
config_file = '/etc/sos.conf'
+
try:
- self.config.readfp(open(config_file))
- except IOError:
- pass
+ try:
+ with open(config_file) as f:
+ self.config.readfp(f)
+ except (ParsingError, Error) as e:
+ raise exit('Failed to parse configuration '
+ 'file %s' % config_file)
+ except (OSError, IOError) as e:
+ raise exit('Unable to read configuration file %s '
+ ': %s' % (config_file, e.args[1]))
def _setup_logging(self):
# main soslog