improve the process of instance_created.end

In the process of handling instance_created.end,
there is a KeyError exception output log. This is because
invoking get_instance_by_uuid before creating the instance
in the data model.
During the review of https://review.opendev.org/#/c/663489/,
reviewers think that it's better to remove the KeyError exception.
This patche seperates the process of instance_created.end from
other Nova notifications and removes the call of get_instance_by_uuid.

Change-Id: Ie9e2d4f5b32ee7a5b52bbcd50abfa81dcabab7bb
This commit is contained in:
licanwei
2019-06-21 16:53:25 +08:00
parent d98f51c452
commit dd321e9f21
2 changed files with 31 additions and 1 deletions

View File

@@ -224,6 +224,19 @@ class VersionedNotification(NovaNotification):
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):
instance_data = payload['nova_object.data']
instance_uuid = instance_data['uuid']
@@ -240,7 +253,7 @@ class VersionedNotification(NovaNotification):
self.delete_instance(instance, node)
notification_mapping = {
'instance.create.end': instance_updated,
'instance.create.end': instance_created,
'instance.lock': instance_updated,
'instance.unlock': instance_updated,
'instance.pause.end': instance_updated,