From e265fd8e45fd437af9c6e0eeb72076268fd24e0e Mon Sep 17 00:00:00 2001 From: Zhenguo Niu Date: Thu, 5 Jan 2017 20:07:06 +0800 Subject: [PATCH] Abort instance provision if it goes to some status If the instance goes to some status like deleting, we should abort the provision. Change-Id: Id6382388af7a15636f7dd102e4f1d0d0fbf31113 --- mogan/engine/flows/create_instance.py | 4 ++++ mogan/objects/instance.py | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/mogan/engine/flows/create_instance.py b/mogan/engine/flows/create_instance.py index ac20fa16..f7a36506 100644 --- a/mogan/engine/flows/create_instance.py +++ b/mogan/engine/flows/create_instance.py @@ -289,6 +289,10 @@ class CreateInstanceTask(flow_utils.MoganTask): def _wait_for_active(self, instance): """Wait for the node to be marked as ACTIVE in Ironic.""" + instance.refresh() + if instance.status in (status.DELETING, status.ERROR, status.DELETED): + raise exception.InstanceDeployFailure( + _("Instance %s provisioning was aborted") % instance.uuid) node = ironic.get_node_by_instance(self.ironicclient, instance.uuid) diff --git a/mogan/objects/instance.py b/mogan/objects/instance.py index 1ff58188..8d6f4109 100644 --- a/mogan/objects/instance.py +++ b/mogan/objects/instance.py @@ -87,3 +87,8 @@ class Instance(base.MoganObject, object_base.VersionedObjectDictCompat): updates = self.obj_get_changes() self.dbapi.instance_update(context, self.uuid, updates) self.obj_reset_changes() + + def refresh(self, context=None): + """Refresh the object by re-fetching from the DB.""" + current = self.__class__.get(context, self.uuid) + self.obj_refresh(current)