|
3 | 3 | import os
|
4 | 4 | import logging
|
5 | 5 |
|
6 |
| -from helpers import load_results_from_csv |
| 6 | +from lib.commands import SSHCommandFailed |
| 7 | +from .helpers import load_results_from_csv |
7 | 8 |
|
8 |
| -@pytest.fixture(scope='package') |
9 |
| -def ext_sr(host, sr_disk): |
10 |
| - sr = host.sr_create('ext', "EXT-local-SR-test", {'device': '/dev/' + sr_disk}) |
11 |
| - yield sr |
12 |
| - # teardown |
13 |
| - sr.destroy() |
14 |
| - |
15 |
| -@pytest.fixture(scope='module', params=['raw', 'vhd', 'qcow2']) |
16 |
| -def disk_on_ext_sr(request, ext_sr): |
17 |
| - disk_type = request.param |
18 |
| - disk = {} |
19 |
| - if disk_type == 'raw': |
20 |
| - ... |
21 |
| - elif disk_type == 'vhd': |
22 |
| - ... |
23 |
| - elif disk_type == 'qcow2': |
24 |
| - ... |
| 9 | +MAX_LENGTH = 64*(1024**3) # 64GiB |
| 10 | + |
| 11 | +# use vhd, qcow2, raw... when image_format support will be available |
| 12 | +@pytest.fixture(scope="module", params=['vdi']) |
| 13 | +def image_format(request): |
| 14 | + return request.param |
| 15 | + |
| 16 | +@pytest.fixture(scope="module") |
| 17 | +def running_unix_vm_with_fio(running_unix_vm): |
| 18 | + vm = running_unix_vm |
| 19 | + install_cmds = ( |
| 20 | + ("command -v apt", "apt update && apt install -y fio", "apt remove -y fio"), |
| 21 | + ("command -v dnf", "dnf install -y fio", "dnf remove -y fio"), |
| 22 | + ("command -v yum", "yum install -y fio", "yum remove -y fio"), |
| 23 | + ("command -v apk", "apk add fio", "apk del fio") |
| 24 | + ) |
| 25 | + |
| 26 | + for check_cmd, install_cmd, remove in install_cmds: |
| 27 | + try: |
| 28 | + vm.ssh(check_cmd, check=True) |
| 29 | + logging.info(f">> Installing fio with {install_cmd}") |
| 30 | + vm.ssh(install_cmd, check=True) |
| 31 | + remove_cmd = remove |
| 32 | + break |
| 33 | + except SSHCommandFailed: ... |
25 | 34 | else:
|
26 |
| - raise ValueError(f"Unsupported disk type: {disk_type}") |
| 35 | + raise RuntimeError("Unsupported package manager: could not install fio") |
27 | 36 |
|
28 |
| - yield disk |
| 37 | + yield vm |
29 | 38 |
|
30 | 39 | # teardown
|
31 |
| - ... |
| 40 | + logging.info(f"<< Removing fio with {remove_cmd}") |
| 41 | + vm.ssh(remove_cmd, check=False) |
| 42 | + |
| 43 | + |
| 44 | +@pytest.fixture(scope="module") |
| 45 | +def vdi_on_local_sr(host, local_sr_on_hostA1, image_format): |
| 46 | + sr = local_sr_on_hostA1 |
| 47 | + vdi = sr.create_vdi("testVDI", MAX_LENGTH) |
| 48 | + vdi.image_format = image_format |
| 49 | + logging.info(f">> Created VDI {vdi.uuid} of type {image_format}") |
| 50 | + |
| 51 | + yield vdi |
| 52 | + |
| 53 | + # teardown |
| 54 | + logging.info(f"<< Destroying VDI {vdi.uuid}") |
| 55 | + vdi.destroy() |
| 56 | + |
| 57 | +@pytest.fixture(scope="module") |
| 58 | +def running_unix_vm_and_vbd(host, vdi_on_local_sr, running_unix_vm_with_fio): |
| 59 | + vm = running_unix_vm_with_fio |
| 60 | + vdi = vdi_on_local_sr |
| 61 | + vbd = vm.create_vbd("autodetect", vdi.uuid) |
| 62 | + |
| 63 | + logging.info(f">> Plugging VDI {vdi.uuid} on VM {vm.uuid}") |
| 64 | + vbd.plug() |
| 65 | + |
| 66 | + yield vm, vbd |
32 | 67 |
|
33 |
| -@pytest.fixture(scope='module') |
34 |
| -def vm_on_ext_sr(host, ext_sr, vm_ref): |
35 |
| - vm = host.import_vm(vm_ref, sr_uuid=ext_sr.uuid) |
36 |
| - yield vm |
37 | 68 | # teardown
|
38 |
| - logging.info("<< Destroy VM") |
39 |
| - vm.destroy(verify=True) |
| 69 | + logging.info(f"<< Unplugging VDI {vdi.uuid} from VM {vm.uuid}") |
| 70 | + vbd.unplug() |
| 71 | + vbd.destroy() |
| 72 | + |
| 73 | +@pytest.fixture(scope="module") |
| 74 | +def vm_with_vbd(running_unix_vm_and_vbd): |
| 75 | + vm, _vbd = running_unix_vm_and_vbd |
| 76 | + return vm |
| 77 | + |
| 78 | +@pytest.fixture(scope="module") |
| 79 | +def plugged_vbd(running_unix_vm_and_vbd): |
| 80 | + _vm, vbd = running_unix_vm_and_vbd |
| 81 | + return vbd |
40 | 82 |
|
41 |
| -@pytest.fixture |
42 |
| -def temp_dir(): |
| 83 | +@pytest.fixture(scope="module") |
| 84 | +def local_temp_dir(): |
43 | 85 | with tempfile.TemporaryDirectory() as tmpdir:
|
44 | 86 | yield tmpdir
|
45 | 87 |
|
| 88 | +@pytest.fixture(scope="module") |
| 89 | +def temp_dir(vm_with_vbd): |
| 90 | + vm = vm_with_vbd |
| 91 | + tempdir = vm.ssh("mktemp -d") |
| 92 | + |
| 93 | + yield tempdir |
| 94 | + |
| 95 | + # teardown |
| 96 | + vm.ssh(f"rm -r {tempdir}") |
| 97 | + |
| 98 | + |
46 | 99 | def pytest_addoption(parser):
|
47 | 100 | parser.addoption(
|
48 | 101 | "--prev-csv",
|
|
0 commit comments