|
1 | 1 | import logging
|
2 | 2 |
|
3 |
| -from lib.common import wait_for_not |
4 |
| -from lib.host import Host |
5 |
| -from lib.vdi import VDI |
6 |
| - |
7 |
| -def wait_for_vdi_coalesce(vdi: VDI): |
8 |
| - wait_for_not(lambda: vdi.get_parent(), msg="Waiting for coalesce") |
9 |
| - logging.info("Coalesce done") |
10 |
| - |
11 |
| -def copy_data_to_tapdev(host: Host, data_file: str, tapdev: str, offset: int, length: int): |
12 |
| - """ |
13 |
| - if offset == 0: |
14 |
| - off = "0" |
15 |
| - else: |
16 |
| - off = f"{offset}B" # Doesn't work with `dd` version of XCP-ng 8.3 |
17 |
| - """ |
18 |
| - bs = 1 |
19 |
| - off = int(offset / bs) |
20 |
| - count = length / bs |
21 |
| - count += length % bs |
22 |
| - count = int(count) |
23 |
| - cmd = ["dd", f"if={data_file}", f"of={tapdev}", f"bs={bs}", f"seek={off}", f"count={count}"] |
24 |
| - host.ssh(cmd) |
25 |
| - |
26 |
| -def get_data(host: Host, file: str, offset: int, length: int, checksum: bool = False) -> str: |
27 |
| - cmd = ["xxd", "-p", "-seek", str(offset), "-len", str(length), file] |
28 |
| - if checksum: |
29 |
| - cmd = cmd + ["|", "sha256sum"] |
30 |
| - return host.ssh(cmd) |
31 |
| - |
32 |
| -def get_hashed_data(host: Host, file: str, offset: int, length: int): |
33 |
| - return get_data(host, file, offset, length, True).split()[0] |
34 |
| - |
35 |
| -def snapshot_vdi(host: Host, vdi_uuid: str): |
36 |
| - vdi_snap = host.xe("vdi-snapshot", {"uuid": vdi_uuid}) |
37 |
| - logging.info(f"Snapshot VDI {vdi_uuid}: {vdi_snap}") |
38 |
| - return vdi_snap |
39 |
| - |
40 |
| -def compare_data(host: Host, tapdev: str, data_file: str, offset: int, length: int) -> bool: |
41 |
| - logging.info("Getting data from VDI and file") |
42 |
| - vdi_checksum = get_hashed_data(host, tapdev, offset, length) |
43 |
| - file_checksum = get_hashed_data(host, data_file, 0, length) |
44 |
| - logging.info(f"VDI: {vdi_checksum}") |
45 |
| - logging.info(f"FILE: {file_checksum}") |
46 |
| - |
47 |
| - return vdi_checksum == file_checksum |
| 3 | +from utils import wait_for_vdi_coalesce, copy_data_to_tapdev, snapshot_vdi, compare_data |
48 | 4 |
|
49 | 5 | class Test:
|
50 | 6 | def test_write_data(self, host, tapdev, data_file_on_host):
|
|
0 commit comments