Пример #1
0
 def test_get_changes(self):
     nodes, purged_nodes, checkpoint, reset = metadata.get_changes(include_purged=False)
     self.assertGreaterEqual(len(nodes), 1)
     self.assertEqual(len(purged_nodes), 0)
     self.assertTrue(reset)
     nodes, purged_nodes, checkpoint, reset = metadata.get_changes(checkpoint=checkpoint)
     self.assertEqual(len(nodes), 0)
     self.assertEqual(len(purged_nodes), 0)
     self.assertFalse(reset)
Пример #2
0
 def test_get_changes(self):
     nodes, purged_nodes, checkpoint, reset = metadata.get_changes(
         include_purged=False)
     self.assertGreaterEqual(len(nodes), 1)
     self.assertEqual(len(purged_nodes), 0)
     self.assertTrue(reset)
     nodes, purged_nodes, checkpoint, reset = metadata.get_changes(
         checkpoint=checkpoint)
     self.assertEqual(len(nodes), 0)
     self.assertEqual(len(purged_nodes), 0)
     self.assertFalse(reset)
Пример #3
0
 def testChangesMissingEnd(self):
     httpretty.register_uri(httpretty.POST, common.get_metadata_url() + 'changes',
                            body='{"checkpoint": "foo", "reset": true, "nodes": [], "statusCode": 200}\n')
     nodes, purged_nodes, checkpoint, reset = metadata.get_changes()
     self.assertEqual(len(nodes), 0)
     self.assertEqual(len(purged_nodes), 0)
     self.assertEqual(checkpoint, 'foo')
     self.assertTrue(reset)
Пример #4
0
 def testChanges(self):
     httpretty.register_uri(httpretty.POST, common.get_metadata_url() + 'changes',
                            body='{"checkpoint": "foo", "reset": true, '
                                 '"nodes": [ {"kind": "FILE", "status": "TRASH"} ], "statusCode": 200}\n'
                                 '{"end": true}')
     nodes, purged_nodes, checkpoint, reset = metadata.get_changes()
     self.assertEqual(len(nodes), 1)
     self.assertEqual(len(purged_nodes), 0)
     self.assertEqual(checkpoint, 'foo')
     self.assertTrue(reset)
Пример #5
0
 def testChanges(self):
     httpretty.register_uri(
         httpretty.POST,
         common.get_metadata_url() + 'changes',
         body='{"checkpoint": "foo", "reset": true, '
         '"nodes": [ {"kind": "FILE", "status": "TRASH"} ], "statusCode": 200}\n'
         '{"end": true}')
     nodes, purged_nodes, checkpoint, reset = metadata.get_changes()
     self.assertEqual(len(nodes), 1)
     self.assertEqual(len(purged_nodes), 0)
     self.assertEqual(checkpoint, 'foo')
     self.assertTrue(reset)
Пример #6
0
 def testChangesMissingEnd(self):
     httpretty.register_uri(
         httpretty.POST,
         common.get_metadata_url() + 'changes',
         body=
         '{"checkpoint": "foo", "reset": true, "nodes": [], "statusCode": 200}\n'
     )
     nodes, purged_nodes, checkpoint, reset = metadata.get_changes()
     self.assertEqual(len(nodes), 0)
     self.assertEqual(len(purged_nodes), 0)
     self.assertEqual(checkpoint, 'foo')
     self.assertTrue(reset)
Пример #7
0
def sync_node_list(full=False):
    cp = sync.get_checkpoint()

    try:
        nodes, purged, ncp, full = metadata.get_changes(checkpoint=None if full else cp, include_purged=not full)
    except RequestError as e:
        logger.critical('Sync failed.')
        print(e)
        return 1

    if full:
        db.drop_all()
        db.init(CACHE_PATH)
    else:
        sync.remove_purged(purged)

    if len(nodes) > 0:
        sync.insert_nodes(nodes)
    sync.set_checkpoint(ncp)
    return
Пример #8
0
def sync_node_list(full=False):
    cp = db.KeyValueStorage.get(CacheConsts.CHECKPOINT_KEY) if not full else None

    try:
        nodes, purged, ncp, full = metadata.get_changes(checkpoint=cp, include_purged=not not cp)
    except RequestError as e:
        logger.critical('Sync failed.')
        print(e)
        return 1

    if full:
        db.drop_all()
        db.init(CACHE_PATH)
    else:
        sync.remove_purged(purged)

    if len(nodes) > 0:
        sync.insert_nodes(nodes, partial=not full)
    db.KeyValueStorage.update(
        {CacheConsts.CHECKPOINT_KEY: ncp, CacheConsts.LAST_SYNC_KEY: time.time()})
    return
Пример #9
0
def sync_node_list(full=False):
    cp = sync.get_checkpoint()

    try:
        nodes, purged, ncp, full = metadata.get_changes(
            checkpoint=None if full else cp, include_purged=not full)
    except RequestError as e:
        logger.critical('Sync failed.')
        print(e)
        return 1

    if full:
        db.drop_all()
        db.init(CACHE_PATH)
    else:
        sync.remove_purged(purged)

    if len(nodes) > 0:
        sync.insert_nodes(nodes)
    sync.set_checkpoint(ncp)
    return
Пример #10
0
def sync_node_list(full=False):
    cp = db.KeyValueStorage.get(CacheConsts.CHECKPOINT_KEY) if not full else None

    try:
        nodes, purged, ncp, full = metadata.get_changes(checkpoint=cp, include_purged=not not cp)
    except RequestError as e:
        logger.critical('Sync failed.')
        print(e)
        return ERROR_RETVAL

    if full:
        db.drop_all()
        db.init(CACHE_PATH)
    else:
        sync.remove_purged(purged)

    if len(nodes) > 0:
        sync.insert_nodes(nodes, partial=not full)
    db.KeyValueStorage.update({CacheConsts.LAST_SYNC_KEY: time.time()})

    if len(nodes) > 0 or len(purged) > 0:
        db.KeyValueStorage.update({CacheConsts.CHECKPOINT_KEY: ncp})