Commit 07b49e41 authored by Guido Trotter's avatar Guido Trotter
Browse files

Hypervisors: Add retry= to StopInstance



Currently some hypervisors need the stop operations to be retried more
than once, while other ones only do it in one pass. With this change
we'll handle retries outside the hypervisor code, but telling whether
this is the first try or not.

Since this option is not used for now, all hypervisors just return if
called with retry set to on, maintaining the old behavior. Since the
fake hypervisor has an idempotent StopInstance call, we avoid returning
in that case.
Signed-off-by: default avatarGuido Trotter <ultrotter@google.com>
Reviewed-by: default avatarOlivier Tharan <olive@google.com>
parent 6915bc28
......@@ -111,8 +111,17 @@ class BaseHypervisor(object):
"""Start an instance."""
raise NotImplementedError
def StopInstance(self, instance, force=False):
"""Stop an instance."""
def StopInstance(self, instance, force=False, retry=False):
"""Stop an instance
@type instance: L{objects.Instance}
@param instance: instance to stop
@type force: boolean
@param force: whether to do a "hard" stop (destroy)
@type retry: boolean
@param retry: whether this is just a retry call
"""
raise NotImplementedError
def RebootInstance(self, instance):
......
......@@ -171,7 +171,7 @@ class ChrootManager(hv_base.BaseHypervisor):
raise HypervisorError("Can't run the chroot start script: %s" %
result.output)
def StopInstance(self, instance, force=False):
def StopInstance(self, instance, force=False, retry=False):
"""Stop an instance.
This method has complicated cleanup tests, as we must:
......@@ -180,6 +180,8 @@ class ChrootManager(hv_base.BaseHypervisor):
- finally unmount the instance dir
"""
if retry:
return
root_dir = "%s/%s" % (self._ROOT_DIR, instance.name)
if not os.path.exists(root_dir):
return
......
......@@ -130,7 +130,7 @@ class FakeHypervisor(hv_base.BaseHypervisor):
raise errors.HypervisorError("Failed to start instance %s: %s" %
(instance.name, err))
def StopInstance(self, instance, force=False):
def StopInstance(self, instance, force=False, retry=False):
"""Stop an instance.
For the fake hypervisor, this just removes the file in the base
......
......@@ -535,10 +535,12 @@ class KVMHypervisor(hv_base.BaseHypervisor):
if wait < 5:
wait *= 1.3
def StopInstance(self, instance, force=False):
def StopInstance(self, instance, force=False, retry=False):
"""Stop an instance.
"""
if retry:
return
pidfile, pid, alive = self._InstancePidAlive(instance.name)
if pid > 0 and alive:
if force or not instance.hvparams[constants.HV_ACPI]:
......
......@@ -178,10 +178,12 @@ class XenHypervisor(hv_base.BaseHypervisor):
(instance.name, result.fail_reason,
result.output))
def StopInstance(self, instance, force=False):
def StopInstance(self, instance, force=False, retry=False):
"""Stop an instance.
"""
if retry:
return
self._RemoveConfigFile(instance.name)
if force:
command = ["xm", "destroy", instance.name]
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment