Ejemplo n.º 1
0
def test_replicate_file_no_instances(app):
    """When a file has no instances matching the config, replicate_file does
    nothing."""
    with app.app_context():
        # us-west-1 isn't in cfg['TOOLTOOL_REGIONS']
        file = add_file_row(len(DATA), DATA_DIGEST, instances=['us-west-1'])
        grooming.replicate_file(app.db.session('relengapi'), file)
    assert_file_instances(app, DATA_DIGEST, ['us-west-1'])
Ejemplo n.º 2
0
def test_replicate_file_no_instances(app):
    """When a file has no instances matching the config, replicate_file does
    nothing."""
    with app.app_context():
        # us-west-1 isn't in cfg['TOOLTOOL_REGIONS']
        file = add_file_row(len(DATA), DATA_DIGEST, instances=['us-west-1'])
        grooming.replicate_file(app.db.session('relengapi'), file)
    assert_file_instances(app, DATA_DIGEST, ['us-west-1'])
Ejemplo n.º 3
0
def test_replicate_file(app):
    """Replicating a file initiates copy operations from regions where the file
    exists to regions where it does not."""
    with app.app_context():
        file = add_file_row(len(DATA), DATA_DIGEST, instances=['us-east-1'])
        make_key(app, 'us-east-1', 'tt-use1', util.keyname(DATA_DIGEST), DATA)
        make_bucket(app, 'us-west-2', 'tt-usw2')
        grooming.replicate_file(app.db.session('relengapi'), file)
    assert_file_instances(app, DATA_DIGEST, ['us-east-1', 'us-west-2'])
    assert key_exists(app, 'us-east-1', 'tt-use1', util.keyname(DATA_DIGEST))
    assert key_exists(app, 'us-west-2', 'tt-usw2', util.keyname(DATA_DIGEST))
Ejemplo n.º 4
0
def test_replicate_file(app):
    """Replicating a file initiates copy operations from regions where the file
    exists to regions where it does not."""
    with app.app_context():
        file = add_file_row(len(DATA), DATA_DIGEST, instances=['us-east-1'])
        make_key(app, 'us-east-1', 'tt-use1', util.keyname(DATA_DIGEST), DATA)
        make_bucket(app, 'us-west-2', 'tt-usw2')
        grooming.replicate_file(app.db.session('relengapi'), file)
    assert_file_instances(app, DATA_DIGEST, ['us-east-1', 'us-west-2'])
    assert key_exists(app, 'us-east-1', 'tt-use1', util.keyname(DATA_DIGEST))
    assert key_exists(app, 'us-west-2', 'tt-usw2', util.keyname(DATA_DIGEST))
Ejemplo n.º 5
0
def test_replicate_file_already_exists(app):
    """If a target object already exists in S3 during replication, it is
    deleted rather than being trusted to be correct."""
    with app.app_context():
        file = add_file_row(len(DATA), DATA_DIGEST, instances=['us-east-1'])
        make_key(app, 'us-east-1', 'tt-use1', util.keyname(DATA_DIGEST), DATA)
        make_key(app, 'us-west-2', 'tt-usw2', util.keyname(DATA_DIGEST), "BAD")
        grooming.replicate_file(app.db.session('relengapi'), file)
    assert_file_instances(app, DATA_DIGEST, ['us-east-1', 'us-west-2'])
    assert key_exists(app, 'us-east-1', 'tt-use1', util.keyname(DATA_DIGEST))
    k = key_exists(app, 'us-west-2', 'tt-usw2', util.keyname(DATA_DIGEST))
    eq_(k.get_contents_as_string(), DATA)  # not "BAD"
Ejemplo n.º 6
0
def test_replicate_file_already_exists(app):
    """If a target object already exists in S3 during replication, it is
    deleted rather than being trusted to be correct."""
    with app.app_context():
        file = add_file_row(len(DATA), DATA_DIGEST, instances=['us-east-1'])
        make_key(app, 'us-east-1', 'tt-use1', util.keyname(DATA_DIGEST), DATA)
        make_key(app, 'us-west-2', 'tt-usw2', util.keyname(DATA_DIGEST), "BAD")
        grooming.replicate_file(app.db.session('relengapi'), file)
    assert_file_instances(app, DATA_DIGEST, ['us-east-1', 'us-west-2'])
    assert key_exists(app, 'us-east-1', 'tt-use1', util.keyname(DATA_DIGEST))
    k = key_exists(app, 'us-west-2', 'tt-usw2', util.keyname(DATA_DIGEST))
    eq_(k.get_contents_as_string(), DATA)  # not "BAD"
Ejemplo n.º 7
0
def test_replicate_file_race(app):
    """If, while replicating a file, another replication completes and the
    subsequent database insert fails, the replication function nonetheless
    succeeds."""
    with app.app_context():
        file = add_file_row(len(DATA), DATA_DIGEST, instances=['us-east-1'])
        make_key(app, 'us-east-1', 'tt-use1', util.keyname(DATA_DIGEST), DATA)
        make_bucket(app, 'us-west-2', 'tt-usw2')

        def test_shim():
            session = app.db.session('relengapi')
            session.add(tables.FileInstance(file=file, region='us-west-2'))
            session.commit()
        grooming.replicate_file(app.db.session('relengapi'), file,
                                _test_shim=test_shim)
    assert_file_instances(app, DATA_DIGEST, ['us-east-1', 'us-west-2'])
Ejemplo n.º 8
0
def test_replicate_file_race(app):
    """If, while replicating a file, another replication completes and the
    subsequent database insert fails, the replication function nonetheless
    succeeds."""
    with app.app_context():
        file = add_file_row(len(DATA), DATA_DIGEST, instances=['us-east-1'])
        make_key(app, 'us-east-1', 'tt-use1', util.keyname(DATA_DIGEST), DATA)
        make_bucket(app, 'us-west-2', 'tt-usw2')

        def test_shim():
            session = app.db.session('relengapi')
            session.add(tables.FileInstance(file=file, region='us-west-2'))
            session.commit()

        grooming.replicate_file(app.db.session('relengapi'),
                                file,
                                _test_shim=test_shim)
    assert_file_instances(app, DATA_DIGEST, ['us-east-1', 'us-west-2'])