Lock attach_volume
There are some issues with instance and volume cleanup when the volume is not in a fully attached state so it will be safer to not attempt a terminate_instance while there are attachments in progress. Change-Id: I4347794e51004a881bf4ef5ee30f65ac28773e51 Closes-Bug: #1355348
This commit is contained in:
parent
6b844e3f45
commit
4c4dc3a6d3
@ -4290,11 +4290,16 @@ class ComputeManager(manager.Manager):
|
||||
bdm = objects.BlockDeviceMapping.get_by_volume_id(
|
||||
context, volume_id)
|
||||
driver_bdm = driver_block_device.DriverVolumeBlockDevice(bdm)
|
||||
try:
|
||||
return self._attach_volume(context, instance, driver_bdm)
|
||||
except Exception:
|
||||
with excutils.save_and_reraise_exception():
|
||||
bdm.destroy(context)
|
||||
|
||||
@utils.synchronized(instance.uuid)
|
||||
def do_attach_volume(context, instance, driver_bdm):
|
||||
try:
|
||||
return self._attach_volume(context, instance, driver_bdm)
|
||||
except Exception:
|
||||
with excutils.save_and_reraise_exception():
|
||||
bdm.destroy(context)
|
||||
|
||||
do_attach_volume(context, instance, driver_bdm)
|
||||
|
||||
def _attach_volume(self, context, instance, bdm):
|
||||
context = context.elevated()
|
||||
|
@ -4336,9 +4336,8 @@ class ComputeTestCase(BaseTestCase):
|
||||
fake_attach_volume)
|
||||
|
||||
# attach volume to instance
|
||||
instance_p = obj_base.obj_to_primitive(instance)
|
||||
self.compute.attach_volume(self.context, volume['id'],
|
||||
'/dev/vdc', instance_p, bdm=bdm)
|
||||
'/dev/vdc', instance, bdm=bdm)
|
||||
|
||||
# assert volume attached correctly
|
||||
self.assertEqual(volume['device_name'], '/dev/vdc')
|
||||
|
Loading…
Reference in New Issue
Block a user