prevent exception when test=True

This commit is contained in:
nicholasmhughes 2017-09-25 11:11:23 -04:00
parent cfe37916c3
commit d68c5c4be0

View file

@ -368,15 +368,16 @@ class _Ini(_Section):
super(_Ini, self).__init__(name, inicontents, separator, commenter)
def refresh(self, inicontents=None):
if inicontents is None and __opts__['test'] is False:
if inicontents is None:
try:
with salt.utils.fopen(self.name) as rfh:
inicontents = rfh.read()
except (OSError, IOError) as exc:
raise CommandExecutionError(
"Unable to open file '{0}'. "
"Exception: {1}".format(self.name, exc)
)
if __opts__['test'] is False:
raise CommandExecutionError(
"Unable to open file '{0}'. "
"Exception: {1}".format(self.name, exc)
)
if not inicontents:
return
# Remove anything left behind from a previous run.