Fix IndexError in volume manager
A list comprehension in volume manager can raise IndexError due to unsafe assumption of input. This change fix it by not assuming list comprehension always return none empty list. This also fixes a snapshot DB call by using OVO. Change-Id: I83e8ac8dcf9e84b37847d6eb09065d55e843f82e Closes-bug: #1628340
This commit is contained in:
parent
d53f37db2b
commit
d96fb9a101
|
@ -419,6 +419,8 @@ class VolumeTestCase(BaseVolumeTestCase):
|
|||
self.context, size=1, host=CONF.host)
|
||||
vol1 = tests_utils.create_volume(
|
||||
self.context, size=1, host=CONF.host)
|
||||
vol2 = tests_utils.create_volume(
|
||||
self.context, size=1, host=CONF.host, status='creating')
|
||||
snap0 = tests_utils.create_snapshot(self.context, vol0.id)
|
||||
snap1 = tests_utils.create_snapshot(self.context, vol1.id)
|
||||
# Return values for update_provider_info
|
||||
|
@ -434,11 +436,14 @@ class VolumeTestCase(BaseVolumeTestCase):
|
|||
vol0.id)
|
||||
vol1_obj = objects.Volume.get_by_id(context.get_admin_context(),
|
||||
vol1.id)
|
||||
vol2_obj = objects.Volume.get_by_id(context.get_admin_context(),
|
||||
vol2.id)
|
||||
snap0_obj = objects.Snapshot.get_by_id(self.context, snap0.id)
|
||||
snap1_obj = objects.Snapshot.get_by_id(self.context, snap1.id)
|
||||
# Check updated provider ids
|
||||
self.assertEqual('1 2 xxxx', vol0_obj.provider_id)
|
||||
self.assertEqual('3 4 yyyy', vol1_obj.provider_id)
|
||||
self.assertIsNone(vol2_obj.provider_id)
|
||||
self.assertEqual('5 6 xxxx', snap0_obj.provider_id)
|
||||
self.assertEqual('7 8 yyyy', snap1_obj.provider_id)
|
||||
# Clean up
|
||||
|
|
|
@ -346,8 +346,9 @@ class VolumeManager(manager.SchedulerDependentManager):
|
|||
# NOTE(JDG): Make sure returned item is in this hosts volumes
|
||||
update = (
|
||||
[updt for updt in updates if updt['id'] ==
|
||||
volume['id']][0])
|
||||
volume['id']])
|
||||
if update:
|
||||
update = update[0]
|
||||
self.db.volume_update(
|
||||
ctxt,
|
||||
update['id'],
|
||||
|
@ -424,7 +425,7 @@ class VolumeManager(manager.SchedulerDependentManager):
|
|||
self.driver.init_capabilities()
|
||||
|
||||
volumes = objects.VolumeList.get_all_by_host(ctxt, self.host)
|
||||
snapshots = self.db.snapshot_get_by_host(ctxt, self.host)
|
||||
snapshots = objects.SnapshotList.get_by_host(ctxt, self.host)
|
||||
self._sync_provider_info(ctxt, volumes, snapshots)
|
||||
# FIXME volume count for exporting is wrong
|
||||
|
||||
|
|
Loading…
Reference in New Issue