Exemplo n.º 1
0
def test_replica_delete(grpc_client):  # NOQA
    f1 = create_backend_file()
    f2 = create_backend_file()
    f3 = create_backend_file()
    r1 = grpc_client.replica_create(address='file://' + f1)
    grpc_client.replica_update(r1.address, mode='RW')
    r2 = grpc_client.replica_create(address='file://' + f2)
    grpc_client.replica_update(r2.address, mode='RW')
    r3 = grpc_client.replica_create(address='file://' + f3)
    grpc_client.replica_update(r3.address, mode='RW')

    rs = grpc_client.replica_list()
    assert len(rs) == 3

    grpc_client.replica_delete(r1.address)
    rs = grpc_client.replica_list()
    assert len(rs) == 2

    grpc_client.replica_delete(r1.address)
    rs = grpc_client.replica_list()
    assert len(rs) == 2

    grpc_client.replica_delete(r2.address)
    rs = grpc_client.replica_list()
    assert len(rs) == 1

    grpc_client.replica_delete(r3.address)
    rs = grpc_client.replica_list()
    assert len(rs) == 0

    cleanup_backend_file([f1, f2, f3])
Exemplo n.º 2
0
def test_replica_create(grpc_client):  # NOQA
    f1 = create_backend_file()
    r1 = 'file://' + f1
    replica = grpc_client.replica_create(address=r1)
    assert replica.address == r1

    grpc_client.replica_create(address=r1)
    grpc_client.replica_create(address=r1)

    rs = grpc_client.replica_list()
    assert len(rs) == 1
    assert rs[0].address == r1
    assert rs[0].mode == 'WO'

    f2 = create_backend_file()
    r2 = 'file://' + f2
    with pytest.raises(grpc.RpcError) as e:
        grpc_client.replica_create(address=r2)
    assert 'Can only have one WO replica at a time' in str(e.value)

    r = grpc_client.replica_update(rs[0].address, mode='RW')
    assert r.mode == 'RW'

    replica2 = grpc_client.replica_create(address=r2)
    assert replica2.address == r2

    rs = grpc_client.replica_list()
    assert len(rs) == 2

    cleanup_backend_file([f1, f2])
Exemplo n.º 3
0
def test_shutdown(grpc_client):  # NOQA
    v = grpc_client.volume_get()
    assert v.replicaCount == 0

    f1 = create_backend_file()
    f2 = create_backend_file()
    addresses = ['file://' + f1, 'file://' + f2]
    v = grpc_client.volume_start(replicas=addresses)
    assert v.replicaCount == 2

    v = grpc_client.volume_shutdown()
    assert v.replicaCount == 0

    rs = grpc_client.replica_list()
    assert len(rs) == 0

    cleanup_backend_file([f1, f2])
Exemplo n.º 4
0
def test_start(grpc_client):  # NOQA
    v = grpc_client.volume_get()
    assert v.replicaCount == 0

    f1 = create_backend_file()
    f2 = create_backend_file()
    addresses = ['file://' + f1, 'file://' + f2]
    v = grpc_client.volume_start(replicas=addresses)

    rs = grpc_client.replica_list()
    assert len(rs) == 2
    assert v.replicaCount == 2

    found_addresses = [r.address for r in rs]
    assert set(found_addresses) == set(addresses)

    cleanup_backend_file([f1, f2])
Exemplo n.º 5
0
def test_replica_change(grpc_client):  # NOQA
    f = create_backend_file()
    r1 = grpc_client.replica_create(address='file://' + f)
    assert r1.mode == 'WO'

    r1 = grpc_client.replica_update(r1.address, mode='RW')
    assert r1.mode == 'RW'

    r1 = grpc_client.replica_get(r1.address)
    assert r1.mode == 'RW'

    cleanup_backend_file([f])