From ad1593bb364a44e7c45ec9bf5bc0bdd31ae21c85 Mon Sep 17 00:00:00 2001 From: Egor Panfilov Date: Sun, 22 Apr 2018 17:17:53 +0300 Subject: [PATCH] Moved do_execute method to AuditHandler class Both Continuous and Oneshot audits made same action in do_execute, so it's a good idea to move it to the base class TrivialFix Change-Id: Ic0353f010509ce45f94126e4db0e629417128ded --- watcher/decision_engine/audit/base.py | 7 +++++++ watcher/decision_engine/audit/continuous.py | 5 ++--- watcher/decision_engine/audit/oneshot.py | 7 ------- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/watcher/decision_engine/audit/base.py b/watcher/decision_engine/audit/base.py index 11ad80e06..9b5ad3c43 100644 --- a/watcher/decision_engine/audit/base.py +++ b/watcher/decision_engine/audit/base.py @@ -74,6 +74,13 @@ class AuditHandler(BaseAuditHandler): def strategy_context(self): return self._strategy_context + def do_execute(self, audit, request_context): + # execute the strategy + solution = self.strategy_context.execute_strategy( + audit, request_context) + + return solution + def do_schedule(self, request_context, audit, solution): try: notifications.audit.send_action_notification( diff --git a/watcher/decision_engine/audit/continuous.py b/watcher/decision_engine/audit/continuous.py index 9272ac4b7..aa5a34fcf 100644 --- a/watcher/decision_engine/audit/continuous.py +++ b/watcher/decision_engine/audit/continuous.py @@ -71,9 +71,8 @@ class ContinuousAuditHandler(base.AuditHandler): return False def do_execute(self, audit, request_context): - # execute the strategy - solution = self.strategy_context.execute_strategy( - audit, request_context) + solution = super(ContinuousAuditHandler, self)\ + .do_execute(audit, request_context) if audit.audit_type == objects.audit.AuditType.CONTINUOUS.value: a_plan_filters = {'audit_uuid': audit.uuid, diff --git a/watcher/decision_engine/audit/oneshot.py b/watcher/decision_engine/audit/oneshot.py index fae2512d4..a3628be33 100644 --- a/watcher/decision_engine/audit/oneshot.py +++ b/watcher/decision_engine/audit/oneshot.py @@ -20,13 +20,6 @@ from watcher import objects class OneShotAuditHandler(base.AuditHandler): - def do_execute(self, audit, request_context): - # execute the strategy - solution = self.strategy_context.execute_strategy( - audit, request_context) - - return solution - def post_execute(self, audit, solution, request_context): super(OneShotAuditHandler, self).post_execute(audit, solution, request_context)