diff --git a/leapp/actors/__init__.py b/leapp/actors/__init__.py index 0aec4699..2ea98354 100644 --- a/leapp/actors/__init__.py +++ b/leapp/actors/__init__.py @@ -29,8 +29,6 @@ def validate(cls, value): return value in cls.ALLOWED_VALUES - - class Actor(object): """ The Actor class represents the smallest step in the workflow. It defines what kind @@ -146,7 +144,7 @@ def get_answers(self, dialog): else: answer = self._messaging.request_answers(dialog) - _store_dialog(dialog, answer) + _store_dialog_db(dialog, answer) return answer @@ -504,9 +502,7 @@ def get_actors(): return actors -def _store_dialog(dialog, answer): - # NOTE(dkubek): Should an audit entry be created? One audit entry is - # created when store.get(...) is called +def _store_dialog_db(dialog, answer): component_keys = ('key', 'label', 'description', 'default', 'value', 'reason') dialog_keys = ('title', 'reason', 'scope') @@ -514,19 +510,18 @@ def _store_dialog(dialog, answer): data = { 'components': [dict((key, component[key]) for key in component_keys) for component in data['components']], **dict((key, data[key]) for key in dialog_keys), - # NOTE(dkubek): Storing answer here is a bit redundant as it is already + + # NOTE(dkubek): Storing answer here is redundant as it is already # being stored in audit when we query from the answerstore, however, # this keeps the information coupled with the question more closely - 'answer': - answer + 'answer': answer } - md = DialogDB( + DialogDB( scope=dialog.scope, data=data, context=os.environ['LEAPP_EXECUTION_ID'], actor=os.environ['LEAPP_CURRENT_ACTOR'], phase=os.environ['LEAPP_CURRENT_PHASE'], hostname=os.environ['LEAPP_HOSTNAME'], - ) - md.store() + ).store() diff --git a/leapp/messaging/answerstore.py b/leapp/messaging/answerstore.py index 3e55e8ae..b2c707dc 100644 --- a/leapp/messaging/answerstore.py +++ b/leapp/messaging/answerstore.py @@ -117,6 +117,9 @@ def get(self, scope, fallback=None): # NOTE(ivasilev) self.storage.get() will return a DictProxy. To avoid TypeError during later # JSON serialization a copy() should be invoked to get a shallow copy of data answer = self._storage.get(scope, fallback).copy() + + # NOTE(dkubek): It is possible that we do not need to save the 'answer' + # here as it is being stored with dialog question right after query create_audit_entry('dialog-answer', {'scope': scope, 'fallback': fallback, 'answer': answer}) return answer diff --git a/leapp/utils/audit/__init__.py b/leapp/utils/audit/__init__.py index e3ec957e..7733ec4e 100644 --- a/leapp/utils/audit/__init__.py +++ b/leapp/utils/audit/__init__.py @@ -311,6 +311,9 @@ def do_store(self, connection): class Dialog(DataSource): + """ + Stores information about dialog questions and their answers + """ def __init__(self, scope=None, data=None, actor=None, phase=None, hostname=None, context=None): """ @@ -320,12 +323,12 @@ def __init__(self, scope=None, data=None, actor=None, phase=None, hostname=None, :type data: dict :param actor: Name of the actor that triggered the entry :type actor: str - :param phase: In which phase of the workflow execution the message was created + :param phase: In which phase of the workflow execution the dialog was triggered :type phase: str - :param context: The execution context - :type context: str :param hostname: Hostname of the system that produced the message :type hostname: str + :param context: The execution context + :type context: str """ super(Dialog, self).__init__(actor=actor, phase=phase, hostname=hostname, context=context) self.scope = scope or ''