parallelize volume deletion
This is second patch in the series to implement parallel delete In this patch, parallelizing volume deletion and updating relevant tests Blueprint parallel-delete Change-Id: Iaded5951618c2ac52c26d6d6437f152c658ad9cf
This commit is contained in:
parent
49d414e445
commit
bf65eedf3f
@ -92,31 +92,43 @@ class Volume(resource.Resource):
|
||||
if backup.status != 'available':
|
||||
raise exception.Error(backup.status)
|
||||
|
||||
@scheduler.wrappertask
|
||||
def _delete(self, backup=False):
|
||||
if self.resource_id is not None:
|
||||
try:
|
||||
vol = self.cinder().volumes.get(self.resource_id)
|
||||
|
||||
if backup:
|
||||
scheduler.TaskRunner(self._backup)()
|
||||
yield self._backup()
|
||||
vol.get()
|
||||
|
||||
if vol.status == 'in-use':
|
||||
logger.warn('cant delete volume when in-use')
|
||||
raise exception.Error('Volume in use')
|
||||
|
||||
self.cinder().volumes.delete(self.resource_id)
|
||||
vol.delete()
|
||||
while True:
|
||||
yield
|
||||
vol.get()
|
||||
except clients.cinderclient.exceptions.NotFound:
|
||||
pass
|
||||
self.resource_id = None
|
||||
|
||||
if volume_backups is not None:
|
||||
def handle_snapshot_delete(self, state):
|
||||
backup = state not in ((self.CREATE, self.FAILED),
|
||||
(self.UPDATE, self.FAILED))
|
||||
return self._delete(backup=backup)
|
||||
|
||||
delete_task = scheduler.TaskRunner(self._delete, backup=backup)
|
||||
delete_task.start()
|
||||
return delete_task
|
||||
|
||||
def handle_delete(self):
|
||||
return self._delete()
|
||||
delete_task = scheduler.TaskRunner(self._delete)
|
||||
delete_task.start()
|
||||
return delete_task
|
||||
|
||||
def check_delete_complete(self, delete_task):
|
||||
return delete_task.step()
|
||||
|
||||
|
||||
class VolumeAttachTask(object):
|
||||
|
@ -112,6 +112,15 @@ class VolumeTest(HeatTestCase):
|
||||
display_description=vol_name,
|
||||
display_name=vol_name).AndReturn(fv)
|
||||
|
||||
def _stubout_delete_volume(self, fv):
|
||||
self.m.StubOutWithMock(fv, 'delete')
|
||||
fv.delete().AndReturn(True)
|
||||
self.m.StubOutWithMock(fv, 'get')
|
||||
fv.get().AndReturn(None)
|
||||
fv.get().AndRaise(
|
||||
clients.cinderclient.exceptions.NotFound('Not found'))
|
||||
self.m.ReplayAll()
|
||||
|
||||
def _mock_create_server_volume_script(self, fva):
|
||||
clients.OpenStackClients.nova().MultipleTimes().AndReturn(self.fc)
|
||||
self.fc.volumes.create_server_volume(
|
||||
@ -130,10 +139,6 @@ class VolumeTest(HeatTestCase):
|
||||
self.cinder_fc.volumes.get('vol-123').AndReturn(fv)
|
||||
|
||||
self.cinder_fc.volumes.get('vol-123').AndReturn(fv)
|
||||
self.cinder_fc.volumes.delete('vol-123').AndReturn(None)
|
||||
|
||||
self.cinder_fc.volumes.get('vol-123').AndRaise(
|
||||
clients.cinderclient.exceptions.NotFound('Not found'))
|
||||
self.m.ReplayAll()
|
||||
|
||||
t = template_format.parse(volume_template)
|
||||
@ -148,6 +153,8 @@ class VolumeTest(HeatTestCase):
|
||||
fv.status = 'in-use'
|
||||
self.assertRaises(exception.ResourceFailure,
|
||||
scheduler.TaskRunner(rsrc.destroy))
|
||||
|
||||
self._stubout_delete_volume(fv)
|
||||
fv.status = 'available'
|
||||
scheduler.TaskRunner(rsrc.destroy)()
|
||||
|
||||
@ -420,7 +427,7 @@ class VolumeTest(HeatTestCase):
|
||||
self.m.StubOutWithMock(self.cinder_fc.backups, 'create')
|
||||
self.cinder_fc.backups.create('vol-123').AndReturn(fb)
|
||||
self.cinder_fc.volumes.get('vol-123').AndReturn(fv)
|
||||
self.cinder_fc.volumes.delete('vol-123').AndReturn(None)
|
||||
|
||||
self.m.ReplayAll()
|
||||
|
||||
t = template_format.parse(volume_template)
|
||||
@ -429,6 +436,7 @@ class VolumeTest(HeatTestCase):
|
||||
|
||||
rsrc = self.create_volume(t, stack, 'DataVolume')
|
||||
|
||||
self._stubout_delete_volume(fv)
|
||||
scheduler.TaskRunner(rsrc.destroy)()
|
||||
|
||||
self.m.VerifyAll()
|
||||
@ -466,7 +474,6 @@ class VolumeTest(HeatTestCase):
|
||||
self._mock_create_volume(fv, stack_name)
|
||||
|
||||
self.cinder_fc.volumes.get('vol-123').AndReturn(fv)
|
||||
self.cinder_fc.volumes.delete('vol-123').AndReturn(None)
|
||||
|
||||
self.m.ReplayAll()
|
||||
|
||||
@ -481,6 +488,7 @@ class VolumeTest(HeatTestCase):
|
||||
create = scheduler.TaskRunner(rsrc.create)
|
||||
self.assertRaises(exception.ResourceFailure, create)
|
||||
|
||||
self._stubout_delete_volume(fv)
|
||||
scheduler.TaskRunner(rsrc.destroy)()
|
||||
|
||||
self.m.VerifyAll()
|
||||
@ -736,6 +744,9 @@ class FakeVolume(object):
|
||||
def update(self, **kw):
|
||||
pass
|
||||
|
||||
def delete(self):
|
||||
pass
|
||||
|
||||
|
||||
class FakeLatencyVolume(object):
|
||||
status = 'attaching'
|
||||
|
Loading…
Reference in New Issue
Block a user