From be6152f89b99a0edc4390a4d10f27575265a0d13 Mon Sep 17 00:00:00 2001 From: Matt Odden Date: Wed, 3 Oct 2012 16:27:24 +0000 Subject: powervm: add polling timeout for LPAR stop command We need to poll the LPAR state after a stop command is sent to verify that the LPAR actually stops. Optionally, a timeout value in seconds can be specified. Also, fixes power_on and power_off calling the wrong start/stop functions bp powervm-compute-enhancements Change-Id: I9ffd0125c1968e9a656d9456ea3eb85f5db8f1ab --- nova/virt/powervm/exception.py | 5 +++++ nova/virt/powervm/operator.py | 29 +++++++++++++++++++++++------ 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/nova/virt/powervm/exception.py b/nova/virt/powervm/exception.py index be476109c..2a8cf4771 100644 --- a/nova/virt/powervm/exception.py +++ b/nova/virt/powervm/exception.py @@ -41,6 +41,11 @@ class PowerVMLPARAttributeNotFound(exception.NovaException): pass +class PowerVMLPAROperationTimeout(exception.NovaException): + message = _("Operation '%(operation)s' on " + "LPAR '%(instance_name)s' timed out") + + class PowerVMImageCreationFailed(exception.NovaException): message = _("Image creation failed on PowerVM") diff --git a/nova/virt/powervm/operator.py b/nova/virt/powervm/operator.py index 7c7478b99..bc0986ca4 100644 --- a/nova/virt/powervm/operator.py +++ b/nova/virt/powervm/operator.py @@ -295,11 +295,11 @@ class PowerVMOperator(object): raise exception.PowerVMLPARInstanceCleanupFailed( instance_name=instance_name) - def power_off(self, instance_name): - self._operator.stop(instance_name) + def power_off(self, instance_name, timeout=30): + self._operator.stop_lpar(instance_name, timeout) def power_on(self, instance_name): - self._operator.start(instance_name) + self._operator.start_lpar(instance_name) class BaseOperator(object): @@ -360,15 +360,32 @@ class BaseOperator(object): self.run_command(self.command.chsysstate('-r lpar -o on -n %s' % instance_name)) - def stop_lpar(self, instance_name): + def stop_lpar(self, instance_name, timeout=30): """Stop a running LPAR. :param instance_name: LPAR instance name + :param timeout: value in seconds for specifying + how long to wait for the LPAR to stop """ - cmd = self.command.chsysstate('-r lpar -o shutdown --immed -n %s' - % instance_name) + cmd = self.command.chsysstate('-r lpar -o shutdown --immed -n %s' % + instance_name) self.run_command(cmd) + # poll instance until stopped or raise exception + lpar_obj = self.get_lpar(instance_name) + wait_inc = 1 # seconds to wait between status polling + start_time = time.time() + while lpar_obj['state'] != 'Not Activated': + curr_time = time.time() + # wait up to (timeout) seconds for shutdown + if (curr_time - start_time) > timeout: + raise exception.PowerVMLPAROperationTimeout( + operation='stop_lpar', + instance_name=instance_name) + + time.sleep(wait_inc) + lpar_obj = self.get_lpar(instance_name) + def remove_lpar(self, instance_name): """Removes a LPAR. -- cgit