Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[For github action testing purposes only] Check answerfile upon loading #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 24 additions & 4 deletions leapp/messaging/answerstore.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import six
from six.moves import configparser

from leapp.exceptions import CommandError
from leapp.utils.audit import create_audit_entry


Expand Down Expand Up @@ -50,15 +51,34 @@ def update(self, answer_file, allow_missing=False):
conf.write(afile)
return not_updated


def _load_ini(self, inifile):
"""
Loads an ini config file from the given location.

:param inifile: Path to the answer file to load.
:return: configparser.SafeConfigParser object
:raises CommandError if any of the values are not in key=value format
"""
conf = configparser.SafeConfigParser(allow_no_value=False)
try:
conf.read(inifile)
return conf
except configparser.ParsingError as exc:
# Some of the sections were not in key = value format
raise CommandError('Failed to load answer file {inifile} with the following errors: {errors}'.format(
inifile=inifile, errors=exc.message))


def load(self, answer_file):
"""
Loads an answer file from the given location and updates the loaded data with it.

:param answer_file: Path to the answer file to load.
:return: None
:raises CommandError if any of the values are not in key=value format
"""
conf = configparser.SafeConfigParser(allow_no_value=True)
conf.read(answer_file)
conf = self._load_ini(answer_file)
for section in conf.sections():
self._storage[section] = self._manager.dict(conf.items(section=section, raw=True))

Expand All @@ -70,9 +90,9 @@ def load_and_translate_for_workflow(self, answer_file, workflow):
:param answer_file: Path to the answer file to load.
:param workflow:
:return: None
:raises CommandError if any of the values are not in key=value format
"""
conf = configparser.SafeConfigParser(allow_no_value=True)
conf.read(answer_file)
conf = self._load_ini(answer_file)
for section in conf.sections():
self._storage[section] = dict(conf.items(section=section, raw=True))
self.translate_for_workflow(workflow)
Expand Down