def purge_random_snapshot(longhorn_api_client, volume_name, snapshot_name): volume = longhorn_api_client.by_id_volume(volume_name) volume.snapshotPurge() wait_for_snapshot_purge(longhorn_api_client, volume_name, snapshot_name)
def snapshot_test(client): # NOQA volume = client.by_id_volume(VOLUME_NAME) snap1 = volume.snapshotCreate() snap2 = volume.snapshotCreate() snap3 = volume.snapshotCreate() snapshots = volume.snapshotList() snapMap = {} for snap in snapshots: snapMap[snap["name"]] = snap assert snapMap[snap1["name"]]["name"] == snap1["name"] assert snapMap[snap1["name"]]["removed"] is False assert snapMap[snap2["name"]]["name"] == snap2["name"] assert snapMap[snap2["name"]]["parent"] == snap1["name"] assert snapMap[snap2["name"]]["removed"] is False assert snapMap[snap3["name"]]["name"] == snap3["name"] assert snapMap[snap3["name"]]["parent"] == snap2["name"] assert snapMap[snap3["name"]]["removed"] is False volume.snapshotDelete(name=snap3["name"]) snapshots = volume.snapshotList(volume=VOLUME_NAME) snapMap = {} for snap in snapshots: snapMap[snap["name"]] = snap assert snapMap[snap1["name"]]["name"] == snap1["name"] assert snapMap[snap1["name"]]["removed"] is False assert snapMap[snap2["name"]]["name"] == snap2["name"] assert snapMap[snap2["name"]]["parent"] == snap1["name"] assert snapMap[snap2["name"]]["removed"] is False assert snapMap[snap3["name"]]["name"] == snap3["name"] assert snapMap[snap3["name"]]["parent"] == snap2["name"] assert snapMap[snap3["name"]]["children"] == ["volume-head"] assert snapMap[snap3["name"]]["removed"] is True snap = volume.snapshotGet(name=snap3["name"]) assert snap["name"] == snap3["name"] assert snap["parent"] == snap3["parent"] assert snap["children"] == snap3["children"] assert snap["removed"] is True volume.snapshotRevert(name=snap2["name"]) snapshots = volume.snapshotList(volume=VOLUME_NAME) snapMap = {} for snap in snapshots: snapMap[snap["name"]] = snap assert snapMap[snap1["name"]]["name"] == snap1["name"] assert snapMap[snap1["name"]]["removed"] is False assert snapMap[snap2["name"]]["name"] == snap2["name"] assert snapMap[snap2["name"]]["parent"] == snap1["name"] assert "volume-head" in snapMap[snap2["name"]]["children"] assert snap3["name"] in snapMap[snap2["name"]]["children"] assert snapMap[snap2["name"]]["removed"] is False assert snapMap[snap3["name"]]["name"] == snap3["name"] assert snapMap[snap3["name"]]["parent"] == snap2["name"] assert snapMap[snap3["name"]]["children"] == [] assert snapMap[snap3["name"]]["removed"] is True volume.snapshotDelete(name=snap1["name"]) volume.snapshotDelete(name=snap2["name"]) volume.snapshotPurge() wait_for_snapshot_purge(volume, snap1["name"], snap3["name"]) snapshots = volume.snapshotList(volume=VOLUME_NAME) snapMap = {} for snap in snapshots: snapMap[snap["name"]] = snap assert snap1["name"] not in snapMap assert snap3["name"] not in snapMap # it's the parent of volume-head, so it cannot be purged at this time assert snapMap[snap2["name"]]["name"] == snap2["name"] assert snapMap[snap2["name"]]["parent"] == "" assert "volume-head" in snapMap[snap2["name"]]["children"] assert snapMap[snap2["name"]]["removed"] is True
def snapshot_test(clients, volume_name, base_image): # NOQA for host_id, client in clients.iteritems(): break volume = client.create_volume(name=volume_name, size=SIZE, numberOfReplicas=2, baseImage=base_image) volume = common.wait_for_volume_detached(client, volume_name) assert volume["name"] == volume_name assert volume["size"] == SIZE assert volume["numberOfReplicas"] == 2 assert volume["state"] == "detached" assert volume["baseImage"] == base_image lht_hostId = get_self_host_id() volume = volume.attach(hostId=lht_hostId) volume = common.wait_for_volume_healthy(client, volume_name) volume = client.by_id_volume(volume_name) positions = {} snap1 = volume.snapshotCreate() snap2_data = write_volume_random_data(volume, positions) snap2 = volume.snapshotCreate() snap3_data = write_volume_random_data(volume, positions) snap3 = volume.snapshotCreate() snapshots = volume.snapshotList() snapMap = {} for snap in snapshots: snapMap[snap["name"]] = snap assert snapMap[snap1["name"]]["name"] == snap1["name"] assert snapMap[snap1["name"]]["removed"] is False assert snapMap[snap2["name"]]["name"] == snap2["name"] assert snapMap[snap2["name"]]["parent"] == snap1["name"] assert snapMap[snap2["name"]]["removed"] is False assert snapMap[snap3["name"]]["name"] == snap3["name"] assert snapMap[snap3["name"]]["parent"] == snap2["name"] assert snapMap[snap3["name"]]["removed"] is False volume.snapshotDelete(name=snap3["name"]) check_volume_data(volume, snap3_data) snapshots = volume.snapshotList(volume=volume_name) snapMap = {} for snap in snapshots: snapMap[snap["name"]] = snap assert snapMap[snap1["name"]]["name"] == snap1["name"] assert snapMap[snap1["name"]]["removed"] is False assert snapMap[snap2["name"]]["name"] == snap2["name"] assert snapMap[snap2["name"]]["parent"] == snap1["name"] assert snapMap[snap2["name"]]["removed"] is False assert snapMap[snap3["name"]]["name"] == snap3["name"] assert snapMap[snap3["name"]]["parent"] == snap2["name"] assert len(snapMap[snap3["name"]]["children"]) == 1 assert "volume-head" in snapMap[snap3["name"]]["children"] assert snapMap[snap3["name"]]["removed"] is True snap = volume.snapshotGet(name=snap3["name"]) assert snap["name"] == snap3["name"] assert snap["parent"] == snap3["parent"] assert len(snap3["children"]) == 1 assert len(snap["children"]) == 1 assert "volume-head" in snap3["children"] assert "volume-head" in snap["children"] assert snap["removed"] is True volume.snapshotRevert(name=snap2["name"]) check_volume_data(volume, snap2_data) snapshots = volume.snapshotList(volume=volume_name) snapMap = {} for snap in snapshots: snapMap[snap["name"]] = snap assert snapMap[snap1["name"]]["name"] == snap1["name"] assert snapMap[snap1["name"]]["removed"] is False assert snapMap[snap2["name"]]["name"] == snap2["name"] assert snapMap[snap2["name"]]["parent"] == snap1["name"] assert "volume-head" in snapMap[snap2["name"]]["children"] assert snap3["name"] in snapMap[snap2["name"]]["children"] assert snapMap[snap2["name"]]["removed"] is False assert snapMap[snap3["name"]]["name"] == snap3["name"] assert snapMap[snap3["name"]]["parent"] == snap2["name"] assert len(snapMap[snap3["name"]]["children"]) == 0 assert snapMap[snap3["name"]]["removed"] is True volume.snapshotDelete(name=snap1["name"]) volume.snapshotDelete(name=snap2["name"]) volume.snapshotPurge() wait_for_snapshot_purge(volume, snap1["name"], snap3["name"]) snapshots = volume.snapshotList(volume=volume_name) snapMap = {} for snap in snapshots: snapMap[snap["name"]] = snap assert snap1["name"] not in snapMap assert snap3["name"] not in snapMap # it's the parent of volume-head, so it cannot be purged at this time assert snapMap[snap2["name"]]["name"] == snap2["name"] assert snapMap[snap2["name"]]["parent"] == "" assert "volume-head" in snapMap[snap2["name"]]["children"] assert snapMap[snap2["name"]]["removed"] is True check_volume_data(volume, snap2_data) volume = volume.detach() volume = common.wait_for_volume_detached(client, volume_name) client.delete(volume) volume = wait_for_volume_delete(client, volume_name) volumes = client.list_volume() assert len(volumes) == 0
def snapshot_test(client, volname): volume = client.by_id_volume(volname) vol_rwsize = VOLUME_RWTEST_SIZE positions = {} snap1 = volume.snapshotCreate() snap2_pos = generate_random_pos(vol_rwsize, positions) snap2_wdata = generate_random_data(vol_rwsize) volume_write(volume["endpoint"], snap2_pos, snap2_wdata) snap2 = volume.snapshotCreate() snap3_pos = generate_random_pos(vol_rwsize, positions) snap3_wdata = generate_random_data(vol_rwsize) volume_write(volume["endpoint"], snap3_pos, snap3_wdata) snap3 = volume.snapshotCreate() snapshots = volume.snapshotList() snapMap = {} for snap in snapshots: snapMap[snap["name"]] = snap assert snapMap[snap1["name"]]["name"] == snap1["name"] assert snapMap[snap1["name"]]["removed"] is False assert snapMap[snap2["name"]]["name"] == snap2["name"] assert snapMap[snap2["name"]]["parent"] == snap1["name"] assert snapMap[snap2["name"]]["removed"] is False assert snapMap[snap3["name"]]["name"] == snap3["name"] assert snapMap[snap3["name"]]["parent"] == snap2["name"] assert snapMap[snap3["name"]]["removed"] is False volume.snapshotDelete(name=snap3["name"]) snap3_rdata = volume_read(volume["endpoint"], snap3_pos, len(snap3_wdata)) assert snap3_rdata == snap3_wdata snapshots = volume.snapshotList(volume=volname) snapMap = {} for snap in snapshots: snapMap[snap["name"]] = snap assert snapMap[snap1["name"]]["name"] == snap1["name"] assert snapMap[snap1["name"]]["removed"] is False assert snapMap[snap2["name"]]["name"] == snap2["name"] assert snapMap[snap2["name"]]["parent"] == snap1["name"] assert snapMap[snap2["name"]]["removed"] is False assert snapMap[snap3["name"]]["name"] == snap3["name"] assert snapMap[snap3["name"]]["parent"] == snap2["name"] assert len(snapMap[snap3["name"]]["children"]) == 1 assert "volume-head" in snapMap[snap3["name"]]["children"] assert snapMap[snap3["name"]]["removed"] is True snap = volume.snapshotGet(name=snap3["name"]) assert snap["name"] == snap3["name"] assert snap["parent"] == snap3["parent"] assert len(snap3["children"]) == 1 assert len(snap["children"]) == 1 assert "volume-head" in snap3["children"] assert "volume-head" in snap["children"] assert snap["removed"] is True volume.snapshotRevert(name=snap2["name"]) snap2_rdata = volume_read(volume["endpoint"], snap2_pos, len(snap2_wdata)) assert snap2_rdata == snap2_wdata snapshots = volume.snapshotList(volume=volname) snapMap = {} for snap in snapshots: snapMap[snap["name"]] = snap assert snapMap[snap1["name"]]["name"] == snap1["name"] assert snapMap[snap1["name"]]["removed"] is False assert snapMap[snap2["name"]]["name"] == snap2["name"] assert snapMap[snap2["name"]]["parent"] == snap1["name"] assert "volume-head" in snapMap[snap2["name"]]["children"] assert snap3["name"] in snapMap[snap2["name"]]["children"] assert snapMap[snap2["name"]]["removed"] is False assert snapMap[snap3["name"]]["name"] == snap3["name"] assert snapMap[snap3["name"]]["parent"] == snap2["name"] assert len(snapMap[snap3["name"]]["children"]) == 0 assert snapMap[snap3["name"]]["removed"] is True volume.snapshotDelete(name=snap1["name"]) volume.snapshotDelete(name=snap2["name"]) volume.snapshotPurge() wait_for_snapshot_purge(volume, snap1["name"], snap3["name"]) snapshots = volume.snapshotList(volume=volname) snapMap = {} for snap in snapshots: snapMap[snap["name"]] = snap assert snap1["name"] not in snapMap assert snap3["name"] not in snapMap # it's the parent of volume-head, so it cannot be purged at this time assert snapMap[snap2["name"]]["name"] == snap2["name"] assert snapMap[snap2["name"]]["parent"] == "" assert "volume-head" in snapMap[snap2["name"]]["children"] assert snapMap[snap2["name"]]["removed"] is True snap2_rdata = volume_read(volume["endpoint"], snap2_pos, len(snap2_wdata)) assert snap2_rdata == snap2_wdata
def snapshot_test(clients, volume_name, base_image): # NOQA for host_id, client in clients.iteritems(): break volume = create_and_check_volume(client, volume_name, base_image=base_image) lht_hostId = get_self_host_id() volume = volume.attach(hostId=lht_hostId) volume = common.wait_for_volume_healthy(client, volume_name) volume = client.by_id_volume(volume_name) positions = {} snap1 = volume.snapshotCreate() snap2_data = write_volume_random_data(volume, positions) snap2 = volume.snapshotCreate() snap3_data = write_volume_random_data(volume, positions) snap3 = volume.snapshotCreate() snapshots = volume.snapshotList() snapMap = {} for snap in snapshots: snapMap[snap["name"]] = snap assert snapMap[snap1["name"]]["name"] == snap1["name"] assert snapMap[snap1["name"]]["removed"] is False assert snapMap[snap2["name"]]["name"] == snap2["name"] assert snapMap[snap2["name"]]["parent"] == snap1["name"] assert snapMap[snap2["name"]]["removed"] is False assert snapMap[snap3["name"]]["name"] == snap3["name"] assert snapMap[snap3["name"]]["parent"] == snap2["name"] assert snapMap[snap3["name"]]["removed"] is False volume.snapshotDelete(name=snap3["name"]) check_volume_data(volume, snap3_data) snapshots = volume.snapshotList(volume=volume_name) snapMap = {} for snap in snapshots: snapMap[snap["name"]] = snap assert snapMap[snap1["name"]]["name"] == snap1["name"] assert snapMap[snap1["name"]]["removed"] is False assert snapMap[snap2["name"]]["name"] == snap2["name"] assert snapMap[snap2["name"]]["parent"] == snap1["name"] assert snapMap[snap2["name"]]["removed"] is False assert snapMap[snap3["name"]]["name"] == snap3["name"] assert snapMap[snap3["name"]]["parent"] == snap2["name"] assert len(snapMap[snap3["name"]]["children"]) == 1 assert "volume-head" in snapMap[snap3["name"]]["children"] assert snapMap[snap3["name"]]["removed"] is True snap = volume.snapshotGet(name=snap3["name"]) assert snap["name"] == snap3["name"] assert snap["parent"] == snap3["parent"] assert len(snap3["children"]) == 1 assert len(snap["children"]) == 1 assert "volume-head" in snap3["children"] assert "volume-head" in snap["children"] assert snap["removed"] is True volume.detach() volume = common.wait_for_volume_detached(client, volume_name) volume.attach(hostId=lht_hostId, disableFrontend=True) common.wait_for_volume_healthy(client, volume_name) volume = client.by_id_volume(volume_name) engine = get_volume_engine(volume) assert volume["disableFrontend"] is True assert volume["frontend"] == "blockdev" assert engine["endpoint"] == "" volume.snapshotRevert(name=snap2["name"]) volume.detach() volume = common.wait_for_volume_detached(client, volume_name) volume.attach(hostId=lht_hostId, disableFrontend=False) common.wait_for_volume_healthy(client, volume_name) volume = client.by_id_volume(volume_name) assert volume["disableFrontend"] is False assert volume["frontend"] == "blockdev" check_volume_data(volume, snap2_data) snapshots = volume.snapshotList(volume=volume_name) snapMap = {} for snap in snapshots: snapMap[snap["name"]] = snap assert snapMap[snap1["name"]]["name"] == snap1["name"] assert snapMap[snap1["name"]]["removed"] is False assert snapMap[snap2["name"]]["name"] == snap2["name"] assert snapMap[snap2["name"]]["parent"] == snap1["name"] assert "volume-head" in snapMap[snap2["name"]]["children"] assert snap3["name"] in snapMap[snap2["name"]]["children"] assert snapMap[snap2["name"]]["removed"] is False assert snapMap[snap3["name"]]["name"] == snap3["name"] assert snapMap[snap3["name"]]["parent"] == snap2["name"] assert len(snapMap[snap3["name"]]["children"]) == 0 assert snapMap[snap3["name"]]["removed"] is True volume.snapshotDelete(name=snap1["name"]) volume.snapshotDelete(name=snap2["name"]) volume.snapshotPurge() wait_for_snapshot_purge(volume, snap1["name"], snap3["name"]) snapshots = volume.snapshotList(volume=volume_name) snapMap = {} for snap in snapshots: snapMap[snap["name"]] = snap assert snap1["name"] not in snapMap assert snap3["name"] not in snapMap # it's the parent of volume-head, so it cannot be purged at this time assert snapMap[snap2["name"]]["name"] == snap2["name"] assert snapMap[snap2["name"]]["parent"] == "" assert "volume-head" in snapMap[snap2["name"]]["children"] assert snapMap[snap2["name"]]["removed"] is True check_volume_data(volume, snap2_data) cleanup_volume(client, volume)