Move Audit-template management in DefaultStrategyContext
This aim of this patchset is to move the management of the Audit-Template into StrategyContext in order to prepare to pass parameters to strategies but also to prepare to add more dynamic Actions management Partially implements: blueprint glossary-related-refactoring Change-Id: I13ee063da947113ce349855aa331a22f40567051
This commit is contained in:
@@ -14,55 +14,51 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
import mock
|
||||
from mock import MagicMock
|
||||
|
||||
from watcher.common import utils
|
||||
from watcher.decision_engine.audit.default import DefaultAuditHandler
|
||||
from watcher.decision_engine.messaging.audit_endpoint import AuditEndpoint
|
||||
from watcher.metrics_engine.cluster_model_collector.manager import \
|
||||
CollectorManager
|
||||
from watcher.tests import base
|
||||
from watcher.tests.db.base import DbTestCase
|
||||
from watcher.tests.decision_engine.strategy.strategies.faker_cluster_state \
|
||||
import FakerModelCollector
|
||||
from watcher.tests.objects import utils as obj_utils
|
||||
|
||||
|
||||
class DefaultAuditHandlerMock(DefaultAuditHandler):
|
||||
def setUp(self):
|
||||
super(DefaultAuditHandlerMock, self).setUp()
|
||||
|
||||
def executor(self):
|
||||
pass
|
||||
|
||||
|
||||
class TestAuditEndpoint(base.TestCase):
|
||||
class TestAuditEndpoint(DbTestCase):
|
||||
def setUp(self):
|
||||
super(TestAuditEndpoint, self).setUp()
|
||||
self.audit_template = obj_utils.create_test_audit_template(
|
||||
self.context)
|
||||
self.audit = obj_utils.create_test_audit(
|
||||
self.context,
|
||||
audit_template_id=self.audit_template.id)
|
||||
|
||||
def test_do_trigger_audit(self):
|
||||
@mock.patch.object(CollectorManager, "get_cluster_model_collector")
|
||||
def test_do_trigger_audit(self, mock_collector):
|
||||
mock_collector.return_value = FakerModelCollector()
|
||||
audit_uuid = utils.generate_uuid()
|
||||
model_collector = FakerModelCollector()
|
||||
audit_handler = DefaultAuditHandler(MagicMock(), model_collector)
|
||||
|
||||
audit_handler = DefaultAuditHandler(mock.MagicMock())
|
||||
endpoint = AuditEndpoint(audit_handler, max_workers=2)
|
||||
|
||||
with mock.patch.object(CollectorManager, 'get_cluster_model_collector') \
|
||||
as mock_call2:
|
||||
mock_call2.return_value = 0
|
||||
with mock.patch.object(DefaultAuditHandler, 'execute') as mock_call:
|
||||
mock_call.return_value = 0
|
||||
endpoint.do_trigger_audit(audit_handler, audit_uuid)
|
||||
|
||||
with mock.patch.object(DefaultAuditHandler, 'execute') \
|
||||
as mock_call:
|
||||
mock_call.return_value = 0
|
||||
endpoint.do_trigger_audit(audit_handler, audit_uuid)
|
||||
# mock_call.assert_called_once_with()
|
||||
mock_call2.assert_called_once_with()
|
||||
mock_call.assert_called_once_with(audit_uuid, audit_handler)
|
||||
|
||||
def test_trigger_audit(self):
|
||||
@mock.patch.object(CollectorManager, "get_cluster_model_collector")
|
||||
def test_trigger_audit(self, mock_collector):
|
||||
mock_collector.return_value = FakerModelCollector()
|
||||
audit_uuid = utils.generate_uuid()
|
||||
model_collector = FakerModelCollector()
|
||||
audit_handler = DefaultAuditHandlerMock(MagicMock(),
|
||||
model_collector)
|
||||
audit_handler = DefaultAuditHandler(mock.MagicMock())
|
||||
endpoint = AuditEndpoint(audit_handler, max_workers=2)
|
||||
|
||||
with mock.patch.object(DefaultAuditHandlerMock, 'executor') \
|
||||
with mock.patch.object(DefaultAuditHandler, 'execute') \
|
||||
as mock_call:
|
||||
mock_call.return_value = 0
|
||||
endpoint.trigger_audit(audit_handler, audit_uuid)
|
||||
|
||||
mock_call.assert_called_once_with(audit_uuid, audit_handler)
|
||||
|
||||
Reference in New Issue
Block a user