From 37293192c6ae7b841ded4fbccd4d5b36cc89fbaa Mon Sep 17 00:00:00 2001 From: Robert Collins Date: Mon, 7 Jan 2013 15:17:42 +1300 Subject: Cope better with out of sync bm data. The baremetal hypervisor tracks references to instances which are deleted asynchronously from the commit to the nova bm. As such, its a normal but rare condition for a bare metal node to refer to a deleted (and even garbage collected) nova instance. We should treat such instances are deleted rather than erroring on any call through list_instances(), permitting starting new instances and listing instances to work - fixing bug: 1096722. Pathologically, the database may suffer permanent skew, which means we need a way to fix it (and thats tracked as a separate bug). Change-Id: Ic21ff66b1fc0ad64bb5feff26291873b96d20e4e --- nova/virt/baremetal/driver.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/nova/virt/baremetal/driver.py b/nova/virt/baremetal/driver.py index e517b399d..a27056994 100644 --- a/nova/virt/baremetal/driver.py +++ b/nova/virt/baremetal/driver.py @@ -169,11 +169,19 @@ class BareMetalDriver(driver.ComputeDriver): l = [] ctx = nova_context.get_admin_context() for node in _get_baremetal_nodes(ctx): - if node['instance_uuid']: - inst = self.virtapi.instance_get_by_uuid(ctx, - node['instance_uuid']) - if inst: - l.append(inst['name']) + if not node['instance_uuid']: + # Not currently assigned to an instance. + continue + try: + inst = self.virtapi.instance_get_by_uuid( + ctx, node['instance_uuid']) + except exception.InstanceNotFound: + # Assigned to an instance that no longer exists. + LOG.warning(_("Node %(id)r assigned to instance %(uuid)r " + "which cannot be found."), + dict(id=node['id'], uuid=node['instance_uuid'])) + continue + l.append(inst['name']) return l def spawn(self, context, instance, image_meta, injected_files, -- cgit