diff --git a/watcher/decision_engine/model/notification/nova.py b/watcher/decision_engine/model/notification/nova.py index 763328a59..f4dee54ae 100644 --- a/watcher/decision_engine/model/notification/nova.py +++ b/watcher/decision_engine/model/notification/nova.py @@ -279,5 +279,10 @@ class VersionedNotification(NovaNotification): metadata=metadata)) func = self.notification_mapping.get(event_type) if func: - LOG.debug(payload) - func(self, payload) + # The nova CDM is not built until an audit is performed. + if self.cluster_data_model: + LOG.debug(payload) + func(self, payload) + else: + LOG.debug('Nova CDM has not yet been built; ignoring ' + 'notifications until an audit is performed.') diff --git a/watcher/tests/decision_engine/model/notification/test_nova_notifications.py b/watcher/tests/decision_engine/model/notification/test_nova_notifications.py index e23bd8ee5..95f793e70 100644 --- a/watcher/tests/decision_engine/model/notification/test_nova_notifications.py +++ b/watcher/tests/decision_engine/model/notification/test_nova_notifications.py @@ -743,3 +743,21 @@ class TestNovaNotifications(NotificationTestCase): self.assertEqual( element.InstanceState.SUSPENDED.value, instance0.state) + + def test_info_no_cdm(self): + # Tests that a notification is received before an audit has been + # performed which would create the nova CDM. + mock_collector = mock.Mock(cluster_data_model=None) + handler = novanotification.VersionedNotification(mock_collector) + payload = { + 'nova_object.data': { + 'uuid': '9966d6bd-a45c-4e1c-9d57-3054899a3ec7', + 'host': None + } + } + with mock.patch.object(handler, 'update_instance') as update_instance: + handler.info(mock.sentinel.ctxt, 'publisher_id', 'instance.update', + payload, metadata={}) + # update_instance should not be called since we did not add an + # Instance object to the CDM since the CDM does not exist yet. + update_instance.assert_not_called()