Handle no nova CDM in notification code
As of change Ic4659d1f18af181203439a8bf1b38805ff34c309 the
nova CDM will not be built until an audit is performed.
Instances and services (compute hosts) can be created and
deleted before an audit is performed which will attempt
to use the notification callback function which relies
on the CDM being built already, and if not results in
an AttributeError.
This change side-steps that issue by checking to see that the
nova CDM exists before trying to call the notification
callback function.
An alternative to this is forcefully create the nova CDM when
notifications are received before an audit which is what happend
before change Ic4659d1f18af181203439a8bf1b38805ff34c309.
Change-Id: I16990afb82019821c443c9df26d3e515e52efa69
Closes-Bug: #1828582
(cherry picked from commit 8a206a6ae5)
This commit is contained in:
@@ -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.')
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user