Ejemplo n.º 1
0
def test_not_rebuilding(grpc_client):  # NOQA
    grpc_client.replica_create(size=SIZE_STR)
    grpc_client.replica_open()

    r = grpc_client.replica_snapshot(
        name='001', created=datetime.datetime.utcnow().isoformat())
    assert r.state == 'dirty'
    assert not r.rebuilding
    assert r.size == SIZE_STR
    assert r.sectorSize == 512
    assert r.parent == 'volume-snap-001.img'
    assert r.head == 'volume-head-001.img'
    assert r.chain == ['volume-head-001.img', 'volume-snap-001.img']

    r = grpc_client.rebuilding_set(rebuilding=True)
    assert r.state == 'rebuilding'
    assert r.rebuilding
    assert r.size == SIZE_STR
    assert r.sectorSize == 512
    assert r.parent == 'volume-snap-001.img'
    assert r.head == 'volume-head-001.img'
    assert r.chain == ['volume-head-001.img', 'volume-snap-001.img']

    r = grpc_client.rebuilding_set(rebuilding=False)
    assert r.state == 'dirty'
    assert not r.rebuilding
    assert r.size == SIZE_STR
    assert r.sectorSize == 512
    assert r.parent == 'volume-snap-001.img'
    assert r.head == 'volume-head-001.img'
    assert r.chain == ['volume-head-001.img', 'volume-snap-001.img']
Ejemplo n.º 2
0
def test_remove_last_disk(grpc_client):  # NOQA
    grpc_client.replica_create(size=SIZE_STR)
    grpc_client.replica_open()

    grpc_client.replica_snapshot(
        name='000', created=datetime.datetime.utcnow().isoformat())
    r = grpc_client.replica_snapshot(
        name='001', created=datetime.datetime.utcnow().isoformat())
    assert r.chain == [
        'volume-head-002.img', 'volume-snap-001.img', 'volume-snap-000.img'
    ]

    grpc_client.disk_mark_as_removed(name='volume-snap-000.img')

    ops = grpc_client.disk_prepare_remove(
        name='volume-snap-000.img').operations
    assert len(ops) == 2
    assert ops[0].action == "coalesce"
    assert ops[0].source == "volume-snap-000.img"
    assert ops[0].target == "volume-snap-001.img"
    assert ops[1].action == "replace"
    assert ops[1].source == "volume-snap-000.img"
    assert ops[1].target == "volume-snap-001.img"

    r = grpc_client.disk_remove(name='volume-snap-000.img')
    assert r.state == 'dirty'
    assert not r.rebuilding
    assert r.size == SIZE_STR
    assert r.sectorSize == 512
    assert r.head == 'volume-head-002.img'
    assert r.parent == 'volume-snap-001.img'
    assert r.chain == ['volume-head-002.img', 'volume-snap-001.img']
Ejemplo n.º 3
0
def test_open(grpc_client):  # NOQA
    r = grpc_client.replica_get()
    assert r.state == 'initial'
    assert r.size == '0'
    assert r.sectorSize == 0
    assert r.parent == ''
    assert r.head == ''

    r = grpc_client.replica_create(size=SIZE_STR)

    assert r.state == 'closed'
    assert not r.dirty
    assert not r.rebuilding
    assert r.size == SIZE_STR
    assert r.sectorSize == 512
    assert r.parent == ''
    assert r.head == 'volume-head-000.img'

    r = grpc_client.replica_open()

    assert r.state == 'open'
    assert not r.dirty
    assert not r.rebuilding
    assert r.size == SIZE_STR
    assert r.sectorSize == 512
    assert r.parent == ''
    assert r.head == 'volume-head-000.img'
Ejemplo n.º 4
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'
Ejemplo n.º 5
0
def test_reload(grpc_client):  # NOQA
    grpc_client.replica_create(size=SIZE_STR)
    grpc_client.replica_open()

    r = grpc_client.replica_get()
    assert r.chain == ['volume-head-000.img']

    r = grpc_client.replica_snapshot(
        name='000', created=datetime.datetime.utcnow().isoformat())
    assert r.chain == ['volume-head-001.img', 'volume-snap-000.img']
    r = grpc_client.replica_snapshot(
        name='001', created=datetime.datetime.utcnow().isoformat())
    assert r.chain == [
        'volume-head-002.img', 'volume-snap-001.img', 'volume-snap-000.img'
    ]

    r = grpc_client.disk_remove(name='volume-snap-000.img')
    assert r.state == 'dirty'
    assert r.size == SIZE_STR
    assert r.sectorSize == 512
    assert r.head == 'volume-head-002.img'
    assert r.parent == 'volume-snap-001.img'
    assert r.chain == ['volume-head-002.img', 'volume-snap-001.img']

    r = grpc_client.replica_reload()
    assert r.state == 'dirty'
    assert r.size == SIZE_STR
    assert r.sectorSize == 512
    assert r.chain == ['volume-head-002.img', 'volume-snap-001.img']
    assert r.head == 'volume-head-002.img'
    assert r.parent == 'volume-snap-001.img'

    grpc_client.replica_close()
    r = grpc_client.replica_open()
    assert r.state == 'open'
    assert r.size == SIZE_STR
    assert r.sectorSize == 512
    assert r.chain == ['volume-head-002.img', 'volume-snap-001.img']
    assert r.head == 'volume-head-002.img'
    assert r.parent == 'volume-snap-001.img'
Ejemplo n.º 6
0
def test_remove_disk(grpc_client):  # NOQA
    grpc_client.replica_create(size=SIZE_STR)
    grpc_client.replica_open()

    grpc_client.replica_snapshot(
        name='000', created=datetime.datetime.utcnow().isoformat())
    r = grpc_client.replica_snapshot(
        name='001', created=datetime.datetime.utcnow().isoformat())
    assert r.chain == [
        'volume-head-002.img', 'volume-snap-001.img', 'volume-snap-000.img'
    ]

    # idempotent
    grpc_client.disk_mark_as_removed(name='003')
    grpc_client.disk_prepare_remove(name='003')

    with pytest.raises(grpc.RpcError) as e:
        grpc_client.disk_mark_as_removed(name='volume-head-002.img')
    assert "Can not mark the active" in str(e.value)

    with pytest.raises(grpc.RpcError) as e:
        grpc_client.disk_prepare_remove(name='volume-head-002.img')
    assert "Can not delete the active" in str(e.value)

    grpc_client.disk_mark_as_removed(name='001')
    ops = grpc_client.disk_prepare_remove(name='001').operations
    assert len(ops) == 0

    r = grpc_client.disk_remove(name='volume-snap-001.img')
    assert r.state == 'dirty'
    assert not r.rebuilding
    assert r.size == SIZE_STR
    assert r.sectorSize == 512
    assert r.head == 'volume-head-002.img'
    assert r.parent == 'volume-snap-000.img'
    assert r.chain == ['volume-head-002.img', 'volume-snap-000.img']
Ejemplo n.º 7
0
def test_reload_simple(grpc_client):  # NOQA
    grpc_client.replica_create(size=SIZE_STR)

    r = grpc_client.replica_open()
    assert r.state == 'open'
    assert not r.rebuilding
    assert r.size == SIZE_STR
    assert r.sectorSize == 512
    assert r.parent == ''
    assert r.head == 'volume-head-000.img'

    r = grpc_client.replica_reload()
    assert r.state == 'open'
    assert r.size == SIZE_STR
    assert r.sectorSize == 512
    assert r.parent == ''
    assert r.head == 'volume-head-000.img'
Ejemplo n.º 8
0
def test_snapshot(grpc_client):  # NOQA
    grpc_client.replica_create(size=SIZE_STR)

    r = grpc_client.replica_open()

    assert r.state == 'open'
    assert not r.dirty
    assert not r.rebuilding
    assert r.size == SIZE_STR
    assert r.sectorSize == 512
    assert r.parent == ''
    assert r.head == 'volume-head-000.img'

    r = grpc_client.replica_snapshot(
        name='000',
        created=datetime.datetime.utcnow().isoformat(),
        labels={
            "name": "000",
            "key": "value"
        })
    assert r.state == 'dirty'
    assert r.dirty
    assert not r.rebuilding
    assert r.size == SIZE_STR
    assert r.sectorSize == 512
    assert r.disks["volume-snap-000.img"].labels["name"] == "000"
    assert r.disks["volume-snap-000.img"].labels["key"] == "value"

    r = grpc_client.replica_snapshot(
        name='001', created=datetime.datetime.utcnow().isoformat())

    assert r.state == 'dirty'
    assert r.dirty
    assert not r.rebuilding
    assert r.size == SIZE_STR
    assert r.sectorSize == 512
    assert r.head == 'volume-head-002.img'
    assert r.parent == 'volume-snap-001.img'
    assert r.chain == [
        'volume-head-002.img', 'volume-snap-001.img', 'volume-snap-000.img'
    ]
Ejemplo n.º 9
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"