Coverage for watcher/decision_engine/messaging/audit_endpoint.py: 91%
29 statements
« prev ^ index » next coverage.py v7.8.2, created at 2025-06-17 12:22 +0000
« prev ^ index » next coverage.py v7.8.2, created at 2025-06-17 12:22 +0000
1# -*- encoding: utf-8 -*-
2# Copyright (c) 2015 b<>com
3#
4# Authors: Jean-Emile DARTOIS <jean-emile.dartois@b-com.com>
5#
6# Licensed under the Apache License, Version 2.0 (the "License");
7# you may not use this file except in compliance with the License.
8# You may obtain a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS,
14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
15# implied.
16# See the License for the specific language governing permissions and
17# limitations under the License.
18#
19import futurist
21from oslo_config import cfg
22from oslo_log import log
24from watcher.decision_engine.audit import continuous as c_handler
25from watcher.decision_engine.audit import event as e_handler
26from watcher.decision_engine.audit import oneshot as o_handler
28from watcher import objects
30CONF = cfg.CONF
31LOG = log.getLogger(__name__)
34class AuditEndpoint(object):
36 def __init__(self, messaging):
37 self._messaging = messaging
38 self._executor = futurist.GreenThreadPoolExecutor(
39 max_workers=CONF.watcher_decision_engine.max_audit_workers)
40 self._oneshot_handler = o_handler.OneShotAuditHandler()
41 self._continuous_handler = c_handler.ContinuousAuditHandler().start()
42 self._event_handler = e_handler.EventAuditHandler()
44 @property
45 def executor(self):
46 return self._executor
48 def do_trigger_audit(self, context, audit_uuid):
49 audit = objects.Audit.get_by_uuid(context, audit_uuid, eager=True)
50 if audit.audit_type == objects.audit.AuditType.ONESHOT.value: 50 ↛ 52line 50 didn't jump to line 52 because the condition on line 50 was always true
51 self._oneshot_handler.execute(audit, context)
52 if audit.audit_type == objects.audit.AuditType.EVENT.value: 52 ↛ 53line 52 didn't jump to line 53 because the condition on line 52 was never true
53 self._event_handler.execute(audit, context)
55 def trigger_audit(self, context, audit_uuid):
56 LOG.debug("Trigger audit %s", audit_uuid)
57 self.executor.submit(self.do_trigger_audit,
58 context,
59 audit_uuid)
60 return audit_uuid