From 551d81809b3488287948807a23b4b7e838595f6b Mon Sep 17 00:00:00 2001 From: Yi Chun Huang Date: Tue, 21 Mar 2017 15:56:12 +0800 Subject: [PATCH] Updating instance_fcp_map correctly when boot-from-volume fails When boot-from-volume fails, its instance_fcp_map should be updated correctly. Unfortunately, current code is wrong and will lead to an error raised. Change-Id: I7aa65d551b435e0600a40e652478a1fb775d5ca1 --- nova/tests/unit/virt/zvm/test_zvm.py | 26 ++++++++++++++++++++++++++ nova/virt/zvm/volumeop.py | 12 ++++++++++-- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/nova/tests/unit/virt/zvm/test_zvm.py b/nova/tests/unit/virt/zvm/test_zvm.py index bfff699..b39e11e 100644 --- a/nova/tests/unit/virt/zvm/test_zvm.py +++ b/nova/tests/unit/virt/zvm/test_zvm.py @@ -3091,6 +3091,32 @@ class SVCDriverTestCase(ZVMTestCase): self.driver._fcp_pool = {} + def test_update_instance_fcp_map_force_remove(self): + fcp1 = self.driver.FCP([]) + self.driver._fcp_pool = {'0001': fcp1} + fcp_list = ['0001'] + self.driver._instance_fcp_map = {'inst1': {'fcp_list': ['0001'], + 'count': 2}} + fcp1.set_in_use() + + self.driver._update_instance_fcp_map('inst1', fcp_list, + self.driver._FORCE_REMOVE) + self.assertEqual({}, self.driver._instance_fcp_map) + self.assertFalse(fcp1.is_in_use()) + self.assertFalse(fcp1.is_reserved()) + + self.driver._instance_fcp_map = {'inst1': {'fcp_list': ['0001'], + 'count': 0}} + fcp1.set_in_use() + + self.driver._update_instance_fcp_map('inst1', fcp_list, + self.driver._FORCE_REMOVE) + self.assertEqual({}, self.driver._instance_fcp_map) + self.assertFalse(fcp1.is_in_use()) + self.assertFalse(fcp1.is_reserved()) + + self.driver._fcp_pool = {} + def test_update_instance_fcp_map_unknown_action(self): self.assertRaises(exception.ZVMVolumeError, self.driver._update_instance_fcp_map, diff --git a/nova/virt/zvm/volumeop.py b/nova/virt/zvm/volumeop.py index 7272716..591ad93 100644 --- a/nova/virt/zvm/volumeop.py +++ b/nova/virt/zvm/volumeop.py @@ -326,6 +326,7 @@ class SVCDriver(DriverAPI): _INCREASE = 1 _DECREASE = 2 _REMOVE = 3 + _FORCE_REMOVE = 4 def __init__(self): self._xcat_url = zvmutils.get_xcat_url() @@ -552,6 +553,13 @@ class SVCDriver(DriverAPI): 'fcp_list': fcp_list} raise exception.ZVMVolumeError(msg=errmsg) + elif action == self._FORCE_REMOVE: + if instance_name in self._instance_fcp_map: + for fcp_no in fcp_list: + fcp = self._fcp_pool.get(fcp_no) + fcp.release_device() + self._instance_fcp_map.pop(instance_name) + else: errmsg = _("Unrecognized option: %s") % action raise exception.ZVMVolumeError(msg=errmsg) @@ -899,8 +907,8 @@ class SVCDriver(DriverAPI): self._attach_device(instance['name'], fcp) def volume_boot_cleanup(self, instance, fcp): - self._update_instance_fcp_map_if_unlocked(instance['name'], - [fcp], self._DECREASE) + self._update_instance_fcp_map_if_unlocked(instance['name'], [fcp], + self._FORCE_REMOVE) self._detach_device(instance['name'], fcp) def _expand_fcp_list(self, fcp_list):