fix configparser import & log if error was raised

This commit is contained in:
Arount 2017-06-30 15:28:52 +02:00 committed by Loren Gordon
parent ca1b1bb633
commit d7f65dc7a7

View file

@ -35,8 +35,10 @@ try:
import yum
HAS_YUM = True
except ImportError:
from salt.ext.six.moves import configparser
HAS_YUM = False
from salt.ext.six.moves import configparser
# pylint: enable=import-error,redefined-builtin
# Import salt libs
@ -2525,9 +2527,16 @@ def _parse_repo_file(filename):
Turn a single repo file into a dict
'''
parsed = configparser.ConfigParser()
parsed.read(filename)
config = {}
try:
parsed.read(filename)
except configparser.MissingSectionHeaderError as err:
log.error(
'Failed to parser file {0}, error: {1}'.format(filename, err.message)
)
return ('', {})
for section in parsed._sections:
section_dict = dict(parsed._sections[section])
section_dict.pop('__name__')