From c8969dbdd429c0b4c4f1211bd90311cabec8dd0d Mon Sep 17 00:00:00 2001 From: Justin Santa Barbara Date: Mon, 28 Mar 2011 00:41:55 -0700 Subject: [PATCH 1/5] Assume that if we don't find a VM for an instance in the DB, and the DB state is NOSTATE, that the db instance is in the process of being spawned. Fix for bug744056 --- nova/compute/manager.py | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/nova/compute/manager.py b/nova/compute/manager.py index 468771f46e19..f396baa44f60 100644 --- a/nova/compute/manager.py +++ b/nova/compute/manager.py @@ -1051,16 +1051,31 @@ class ComputeManager(manager.SchedulerDependentManager): for db_instance in db_instances: name = db_instance['name'] + db_state = db_instance['state'] vm_instance = vm_instances.get(name) + if vm_instance is None: - LOG.info(_("Found instance '%(name)s' in DB but no VM. " - "Setting state to shutoff.") % locals()) - vm_state = power_state.SHUTOFF + #NOTE(justinsb): We have to be very careful here, because a + #concurrent operation could be in progress (e.g. a spawn) + if db_state == power_state.NOSTATE: + #Assume that NOSTATE => spawning + #TODO(justinsb): This does mean that if we crash during a + #spawn, the machine will never leave the spawning state. + #We could have a separate task to correct this error. + #TODO(justinsb): What happens during a live migration? + LOG.info(_("Found instance '%(name)s' in DB but no VM. " + "State=%(db_state), so assuming spawn is in " + "progress.") % locals()) + vm_state = db_state + else: + LOG.info(_("Found instance '%(name)s' in DB but no VM. " + "State=%(db_state), so setting state to " + "shutoff.") % locals()) + vm_state = power_state.SHUTOFF else: vm_state = vm_instance.state vms_not_found_in_db.remove(name) - db_state = db_instance['state'] if vm_state != db_state: LOG.info(_("DB/VM state mismatch. Changing state from " "'%(db_state)s' to '%(vm_state)s'") % locals()) From b648f3499626874327d8f1b087a578afe903d010 Mon Sep 17 00:00:00 2001 From: Justin Santa Barbara Date: Mon, 28 Mar 2011 00:44:13 -0700 Subject: [PATCH 2/5] pep8 fixes --- nova/compute/manager.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nova/compute/manager.py b/nova/compute/manager.py index f396baa44f60..2b8494787aa6 100644 --- a/nova/compute/manager.py +++ b/nova/compute/manager.py @@ -1053,7 +1053,7 @@ class ComputeManager(manager.SchedulerDependentManager): name = db_instance['name'] db_state = db_instance['state'] vm_instance = vm_instances.get(name) - + if vm_instance is None: #NOTE(justinsb): We have to be very careful here, because a #concurrent operation could be in progress (e.g. a spawn) From 7ed45fe61416213a4fbfba7e45a765e43b933e16 Mon Sep 17 00:00:00 2001 From: Justin Santa Barbara Date: Mon, 28 Mar 2011 01:05:20 -0700 Subject: [PATCH 3/5] Fixed some format strings --- nova/compute/manager.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nova/compute/manager.py b/nova/compute/manager.py index 2b8494787aa6..0e42a4bd28e3 100644 --- a/nova/compute/manager.py +++ b/nova/compute/manager.py @@ -1064,12 +1064,12 @@ class ComputeManager(manager.SchedulerDependentManager): #We could have a separate task to correct this error. #TODO(justinsb): What happens during a live migration? LOG.info(_("Found instance '%(name)s' in DB but no VM. " - "State=%(db_state), so assuming spawn is in " + "State=%(db_state)s, so assuming spawn is in " "progress.") % locals()) vm_state = db_state else: LOG.info(_("Found instance '%(name)s' in DB but no VM. " - "State=%(db_state), so setting state to " + "State=%(db_state)s, so setting state to " "shutoff.") % locals()) vm_state = power_state.SHUTOFF else: From 408de4bd5fe436e1829f4b916f0f20042e48eacc Mon Sep 17 00:00:00 2001 From: Justin Santa Barbara Date: Mon, 28 Mar 2011 01:08:50 -0700 Subject: [PATCH 4/5] Clarified note about scope of the _poll_instance_states function --- nova/compute/manager.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/nova/compute/manager.py b/nova/compute/manager.py index 0e42a4bd28e3..93eca61fb928 100644 --- a/nova/compute/manager.py +++ b/nova/compute/manager.py @@ -1060,7 +1060,9 @@ class ComputeManager(manager.SchedulerDependentManager): if db_state == power_state.NOSTATE: #Assume that NOSTATE => spawning #TODO(justinsb): This does mean that if we crash during a - #spawn, the machine will never leave the spawning state. + #spawn, the machine will never leave the spawning state, + #but this is just the way nova is; this function isn't + #trying to correct that problem. #We could have a separate task to correct this error. #TODO(justinsb): What happens during a live migration? LOG.info(_("Found instance '%(name)s' in DB but no VM. " From 5a80f8b3d5ae3be774b0b3e1dbc89c9830273eaa Mon Sep 17 00:00:00 2001 From: Justin Santa Barbara Date: Mon, 28 Mar 2011 10:00:33 -0700 Subject: [PATCH 5/5] Fix formatting of TODO and NOTE - should be a space after the # --- nova/compute/manager.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/nova/compute/manager.py b/nova/compute/manager.py index 93eca61fb928..eb42f054dee2 100644 --- a/nova/compute/manager.py +++ b/nova/compute/manager.py @@ -1055,16 +1055,16 @@ class ComputeManager(manager.SchedulerDependentManager): vm_instance = vm_instances.get(name) if vm_instance is None: - #NOTE(justinsb): We have to be very careful here, because a - #concurrent operation could be in progress (e.g. a spawn) + # NOTE(justinsb): We have to be very careful here, because a + # concurrent operation could be in progress (e.g. a spawn) if db_state == power_state.NOSTATE: - #Assume that NOSTATE => spawning - #TODO(justinsb): This does mean that if we crash during a - #spawn, the machine will never leave the spawning state, - #but this is just the way nova is; this function isn't - #trying to correct that problem. - #We could have a separate task to correct this error. - #TODO(justinsb): What happens during a live migration? + # Assume that NOSTATE => spawning + # TODO(justinsb): This does mean that if we crash during a + # spawn, the machine will never leave the spawning state, + # but this is just the way nova is; this function isn't + # trying to correct that problem. + # We could have a separate task to correct this error. + # TODO(justinsb): What happens during a live migration? LOG.info(_("Found instance '%(name)s' in DB but no VM. " "State=%(db_state)s, so assuming spawn is in " "progress.") % locals())