예제 #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])
예제 #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])
예제 #3
0
def test_replica_failure_detection(
        grpc_controller_client,  # NOQA
        grpc_replica_client,  # NOQA
        grpc_replica_client2):  # NOQA
    open_replica(grpc_replica_client)
    open_replica(grpc_replica_client2)

    r1_url = grpc_replica_client.url
    r2_url = grpc_replica_client2.url
    v = grpc_controller_client.volume_start(replicas=[
        r1_url,
        r2_url,
    ])
    assert v.replicaCount == 2

    # wait for initial read/write period to pass
    time.sleep(2)

    cleanup_replica(grpc_replica_client)

    detected = False
    for i in range(10):
        replicas = grpc_controller_client.replica_list()
        assert len(replicas) == 2
        for r in replicas:
            if r.address == r1_url and r.mode == 'ERR':
                detected = True
                break
        if detected:
            break
        time.sleep(1)
    assert detected
예제 #4
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])
예제 #5
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])
예제 #6
0
def test_replica_add_after_rebuild_failed(
        bin,
        grpc_controller_client,  # NOQA
        grpc_replica_client,  # NOQA
        grpc_replica_client2):  # NOQA
    open_replica(grpc_replica_client)
    open_replica(grpc_replica_client2)

    grpc_replica_client.replica_open()
    grpc_replica_client.replica_snapshot(
        name='000', created=datetime.datetime.utcnow().isoformat())
    grpc_replica_client.replica_close()

    cmd = [
        bin, '--debug', '--url', grpc_controller_client.address, 'add-replica',
        grpc_replica_client.url
    ]
    subprocess.check_call(cmd)

    volume = grpc_controller_client.volume_get()
    assert volume.replicaCount == 1

    grpc_replica_client2.replica_open()
    grpc_replica_client2.rebuilding_set(rebuilding=True)
    grpc_replica_client2.replica_close()

    cmd = [
        bin, '--debug', '--url', grpc_controller_client.address, 'add-replica',
        grpc_replica_client2.url
    ]
    subprocess.check_call(cmd)

    volume = grpc_controller_client.volume_get()
    assert volume.replicaCount == 2

    replicas = grpc_controller_client.replica_list()
    assert len(replicas) == 2

    for r in replicas:
        assert r.mode == 'RW'
예제 #7
0
def test_replica_add_rebuild(
        bin,
        grpc_controller_client,  # NOQA
        grpc_replica_client,  # NOQA
        grpc_replica_client2):  # NOQA
    open_replica(grpc_replica_client)
    open_replica(grpc_replica_client2)

    snap0 = "000"
    snap1 = "001"
    grpc_replica_client.replica_open()
    createtime0 = getNow()
    grpc_replica_client.replica_snapshot(name=snap0,
                                         created=createtime0,
                                         labels={
                                             "name": "snap0",
                                             "key": "value"
                                         })
    createtime1 = getNow()
    r = grpc_replica_client.replica_snapshot(name=snap1,
                                             user_created=True,
                                             created=createtime1)

    r2 = grpc_replica_client2.replica_get()

    assert r.chain == [
        'volume-head-002.img', 'volume-snap-001.img', 'volume-snap-000.img'
    ]

    assert r2.chain != [
        'volume-head-002.img', 'volume-snap-001.img', 'volume-snap-000.img'
    ]

    grpc_replica_client.replica_close()
    cmd = [
        bin, '--debug', '--url', grpc_controller_client.address, 'add-replica',
        grpc_replica_client.url
    ]
    subprocess.check_call(cmd)

    volume = grpc_controller_client.volume_get()
    assert volume.replicaCount == 1

    cmd = [
        bin, '--debug', '--url', grpc_controller_client.address, 'add-replica',
        grpc_replica_client2.url
    ]
    subprocess.check_call(cmd)

    volume = grpc_controller_client.volume_get()
    assert volume.replicaCount == 2

    replicas = grpc_controller_client.replica_list()
    assert len(replicas) == 2

    for r in replicas:
        assert r.mode == 'RW'

    cmd = [
        bin, '--debug', '--url', grpc_controller_client.address, 'snapshot',
        'info'
    ]
    output = subprocess.check_output(cmd)
    info = json.loads(output)

    # two existing snapshots and one system snapshot due to rebuild
    # and volume-head
    volumehead = "volume-head"
    assert len(info) == 4
    for name in info:
        if name != snap0 and name != snap1 and name != volumehead:
            snapreb = name
            break

    head_info = info[volumehead]
    assert head_info["name"] == volumehead
    assert head_info["parent"] == snapreb
    assert not head_info["children"]
    assert head_info["removed"] is False
    assert head_info["usercreated"] is False
    assert head_info["size"] == "0"

    snapreb_info = info[snapreb]
    assert snapreb_info["name"] == snapreb
    assert snapreb_info["parent"] == snap1
    assert volumehead in snapreb_info["children"]
    assert snapreb_info["removed"] is False
    assert snapreb_info["usercreated"] is False
    assert snapreb_info["size"] == "0"

    snap1_info = info[snap1]
    assert snap1_info["name"] == snap1
    assert snap1_info["parent"] == snap0
    assert snapreb in snap1_info["children"]
    assert snap1_info["removed"] is False
    assert snap1_info["usercreated"] is True
    assert snap1_info["created"] == createtime1
    assert snap1_info["size"] == "0"

    snap0_info = info[snap0]
    assert snap0_info["name"] == snap0
    assert snap0_info["parent"] == ""
    assert snap1 in snap0_info["children"]
    assert snap0_info["removed"] is False
    assert snap0_info["usercreated"] is False
    assert snap0_info["created"] == createtime0
    assert snap0_info["size"] == "0"
    assert snap0_info["labels"]["name"] == "snap0"
    assert snap0_info["labels"]["key"] == "value"
예제 #8
0
def test_replica_list(grpc_client):  # NOQA
    replicas = grpc_client.replica_list()
    assert len(replicas) == 0