|
1 |
| -import logging |
| 1 | +import pytest |
2 | 2 |
|
3 |
| -from .utils import compare_data, copy_data_to_tapdev, snapshot_vdi, wait_for_vdi_coalesce |
| 3 | +import logging |
4 | 4 |
|
5 |
| -class Test: |
6 |
| - def test_write_data(self, host, tapdev, data_file_on_host): |
7 |
| - length = 1 * 1024 * 1024 |
8 |
| - offset = 0 |
| 5 | +from .utils import compare_data, copy_data_to_tapdev, operation_on_vdi, wait_for_vdi_coalesce |
9 | 6 |
|
10 |
| - logging.info("Copying data to tapdev") |
11 |
| - copy_data_to_tapdev(host, data_file_on_host, tapdev, offset, length) |
| 7 | +from typing import TYPE_CHECKING |
12 | 8 |
|
13 |
| - logging.info("Comparing data to tapdev") |
14 |
| - assert compare_data(host, tapdev, data_file_on_host, offset, length) |
| 9 | +if TYPE_CHECKING: |
| 10 | + from lib.host import Host |
| 11 | + from lib.vdi import VDI |
15 | 12 |
|
16 |
| - def test_coalesce(self, host, tapdev, vdi_with_vbd_on_dom0, data_file_on_host): |
17 |
| - vdi = vdi_with_vbd_on_dom0 |
18 |
| - vdi_uuid = vdi.uuid |
| 13 | +class Test: |
| 14 | + def test_write_data(self, host: "Host", tapdev: str, data_file_on_host: str): |
19 | 15 | length = 1 * 1024 * 1024
|
20 | 16 | offset = 0
|
21 | 17 |
|
22 |
| - vdi_snap = snapshot_vdi(host, vdi_uuid) |
23 |
| - |
24 | 18 | logging.info("Copying data to tapdev")
|
25 | 19 | copy_data_to_tapdev(host, data_file_on_host, tapdev, offset, length)
|
26 | 20 |
|
27 |
| - logging.info("Removing VDI snapshot") |
28 |
| - host.xe("vdi-destroy", {"uuid": vdi_snap}) |
29 |
| - |
30 |
| - wait_for_vdi_coalesce(vdi) |
31 |
| - |
32 | 21 | logging.info("Comparing data to tapdev")
|
33 | 22 | assert compare_data(host, tapdev, data_file_on_host, offset, length)
|
34 | 23 |
|
35 |
| - def test_clone_coalesce(self, host, tapdev, vdi_with_vbd_on_dom0, data_file_on_host): |
| 24 | + @pytest.mark.parametrize("vdi_op", ["snapshot", "clone"]) |
| 25 | + def test_coalesce(self, host: "Host", tapdev: str, vdi_with_vbd_on_dom0: "VDI", data_file_on_host: str, vdi_op): |
36 | 26 | vdi = vdi_with_vbd_on_dom0
|
37 | 27 | vdi_uuid = vdi.uuid
|
38 | 28 | length = 1 * 1024 * 1024
|
39 | 29 | offset = 0
|
40 | 30 |
|
41 |
| - clone_uuid = host.xe("vdi-clone", {"uuid": vdi_uuid}) |
42 |
| - logging.info(f"Clone VDI {vdi_uuid}: {clone_uuid}") |
| 31 | + new_vdi = operation_on_vdi(host, vdi_uuid, vdi_op) |
43 | 32 |
|
44 | 33 | logging.info("Copying data to tapdev")
|
45 | 34 | copy_data_to_tapdev(host, data_file_on_host, tapdev, offset, length)
|
46 | 35 |
|
47 |
| - logging.info("Removing VDI clone") |
48 |
| - host.xe("vdi-destroy", {"uuid": clone_uuid}) |
| 36 | + logging.info(f"Removing VDI {vdi_op}") |
| 37 | + host.xe("vdi-destroy", {"uuid": new_vdi}) |
49 | 38 |
|
50 | 39 | wait_for_vdi_coalesce(vdi)
|
51 | 40 |
|
|
0 commit comments