Merge "improve the process of instance_created.end"
This commit is contained in:
@@ -234,6 +234,19 @@ class VersionedNotification(NovaNotification):
|
|||||||
|
|
||||||
self.update_instance(instance, payload)
|
self.update_instance(instance, payload)
|
||||||
|
|
||||||
|
def instance_created(self, payload):
|
||||||
|
instance_data = payload['nova_object.data']
|
||||||
|
instance_uuid = instance_data['uuid']
|
||||||
|
instance = element.Instance(uuid=instance_uuid)
|
||||||
|
self.cluster_data_model.add_instance(instance)
|
||||||
|
|
||||||
|
node_uuid = instance_data.get('host')
|
||||||
|
if node_uuid:
|
||||||
|
node = self.get_or_create_node(node_uuid)
|
||||||
|
self.cluster_data_model.map_instance(instance, node)
|
||||||
|
|
||||||
|
self.update_instance(instance, payload)
|
||||||
|
|
||||||
def instance_deleted(self, payload):
|
def instance_deleted(self, payload):
|
||||||
instance_data = payload['nova_object.data']
|
instance_data = payload['nova_object.data']
|
||||||
instance_uuid = instance_data['uuid']
|
instance_uuid = instance_data['uuid']
|
||||||
@@ -250,7 +263,7 @@ class VersionedNotification(NovaNotification):
|
|||||||
self.delete_instance(instance, node)
|
self.delete_instance(instance, node)
|
||||||
|
|
||||||
notification_mapping = {
|
notification_mapping = {
|
||||||
'instance.create.end': instance_updated,
|
'instance.create.end': instance_created,
|
||||||
'instance.lock': instance_updated,
|
'instance.lock': instance_updated,
|
||||||
'instance.unlock': instance_updated,
|
'instance.unlock': instance_updated,
|
||||||
'instance.pause.end': instance_updated,
|
'instance.pause.end': instance_updated,
|
||||||
|
|||||||
@@ -810,3 +810,20 @@ class TestNovaNotifications(NotificationTestCase):
|
|||||||
# update_instance should not be called since we did not add an
|
# update_instance should not be called since we did not add an
|
||||||
# Instance object to the CDM since the CDM does not exist yet.
|
# Instance object to the CDM since the CDM does not exist yet.
|
||||||
update_instance.assert_not_called()
|
update_instance.assert_not_called()
|
||||||
|
|
||||||
|
def test_fake_instance_create(self):
|
||||||
|
self.fake_cdmc.cluster_data_model = mock.Mock()
|
||||||
|
handler = novanotification.VersionedNotification(self.fake_cdmc)
|
||||||
|
message = self.load_message('instance-create-end.json')
|
||||||
|
|
||||||
|
# get_instance_by_uuid should not be called when creating instance
|
||||||
|
with mock.patch.object(self.fake_cdmc.cluster_data_model,
|
||||||
|
'get_instance_by_uuid') as mock_get:
|
||||||
|
handler.info(
|
||||||
|
ctxt=self.context,
|
||||||
|
publisher_id=message['publisher_id'],
|
||||||
|
event_type=message['event_type'],
|
||||||
|
payload=message['payload'],
|
||||||
|
metadata=self.FAKE_METADATA,
|
||||||
|
)
|
||||||
|
mock_get.assert_not_called()
|
||||||
|
|||||||
Reference in New Issue
Block a user