def sync_single_rhic(uuid): """ Will sync data on a single RHIC specified by the 'uuid' @param uuid: uuid of a rhic to sync from our parent @type uuid: str @return: """ start = time.time() _LOG.info("Sync RHIC uuid=%s" % (uuid)) status_code = identity.sync_single_rhic_blocking(uuid) identity_lookup.complete_rhic_lookup_task(uuid, status_code) end = time.time() _LOG.info("Sync RHIC uuid=%s task completed with status_code '%s' in %s seconds" % \ (uuid, status_code, end-start)) return status_code
def test_complete_rhic_lookup_task_200(self): task = RHICLookupTask(uuid="11a1aa11-a11a-1a11-111a-a11111111111", completed=False, task_id=None) task.save() found = RHICLookupTask.objects() self.assertEquals(len(found), 1) self.assertEquals(found[0].uuid, task.uuid) # Mark as '200', a successful complete which will remove the task from the lookup db accepted = 200 ret_val = identity_lookup.complete_rhic_lookup_task(task.uuid, accepted) self.assertIsNone(ret_val) found = RHICLookupTask.objects() self.assertEquals(len(found), 0)
def test_complete_rhic_lookup_task_unexpected_value(self): task = RHICLookupTask(uuid="11a1aa11-a11a-1a11-111a-a11111111111", completed=False, task_id=None) task.save() found = RHICLookupTask.objects() self.assertEquals(len(found), 1) self.assertEquals(found[0].uuid, task.uuid) # Mark task with an odd unexpected value # We expect the task to be deleted and the unexpected value is not cached. unexpected = 123 ret_val = identity_lookup.complete_rhic_lookup_task(task.uuid, unexpected) self.assertIsNone(ret_val) found = RHICLookupTask.objects() self.assertEquals(len(found), 0)
def test_complete_rhic_lookup_task_202(self): task = RHICLookupTask(uuid="11a1aa11-a11a-1a11-111a-a11111111111", completed=False, task_id=None) task.save() found = RHICLookupTask.objects() self.assertEquals(len(found), 1) self.assertEquals(found[0].uuid, task.uuid) # Mark as '202', meaning we haven't found an answer yet, let the tasks continue # task should remain in DB, should be marked as 'completed=False' in_progress = 202 ret_val = identity_lookup.complete_rhic_lookup_task(task.uuid, in_progress) self.assertIsNone(ret_val) found = RHICLookupTask.objects() self.assertEquals(len(found), 1) self.assertEquals(found[0].uuid, task.uuid) self.assertIsNone(found[0].task_id) self.assertEquals(found[0].status_code, in_progress) self.assertFalse(found[0].completed)
def test_complete_rhic_lookup_task_404(self): task = RHICLookupTask(uuid="11a1aa11-a11a-1a11-111a-a11111111111", completed=False, task_id=None) task.save() found = RHICLookupTask.objects() self.assertEquals(len(found), 1) self.assertEquals(found[0].uuid, task.uuid) # Mark as '404', task finished and received answer RHIC is unknown # task should be cached in DB with '404' status_code # it should be marked as 'completed=True' not_found = 404 ret_val = identity_lookup.complete_rhic_lookup_task(task.uuid, not_found) self.assertIsNone(ret_val) found = RHICLookupTask.objects() self.assertEquals(len(found), 1) self.assertEquals(found[0].uuid, task.uuid) self.assertIsNone(found[0].task_id) self.assertEquals(found[0].status_code, not_found) self.assertTrue(found[0].completed)