'Basic cleanup that doesn\'t touch other thread\'s claimed works.'

def test_do_cleanup_not_cleaning_already_claimed_by_us(self):

    original_time = timeutils.utcnow()
    other_thread_claimed_time = timeutils.utcnow()
    vol = utils.create_volume(self.context, status='creating')
    worker1 = db.worker_create(self.context, status='creating', resource_type='Volume', resource_id=vol.id, service_id=self.service.id, updated_at=original_time)
    worker1 = db.worker_get(self.context, id=worker1.id)
    vol2 = utils.create_volume(self.context, status='deleting')
    worker2 = db.worker_create(self.context, status='deleting', resource_type='Volume', resource_id=vol2.id, service_id=self.service.id, updated_at=other_thread_claimed_time)
    worker2 = db.worker_get(self.context, id=worker2.id)
    worker2.updated_at = original_time
    clean_req = objects.CleanupRequest(service_id=self.service.id)
    mngr = FakeManager(self.service.id)
    with mock.patch('cinder.db.worker_get_all') as get_all_mock:
        get_all_mock.return_value = [worker1, worker2]
        mngr.do_cleanup(self.context, clean_req)
    workers = db.worker_get_all(self.context)
    self.assertEqual(1, len(workers))
    self.assertEqual(worker2.id, workers[0].id)
    vol.refresh()
    self.assertEqual('creating_cleaned', vol.status)
    vol2.refresh()
    self.assertEqual('deleting', vol2.status)
