Commit 8c9894c2 authored by Christos Stavrakakis's avatar Christos Stavrakakis

cyclades: Add missing lock when detaching a volume

Get server with 'for_update' option when detaching a server's volume.
parent ff301237
......@@ -987,7 +987,7 @@ def add(request, net, args):
raise faults.BadRequest('Malformed Request.')
vm = util.get_vm(server_id, request.user_uniq, non_suspended=True,
non_deleted=True)
for_update=True, non_deleted=True)
servers.connect(vm, network=net)
return HttpResponse(status=202)
......@@ -1015,7 +1015,7 @@ def remove(request, net, args):
nic = util.get_nic(nic_id=nic_id)
server_id = nic.machine_id
vm = util.get_vm(server_id, request.user_uniq, non_suspended=True,
non_deleted=True)
for_update=True, non_deleted=True)
servers.disconnect(vm, nic)
......@@ -1075,7 +1075,7 @@ def get_volumes(request, server_id):
def get_volume_info(request, server_id, volume_id):
log.debug("get_volume_info server_id %s volume_id", server_id, volume_id)
user_id = request.user_uniq
vm = util.get_vm(server_id, user_id)
vm = util.get_vm(server_id, user_id, for_update=False)
volume = get_volume(user_id, volume_id, for_update=False, non_deleted=True,
exception=faults.BadRequest)
servers._check_attachment(vm, volume)
......@@ -1108,7 +1108,7 @@ def attach_volume(request, server_id):
def detach_volume(request, server_id, volume_id):
log.debug("detach_volume server_id %s volume_id", server_id, volume_id)
user_id = request.user_uniq
vm = util.get_vm(server_id, user_id, non_deleted=True)
vm = util.get_vm(server_id, user_id, for_update=True, non_deleted=True)
volume = get_volume(user_id, volume_id, for_update=True, non_deleted=True,
exception=faults.BadRequest)
vm = server_attachments.detach_volume(vm, volume)
......
......@@ -183,7 +183,7 @@ class VolumesTest(BaseAPITest):
volumes.delete,
vol)
vm = mf.VirtualMachineFactory()
vm = mf.VirtualMachineFactory(userid=vol.userid)
# Also we cannot delete root volume
vol.index = 0
vol.machine = vm
......
......@@ -209,10 +209,14 @@ def delete(volume):
"""Delete a Volume"""
# A volume is deleted by detaching it from the server that is attached.
# Deleting a detached volume is not implemented.
if volume.machine_id is not None:
server_attachments.detach_volume(volume.machine, volume)
server_id = volume.machine_id
if server_id is not None:
server = util.get_server(volume.userid, server_id, for_update=True,
non_deleted=True,
exception=faults.BadRequest)
server_attachments.detach_volume(server, volume)
log.info("Detach volume '%s' from server '%s', job: %s",
volume.id, volume.machine_id, volume.backendjobid)
volume.id, server_id, volume.backendjobid)
else:
raise faults.BadRequest("Cannot delete a detached volume")
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment