def allocate(self, context, resource_id):
     resource = db.resource_get_by_id(resource_id)
     if resource['processing']:
         raise exceptions.ResourceProcessing(resource_id=resource_id)
     if resource['allocated']:
         raise exceptions.ResourceAllocated(resource_id=resource_id)
     resource = db.resource_update(resource_id, {'allocated': True,
                                                 'processing': False})
     return resource
 def deallocate(self, context, resource_id):
     resource = db.resource_get_by_id(resource_id)
     if resource['processing']:
         raise exceptions.ResourceProcessing(resource_id=resource_id)
     resource = db.resource_update(resource_id, {'allocated': False,
                                                 'processing': True})
     task = tasks.WipeTask(resource)
     self.task_queue.push(task)
     return resource
 def delete(self, context, resource_id, force=False):
     resource = db.resource_get_by_id(resource_id)
     if not force:
         if resource['processing']:
             raise exceptions.ResourceProcessing(resource_id=resource_id)
         if resource['allocated']:
             raise exceptions.ResourceAllocated(resource_id=resource_id)
     resource = db.resource_update(resource_id, {'processing': True})
     task = tasks.DeleteTask(resource, force)
     self.task_queue.push(task)
 def test_update(self):
     args = ['fake-resource-id', {}]
     db.resource_update(*args)
     self.mock.resource_update.assert_with_call(args)