From 4c23e0b0bcfec32c2fda762d01663280a1f55afa Mon Sep 17 00:00:00 2001 From: Prabhat Ranjan Date: Fri, 30 Jun 2017 15:28:09 +0530 Subject: [PATCH] Instance delete always stops partition Instance delete always stops partition even if partition ia already stoped. Work around is when it try to stop the partition which is already stopped, then catch exception and pass it. Closes-Bug: #1701506 Change-Id: I8ddb84de307bc58fa68136c503408a2d65ef629a Signed-off-by: Prabhat Ranjan --- nova_dpm/tests/unit/virt/dpm/test_vm.py | 17 +++++++++++++++++ nova_dpm/virt/dpm/vm.py | 14 +++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/nova_dpm/tests/unit/virt/dpm/test_vm.py b/nova_dpm/tests/unit/virt/dpm/test_vm.py index 7c2e6eb..1209e42 100755 --- a/nova_dpm/tests/unit/virt/dpm/test_vm.py +++ b/nova_dpm/tests/unit/virt/dpm/test_vm.py @@ -20,6 +20,8 @@ from nova.objects import instance as instance_obj from nova.test import TestCase from nova_dpm.virt.dpm import exceptions from nova_dpm.virt.dpm import vm + +import mock import zhmcclient import zhmcclient_mock @@ -43,6 +45,14 @@ def fake_session(): 'maximum-memory': 512, 'ifl-processors': 3 }) + cpc1.partitions.add({ + 'name': 'OpenStack-foo-6511ee0f-0d64-4392-aaaa-bbbbbbbbbbbb', + 'description': 'OpenStack CPCSubset=foo', + 'initial-memory': 512, + 'status': 'stopped', + 'maximum-memory': 512, + 'ifl-processors': 3 + }) adapter1 = cpc1.adapters.add({ 'object-id': '6511ee0f-0d64-4392-b9e0-cdbea10a17c3', 'name': 'fcp_1', @@ -271,6 +281,13 @@ class VmPartitionInstanceTestCase(TestCase): 'object-uri') + '/hbas/1', self.partition_inst.get_boot_hba_uri()) + def test_destroy_stopped_partition(self): + instance = instance_obj.Instance() + instance.save = mock.Mock() + instance.uuid = '6511ee0f-0d64-4392-aaaa-bbbbbbbbbbbb' + partition_inst = vm.PartitionInstance(instance, self.cpc) + partition_inst.destroy() + class PhysicalAdapterModelTestCase(TestCase): diff --git a/nova_dpm/virt/dpm/vm.py b/nova_dpm/virt/dpm/vm.py index 66adab4..6f1b36a 100644 --- a/nova_dpm/virt/dpm/vm.py +++ b/nova_dpm/virt/dpm/vm.py @@ -32,6 +32,7 @@ from nova_dpm.virt.dpm import exceptions from nova_dpm.virt.dpm import utils from oslo_log import log as logging from zhmcclient._exceptions import NotFound +from zhmcclient import HTTPError CONF = conf.CONF OPENSTACK_PREFIX = 'OpenStack' @@ -289,7 +290,18 @@ class PartitionInstance(object): def destroy(self): LOG.debug('Partition Destroy triggered') if self.partition: - self.partition.stop(True) + try: + self.partition.stop(True) + except HTTPError as http_error: + # (http_status == 409 and reason == 1) means + # Partition status is not valid to perform the operation. + # e.g - If partition is already stop then stop operation + # is not a valid operation on partition. + if http_error.http_status == 409 and http_error.reason == 1: + pass + else: + raise http_error + # TODO(preethipy): The below method to be removed once the bug # on DPM is fixed to return correct status on API return self._loop_status_update(5, 'stopped')