From: git-harry Date: Fri, 7 Feb 2014 13:37:59 +0000 (+0000) Subject: lvm: unhandled exception when migrating volume X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=c311e94d3d1f19924ac77d197c616782b497f908;p=openstack-build%2Fcinder-build.git lvm: unhandled exception when migrating volume Catches the StopIteration exception if the destination volume group does not exist when attempting to migrate a volume. Change-Id: I0b5dd15e4c7198fe54abf1aa917a60554adcd568 Closes-Bug: #1277512 --- diff --git a/cinder/tests/test_volume.py b/cinder/tests/test_volume.py index caeea99bd..990181101 100644 --- a/cinder/tests/test_volume.py +++ b/cinder/tests/test_volume.py @@ -2685,6 +2685,29 @@ class LVMISCSIVolumeDriverTestCase(DriverTestCase): self.assertEqual(moved, False) self.assertIsNone(model_update) + def test_lvm_volume_group_missing(self): + hostname = socket.gethostname() + capabilities = {'location_info': 'LVMVolumeDriver:%s:' + 'cinder-volumes-3:default:0' % hostname} + host = {'capabilities': capabilities} + vol = {'name': 'test', 'id': 1, 'size': 1, 'status': 'available'} + + def get_all_volume_groups(): + return [{'name': 'cinder-volumes-2'}] + + self.stubs.Set(volutils, 'get_all_volume_groups', + get_all_volume_groups) + + self.volume.driver.vg = FakeBrickLVM('cinder-volumes', + False, + None, + 'default') + + moved, model_update = self.volume.driver.migrate_volume(self.context, + vol, host) + self.assertEqual(moved, False) + self.assertIsNone(model_update) + def test_lvm_migrate_volume_proceed(self): hostname = socket.gethostname() capabilities = {'location_info': 'LVMVolumeDriver:%s:' diff --git a/cinder/volume/drivers/lvm.py b/cinder/volume/drivers/lvm.py index 352185c86..2d2515a48 100644 --- a/cinder/volume/drivers/lvm.py +++ b/cinder/volume/drivers/lvm.py @@ -693,9 +693,9 @@ class LVMISCSIDriver(LVMVolumeDriver, driver.ISCSIDriver): if dest_vg != self.vg.vg_name: vg_list = volutils.get_all_volume_groups() - vg_dict = \ + try: (vg for vg in vg_list if vg['name'] == dest_vg).next() - if vg_dict is None: + except StopIteration: message = ("Destination Volume Group %s does not exist" % dest_vg) LOG.error(_('%s'), message)