]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
lvm: unhandled exception when migrating volume
authorgit-harry <git-harry@live.co.uk>
Fri, 7 Feb 2014 13:37:59 +0000 (13:37 +0000)
committergit-harry <git-harry@live.co.uk>
Fri, 7 Feb 2014 13:37:59 +0000 (13:37 +0000)
Catches the StopIteration exception if the destination volume group
does not exist when attempting to migrate a volume.

Change-Id: I0b5dd15e4c7198fe54abf1aa917a60554adcd568
Closes-Bug:  #1277512

cinder/tests/test_volume.py
cinder/volume/drivers/lvm.py

index caeea99bd9e57f7f6b334a9d6f12bddfe5dbd603..9901811016299b057c65977b5296ca07efa3333e 100644 (file)
@@ -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:'
index 352185c86335720a4bd65f9d0622b5fab75aeb15..2d2515a48eeb3a90a82ab6fa1e9c8d5eb8055a82 100644 (file)
@@ -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)