diff --git a/masakari/engine/instance_events.py b/masakari/engine/instance_events.py new file mode 100644 index 00000000..3affdc9b --- /dev/null +++ b/masakari/engine/instance_events.py @@ -0,0 +1,34 @@ +# Copyright 2017 NTT DATA +# All Rights Reserved. +# +# 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. + +""" VM libvirt events + +These are the events which needs to be processed by masakari in case of +instance recovery failure. +""" + +INSTANCE_EVENTS = { + # Add more events and vir_domain_events here. + 'LIFECYCLE': ['STOPPED_FAILED'], + 'IO_ERROR': ['IO_ERROR_REPORT'] +} + + +def is_valid_event(payload): + vir_domain_event_list = INSTANCE_EVENTS.get(payload.get('event')) + if vir_domain_event_list and payload.get( + 'vir_domain_event') in vir_domain_event_list: + return True + return False diff --git a/masakari/engine/manager.py b/masakari/engine/manager.py index 843bd46a..b44cd694 100644 --- a/masakari/engine/manager.py +++ b/masakari/engine/manager.py @@ -29,6 +29,7 @@ from oslo_utils import timeutils import masakari.conf from masakari.engine import driver +from masakari.engine import instance_events as virt_events from masakari import exception from masakari.i18n import _LE, _LI, _LW from masakari import manager @@ -100,6 +101,13 @@ class MasakariManager(manager.Manager): return notification_status def _handle_notification_type_instance(self, context, notification): + if not virt_events.is_valid_event(notification.payload): + LOG.info(_LI("Notification '%(uuid)s' received with payload " + "%(payload)s is ignored."), { + "uuid": notification.notification_uuid, + "payload": notification.payload}) + return fields.NotificationStatus.IGNORED + notification_status = fields.NotificationStatus.FINISHED try: self.driver.execute_instance_failure( diff --git a/masakari/tests/unit/engine/test_engine_mgr.py b/masakari/tests/unit/engine/test_engine_mgr.py index cde0de96..ac2ca023 100644 --- a/masakari/tests/unit/engine/test_engine_mgr.py +++ b/masakari/tests/unit/engine/test_engine_mgr.py @@ -45,8 +45,8 @@ class EngineManagerUnitTestCase(test.NoDBTestCase): def _get_vm_type_notification(self): return fakes.create_fake_notification( type="VM", id=1, payload={ - 'event': 'stopped', 'instance_uuid': uuidsentinel.fake_ins, - 'vir_domain_event': 'fake_event' + 'event': 'LIFECYCLE', 'instance_uuid': uuidsentinel.fake_ins, + 'vir_domain_event': 'STOPPED_FAILED' }, source_host_uuid=uuidsentinel.fake_host, generated_time=NOW, status="new", @@ -100,6 +100,22 @@ class EngineManagerUnitTestCase(test.NoDBTestCase): self.context, notification.payload.get('instance_uuid'), notification.notification_uuid) + @mock.patch.object(notification_obj.Notification, "save") + def test_process_notification_type_vm_error_event_unmatched( + self, mock_save): + notification = fakes.create_fake_notification( + type="VM", id=1, payload={ + 'event': 'fake_event', 'instance_uuid': uuidsentinel.fake_ins, + 'vir_domain_event': 'fake_vir_domain_event' + }, + source_host_uuid=uuidsentinel.fake_host, + generated_time=NOW, status="new", + notification_uuid=uuidsentinel.fake_notification) + + self.engine.process_notification(self.context, + notification=notification) + self.assertEqual("ignored", notification.status) + @mock.patch("masakari.engine.drivers.taskflow." "TaskFlowDriver.execute_instance_failure") @mock.patch.object(notification_obj.Notification, "save")