compute: Make swap_volume with resize updates BDM size

swap_volume is now the last code path that would not keep the
volume_size of the volume BDM entry updated.

Change-Id: Ibac2482f8d808c3f888ecb43d5e743f0a1cc179b
Related-bug: #1370177
This commit is contained in:
Nikola Dipanov 2015-06-05 21:27:35 +01:00
parent d13012da9d
commit a8b5028bbd
2 changed files with 20 additions and 10 deletions

View File

@ -4518,12 +4518,11 @@ class ComputeManager(manager.Manager):
new_cinfo['serial'] = old_cinfo['serial']
return (old_cinfo, new_cinfo)
def _swap_volume(self, context, instance, bdm, connector, old_volume_id,
new_volume_id):
def _swap_volume(self, context, instance, bdm, connector,
old_volume_id, new_volume_id, resize_to):
mountpoint = bdm['device_name']
failed = False
new_cinfo = None
resize_to = 0
try:
old_cinfo, new_cinfo = self._init_volume_connection(context,
new_volume_id,
@ -4536,10 +4535,6 @@ class ComputeManager(manager.Manager):
"old: %(old_cinfo)s",
{'new_cinfo': new_cinfo, 'old_cinfo': old_cinfo},
contex=context, instance=instance)
old_vol_size = self.volume_api.get(context, old_volume_id)['size']
new_vol_size = self.volume_api.get(context, new_volume_id)['size']
if new_vol_size > old_vol_size:
resize_to = new_vol_size
self.driver.swap_volume(old_cinfo, new_cinfo, instance, mountpoint,
resize_to)
except Exception:
@ -4593,6 +4588,13 @@ class ComputeManager(manager.Manager):
bdm = objects.BlockDeviceMapping.get_by_volume_id(
context, old_volume_id, instance_uuid=instance.uuid)
connector = self.driver.get_volume_connector(instance)
resize_to = 0
old_vol_size = self.volume_api.get(context, old_volume_id)['size']
new_vol_size = self.volume_api.get(context, new_volume_id)['size']
if new_vol_size > old_vol_size:
resize_to = new_vol_size
LOG.info(_LI('Swapping volume %(old_volume)s for %(new_volume)s'),
{'old_volume': old_volume_id, 'new_volume': new_volume_id},
context=context, instance=instance)
@ -4600,7 +4602,8 @@ class ComputeManager(manager.Manager):
bdm,
connector,
old_volume_id,
new_volume_id)
new_volume_id,
resize_to)
save_volume_id = comp_ret['save_volume_id']
@ -4612,8 +4615,11 @@ class ComputeManager(manager.Manager):
'destination_type': 'volume',
'snapshot_id': None,
'volume_id': save_volume_id,
'volume_size': None,
'no_device': None}
if resize_to:
values['volume_size'] = resize_to
LOG.debug("swap_volume: Updating volume %(volume_id)s BDM record with "
"%(updates)s", {'volume_id': bdm.volume_id,
'updates': values},

View File

@ -1443,6 +1443,10 @@ class ComputeManagerUnitTestCase(test.NoDBTestCase):
instance, mountpoint, resize_to):
self.assertEqual(resize_to, 2)
def fake_block_device_mapping_update(ctxt, id, updates, legacy):
self.assertEqual(2, updates['volume_size'])
return fake_bdm
self.stubs.Set(self.compute.volume_api, 'roll_detaching',
fake_vol_api_roll_detaching)
self.stubs.Set(self.compute.volume_api, 'get', fake_vol_get)
@ -1461,7 +1465,7 @@ class ComputeManagerUnitTestCase(test.NoDBTestCase):
self.stubs.Set(self.compute.volume_api, 'migrate_volume_completion',
fake_vol_migrate_volume_completion)
self.stubs.Set(db, 'block_device_mapping_update',
lambda *a, **k: fake_bdm)
fake_block_device_mapping_update)
self.stubs.Set(db,
'instance_fault_create',
lambda x, y: