Remove stale notification code
In this changeset, I cleaned up the Watcher codebase to remove the old notification mechanism that is actually unused. Partially Implements: blueprint watcher-notifications-ovo Change-Id: I1901e65f031441b98a7d6f6c9c1c0364eaaaf481
This commit is contained in:
@@ -19,7 +19,6 @@
|
||||
import mock
|
||||
|
||||
from watcher.applier.action_plan import default
|
||||
from watcher.applier.messaging import event_types as ev
|
||||
from watcher.objects import action_plan as ap_objects
|
||||
from watcher.tests.db import base
|
||||
from watcher.tests.objects import utils as obj_utils
|
||||
@@ -41,20 +40,3 @@ class TestDefaultActionPlanHandler(base.DbTestCase):
|
||||
action_plan = ap_objects.ActionPlan.get_by_uuid(
|
||||
self.context, self.action_plan.uuid)
|
||||
self.assertEqual(ap_objects.State.SUCCEEDED, action_plan.state)
|
||||
|
||||
def test_trigger_audit_send_notification(self):
|
||||
messaging = mock.MagicMock()
|
||||
command = default.DefaultActionPlanHandler(
|
||||
self.context, messaging, self.action_plan.uuid)
|
||||
command.execute()
|
||||
|
||||
call_on_going = mock.call(ev.EventTypes.LAUNCH_ACTION_PLAN.name, {
|
||||
'action_plan_state': ap_objects.State.ONGOING,
|
||||
'action_plan__uuid': self.action_plan.uuid})
|
||||
call_succeeded = mock.call(ev.EventTypes.LAUNCH_ACTION_PLAN.name, {
|
||||
'action_plan_state': ap_objects.State.SUCCEEDED,
|
||||
'action_plan__uuid': self.action_plan.uuid})
|
||||
|
||||
calls = [call_on_going, call_succeeded]
|
||||
messaging.publish_status_event.assert_has_calls(calls)
|
||||
self.assertEqual(2, messaging.publish_status_event.call_count)
|
||||
|
||||
@@ -19,8 +19,8 @@
|
||||
|
||||
import mock
|
||||
|
||||
import oslo_messaging as om
|
||||
from watcher.applier import manager as applier_manager
|
||||
from watcher.common.messaging import messaging_handler
|
||||
from watcher.common import service
|
||||
from watcher.tests import base
|
||||
|
||||
@@ -30,8 +30,8 @@ class TestApplierManager(base.TestCase):
|
||||
super(TestApplierManager, self).setUp()
|
||||
self.applier = service.Service(applier_manager.ApplierManager)
|
||||
|
||||
@mock.patch.object(messaging_handler.MessagingHandler, "stop")
|
||||
@mock.patch.object(messaging_handler.MessagingHandler, "start")
|
||||
@mock.patch.object(om.rpc.server.RPCServer, "stop")
|
||||
@mock.patch.object(om.rpc.server.RPCServer, "start")
|
||||
def test_start(self, m_messaging_start, m_messaging_stop):
|
||||
self.applier.start()
|
||||
self.applier.stop()
|
||||
|
||||
@@ -27,14 +27,11 @@ from watcher.tests import base
|
||||
|
||||
|
||||
class TestApplierAPI(base.TestCase):
|
||||
def setUp(self):
|
||||
super(TestApplierAPI, self).setUp()
|
||||
|
||||
api = rpcapi.ApplierAPI()
|
||||
|
||||
def test_get_version(self):
|
||||
expected_version = self.api.API_VERSION
|
||||
self.assertEqual(expected_version, self.api.get_version())
|
||||
def setUp(self):
|
||||
super(TestApplierAPI, self).setUp()
|
||||
|
||||
def test_get_api_version(self):
|
||||
with mock.patch.object(om.RPCClient, 'call') as mock_call:
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
__author__ = 'bcom'
|
||||
@@ -1,84 +0,0 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
# Copyright (c) 2015 b<>com
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
# implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import mock
|
||||
|
||||
from mock import call
|
||||
from watcher.common.messaging.events import event as messaging_event
|
||||
from watcher.common.messaging.events import event_dispatcher
|
||||
from watcher.decision_engine.messaging import events as messaging_events
|
||||
from watcher.tests import base
|
||||
|
||||
|
||||
class TestEventDispatcher(base.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestEventDispatcher, self).setUp()
|
||||
self.event_dispatcher = event_dispatcher.EventDispatcher()
|
||||
|
||||
def fake_listener(self):
|
||||
return mock.MagicMock()
|
||||
|
||||
def fake_event(self, event_type):
|
||||
event = messaging_event.Event()
|
||||
event.type = event_type
|
||||
return event
|
||||
|
||||
def test_add_listener(self):
|
||||
listener = self.fake_listener()
|
||||
self.event_dispatcher.add_event_listener(messaging_events.Events.ALL,
|
||||
listener)
|
||||
|
||||
self.assertTrue(self.event_dispatcher.has_listener(
|
||||
messaging_events.Events.ALL, listener))
|
||||
|
||||
def test_remove_listener(self):
|
||||
listener = self.fake_listener()
|
||||
self.event_dispatcher.add_event_listener(messaging_events.Events.ALL,
|
||||
listener)
|
||||
self.event_dispatcher.remove_event_listener(
|
||||
messaging_events.Events.ALL, listener)
|
||||
|
||||
self.assertFalse(self.event_dispatcher.has_listener(
|
||||
messaging_events.Events.TRIGGER_AUDIT, listener))
|
||||
|
||||
def test_dispatch_event(self):
|
||||
listener = self.fake_listener()
|
||||
event = self.fake_event(messaging_events.Events.TRIGGER_AUDIT)
|
||||
self.event_dispatcher.add_event_listener(
|
||||
messaging_events.Events.TRIGGER_AUDIT, listener)
|
||||
|
||||
self.event_dispatcher.dispatch_event(event)
|
||||
listener.assert_has_calls(calls=[call(event)])
|
||||
|
||||
def test_dispatch_event_to_all_listener(self):
|
||||
event = self.fake_event(messaging_events.Events.ACTION_PLAN)
|
||||
listener_all = self.fake_listener()
|
||||
listener_action_plan = self.fake_listener()
|
||||
listener_trigger_audit = self.fake_listener()
|
||||
|
||||
self.event_dispatcher.add_event_listener(
|
||||
messaging_events.Events.ALL, listener_all)
|
||||
self.event_dispatcher.add_event_listener(
|
||||
messaging_events.Events.ACTION_PLAN, listener_action_plan)
|
||||
|
||||
self.event_dispatcher.add_event_listener(
|
||||
messaging_events.Events.TRIGGER_AUDIT, listener_trigger_audit)
|
||||
|
||||
self.event_dispatcher.dispatch_event(event)
|
||||
listener_all.assert_has_calls(calls=[call(event)])
|
||||
listener_action_plan.assert_has_calls(calls=[call(event)])
|
||||
listener_trigger_audit.assert_has_calls([])
|
||||
@@ -1,78 +0,0 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
# Copyright (c) 2015 b<>com
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
# implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import mock
|
||||
from oslo_config import cfg
|
||||
import oslo_messaging as messaging
|
||||
from watcher.common.messaging import messaging_handler
|
||||
from watcher.tests import base
|
||||
|
||||
CONF = cfg.CONF
|
||||
|
||||
|
||||
class TestMessagingHandler(base.TestCase):
|
||||
|
||||
PUBLISHER_ID = 'TEST_API'
|
||||
TOPIC_WATCHER = 'TEST_TOPIC_WATCHER'
|
||||
ENDPOINT = 'http://fake-fqdn:1337'
|
||||
VERSION = "1.0"
|
||||
|
||||
def setUp(self):
|
||||
super(TestMessagingHandler, self).setUp()
|
||||
CONF.set_default('host', 'fake-fqdn')
|
||||
|
||||
@mock.patch.object(messaging, "get_rpc_server")
|
||||
@mock.patch.object(messaging, "Target")
|
||||
def test_setup_messaging_handler(self, m_target_cls, m_get_rpc_server):
|
||||
m_target = mock.Mock()
|
||||
m_target_cls.return_value = m_target
|
||||
handler = messaging_handler.MessagingHandler(
|
||||
publisher_id=self.PUBLISHER_ID,
|
||||
topic_name=self.TOPIC_WATCHER,
|
||||
endpoints=[self.ENDPOINT],
|
||||
version=self.VERSION,
|
||||
serializer=None,
|
||||
)
|
||||
|
||||
handler.run()
|
||||
|
||||
m_target_cls.assert_called_once_with(
|
||||
server="fake-fqdn",
|
||||
topic="TEST_TOPIC_WATCHER",
|
||||
version="1.0",
|
||||
)
|
||||
m_get_rpc_server.assert_called_once_with(
|
||||
handler.transport,
|
||||
m_target,
|
||||
[self.ENDPOINT],
|
||||
executor='eventlet',
|
||||
serializer=None,
|
||||
)
|
||||
|
||||
def test_messaging_handler_remove_endpoint(self):
|
||||
handler = messaging_handler.MessagingHandler(
|
||||
publisher_id=self.PUBLISHER_ID,
|
||||
topic_name=self.TOPIC_WATCHER,
|
||||
endpoints=[self.ENDPOINT],
|
||||
version=self.VERSION,
|
||||
serializer=None,
|
||||
)
|
||||
|
||||
self.assertEqual([self.ENDPOINT], handler.endpoints)
|
||||
|
||||
handler.remove_endpoint(self.ENDPOINT)
|
||||
|
||||
self.assertEqual([], handler.endpoints)
|
||||
@@ -1,56 +0,0 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
# Copyright (c) 2015 b<>com
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
# implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
|
||||
import mock
|
||||
import oslo_messaging as messaging
|
||||
from watcher.common.messaging import notification_handler
|
||||
from watcher.common.messaging.utils import observable
|
||||
from watcher.tests import base
|
||||
|
||||
PUBLISHER_ID = 'TEST_API'
|
||||
|
||||
|
||||
class TestNotificationHandler(base.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestNotificationHandler, self).setUp()
|
||||
self.notification_handler = notification_handler.NotificationHandler(
|
||||
PUBLISHER_ID)
|
||||
|
||||
def _test_notify(self, level_to_call):
|
||||
ctx = {}
|
||||
publisher_id = PUBLISHER_ID
|
||||
event_type = 'Test'
|
||||
payload = {}
|
||||
metadata = {}
|
||||
|
||||
with mock.patch.object(observable.Observable, 'notify') as mock_call:
|
||||
notification_result = level_to_call(ctx, publisher_id, event_type,
|
||||
payload, metadata)
|
||||
self.assertEqual(messaging.NotificationResult.HANDLED,
|
||||
notification_result)
|
||||
mock_call.assert_called_once_with(ctx, publisher_id, event_type,
|
||||
metadata, payload)
|
||||
|
||||
def test_notify_info(self):
|
||||
self._test_notify(self.notification_handler.info)
|
||||
|
||||
def test_notify_warn(self):
|
||||
self._test_notify(self.notification_handler.warn)
|
||||
|
||||
def test_notify_error(self):
|
||||
self._test_notify(self.notification_handler.error)
|
||||
@@ -19,7 +19,7 @@ import mock
|
||||
|
||||
from oslo_config import cfg
|
||||
|
||||
from watcher.common.messaging import messaging_handler
|
||||
import oslo_messaging as om
|
||||
from watcher.common import rpc
|
||||
from watcher.common import service
|
||||
from watcher import objects
|
||||
@@ -81,13 +81,13 @@ class TestService(base.TestCase):
|
||||
def setUp(self):
|
||||
super(TestService, self).setUp()
|
||||
|
||||
@mock.patch.object(messaging_handler, "MessagingHandler")
|
||||
@mock.patch.object(om.rpc.server, "RPCServer")
|
||||
def test_start(self, m_handler):
|
||||
dummy_service = service.Service(DummyManager)
|
||||
dummy_service.start()
|
||||
self.assertEqual(2, m_handler.call_count)
|
||||
|
||||
@mock.patch.object(messaging_handler, "MessagingHandler")
|
||||
@mock.patch.object(om.rpc.server, "RPCServer")
|
||||
def test_stop(self, m_handler):
|
||||
dummy_service = service.Service(DummyManager)
|
||||
dummy_service.stop()
|
||||
@@ -98,6 +98,8 @@ class TestService(base.TestCase):
|
||||
dummy_service = service.Service(DummyManager)
|
||||
handler = dummy_service.build_topic_handler(topic_name)
|
||||
self.assertIsNotNone(handler)
|
||||
self.assertIsInstance(handler, om.rpc.server.RPCServer)
|
||||
self.assertEqual("mytopic", handler._target.topic)
|
||||
|
||||
def test_init_service(self):
|
||||
dummy_service = service.Service(DummyManager)
|
||||
@@ -105,58 +107,7 @@ class TestService(base.TestCase):
|
||||
rpc.RequestContextSerializer)
|
||||
self.assertIsInstance(
|
||||
dummy_service.conductor_topic_handler,
|
||||
messaging_handler.MessagingHandler)
|
||||
om.rpc.server.RPCServer)
|
||||
self.assertIsInstance(
|
||||
dummy_service.status_topic_handler,
|
||||
messaging_handler.MessagingHandler)
|
||||
|
||||
@mock.patch.object(messaging_handler, "MessagingHandler")
|
||||
def test_publish_control(self, m_handler_cls):
|
||||
m_handler = mock.Mock()
|
||||
m_handler_cls.return_value = m_handler
|
||||
payload = {
|
||||
"name": "value",
|
||||
}
|
||||
event = "myevent"
|
||||
dummy_service = service.Service(DummyManager)
|
||||
dummy_service.publish_control(event, payload)
|
||||
m_handler.publish_event.assert_called_once_with(event, payload)
|
||||
|
||||
@mock.patch.object(messaging_handler, "MessagingHandler")
|
||||
def test_publish_status_event(self, m_handler_cls):
|
||||
m_handler = mock.Mock()
|
||||
m_handler_cls.return_value = m_handler
|
||||
payload = {
|
||||
"name": "value",
|
||||
}
|
||||
event = "myevent"
|
||||
dummy_service = service.Service(DummyManager)
|
||||
dummy_service.publish_status_event(event, payload)
|
||||
m_handler.publish_event.assert_called_once_with(event, payload, None)
|
||||
|
||||
@mock.patch.object(service.Service, 'publish_status_event')
|
||||
def test_response(self, mock_call):
|
||||
event = "My event"
|
||||
context = {'request_id': 12}
|
||||
message = "My Message"
|
||||
|
||||
dummy_service = service.Service(DummyManager)
|
||||
dummy_service.response(event, context, message)
|
||||
|
||||
expected_payload = {
|
||||
'request_id': context['request_id'],
|
||||
'msg': message
|
||||
}
|
||||
mock_call.assert_called_once_with(event, expected_payload)
|
||||
|
||||
def test_messaging_build_topic_handler(self):
|
||||
dummy_service = service.Service(DummyManager)
|
||||
topic = dummy_service.build_topic_handler("conductor_topic")
|
||||
|
||||
self.assertIsInstance(topic, messaging_handler.MessagingHandler)
|
||||
self.assertEqual("pub_id", dummy_service.publisher_id)
|
||||
self.assertEqual("pub_id", topic.publisher_id)
|
||||
|
||||
self.assertEqual("conductor_topic",
|
||||
dummy_service.conductor_topic_handler.topic_name)
|
||||
self.assertEqual("conductor_topic", topic.topic_name)
|
||||
om.rpc.server.RPCServer)
|
||||
|
||||
@@ -21,7 +21,6 @@ import mock
|
||||
|
||||
from watcher.decision_engine.audit import continuous
|
||||
from watcher.decision_engine.audit import oneshot
|
||||
from watcher.decision_engine.messaging import events
|
||||
from watcher.decision_engine.model.collector import manager
|
||||
from watcher.objects import audit as audit_objects
|
||||
from watcher.tests.db import base
|
||||
@@ -57,25 +56,6 @@ class TestOneShotAuditHandler(base.DbTestCase):
|
||||
audit = audit_objects.Audit.get_by_uuid(self.context, self.audit.uuid)
|
||||
self.assertEqual(audit_objects.State.SUCCEEDED, audit.state)
|
||||
|
||||
@mock.patch.object(manager.CollectorManager, "get_cluster_model_collector")
|
||||
def test_trigger_audit_send_notification(self, mock_collector):
|
||||
messaging = mock.MagicMock()
|
||||
mock_collector.return_value = faker.FakerModelCollector()
|
||||
audit_handler = oneshot.OneShotAuditHandler(messaging)
|
||||
audit_handler.execute(self.audit, self.context)
|
||||
|
||||
call_on_going = mock.call(events.Events.TRIGGER_AUDIT.name, {
|
||||
'audit_status': audit_objects.State.ONGOING,
|
||||
'audit_uuid': self.audit.uuid})
|
||||
call_succeeded = mock.call(events.Events.TRIGGER_AUDIT.name, {
|
||||
'audit_status': audit_objects.State.SUCCEEDED,
|
||||
'audit_uuid': self.audit.uuid})
|
||||
|
||||
calls = [call_on_going, call_succeeded]
|
||||
messaging.publish_status_event.assert_has_calls(calls)
|
||||
self.assertEqual(
|
||||
2, messaging.publish_status_event.call_count)
|
||||
|
||||
|
||||
class TestContinuousAuditHandler(base.DbTestCase):
|
||||
def setUp(self):
|
||||
|
||||
@@ -29,10 +29,6 @@ class TestDecisionEngineAPI(base.TestCase):
|
||||
|
||||
api = rpcapi.DecisionEngineAPI()
|
||||
|
||||
def test_get_version(self):
|
||||
expected_version = self.api.API_VERSION
|
||||
self.assertEqual(expected_version, self.api.get_version())
|
||||
|
||||
def test_get_api_version(self):
|
||||
with mock.patch.object(om.RPCClient, 'call') as mock_call:
|
||||
expected_context = self.context
|
||||
|
||||
Reference in New Issue
Block a user