|
| 1 | +from __future__ import annotations |
| 2 | + |
1 | 3 | import pytest |
2 | 4 |
|
| 5 | +import logging |
| 6 | + |
| 7 | +from data import HOST_FREE_NICS |
| 8 | +from lib.common import PackageManagerEnum |
3 | 9 | from lib.host import Host |
| 10 | +from lib.network import Network |
| 11 | +from lib.vm import VM |
| 12 | + |
| 13 | +from typing import Generator |
4 | 14 |
|
5 | 15 | @pytest.fixture(scope='package') |
6 | 16 | def host_no_sdn_controller(host: Host) -> None: |
7 | 17 | """ An XCP-ng with no SDN controller. """ |
8 | 18 | if host.xe('sdn-controller-list', minimal=True): |
9 | | - pytest.skip("This test requires an XCP-ng with no SDN controller") |
| 19 | + pytest.fail("This test requires an XCP-ng with no SDN controller") |
| 20 | + |
| 21 | +# a clone of imported_vm in which we've added tcpdump |
| 22 | +# not to be used by tests directly |
| 23 | +@pytest.fixture(scope='module') |
| 24 | +def vm_with_tcpdump_scope_module(imported_vm: VM): |
| 25 | + logging.info("Preparing VM with tcpdump installed") |
| 26 | + vm = imported_vm.clone(name=f"{imported_vm.name()} with tcpdump") |
| 27 | + vm.start() |
| 28 | + vm.wait_for_vm_running_and_ssh_up() |
| 29 | + |
| 30 | + # install tcpdump |
| 31 | + pkg_mgr = vm.detect_package_manager() |
| 32 | + if pkg_mgr == PackageManagerEnum.APK: |
| 33 | + vm.ssh("apk add tcpdump") |
| 34 | + elif pkg_mgr == PackageManagerEnum.APT_GET: |
| 35 | + vm.ssh("apt-get install tcpdump") |
| 36 | + elif pkg_mgr == PackageManagerEnum.RPM: |
| 37 | + # XXX assume yum for now |
| 38 | + vm.ssh("yum install tcpdump") |
| 39 | + else: |
| 40 | + pytest.fail("Package manager '%s' not supported" % pkg_mgr) |
| 41 | + |
| 42 | + vm.shutdown(verify=True) |
| 43 | + yield vm |
| 44 | + vm.destroy() |
| 45 | + |
| 46 | +@pytest.fixture(scope='function') |
| 47 | +def vm_with_tcpdump_scope_function(vm_with_tcpdump_scope_module: VM): |
| 48 | + vm = vm_with_tcpdump_scope_module.clone(name=f"{vm_with_tcpdump_scope_module.name()} for tests") |
| 49 | + yield vm |
| 50 | + vm.destroy() |
| 51 | + |
| 52 | +@pytest.fixture(scope='module') |
| 53 | +def empty_network(host: Host) -> Generator[Network, None, None]: |
| 54 | + net = host.create_network(label="empty_network for tests") |
| 55 | + yield net |
| 56 | + net.destroy() |
| 57 | + |
| 58 | +@pytest.fixture(scope='function') |
| 59 | +def bond_lacp(host: Host, empty_network: Network): |
| 60 | + if len(HOST_FREE_NICS) < 2: |
| 61 | + pytest.fail("This fixture needs at least 2 free NICs") |
| 62 | + |
| 63 | + pifs = [] |
| 64 | + logging.info(f"bond: resolve PIFs on {host.hostname_or_ip} using \ |
| 65 | + {[(pif.network_uuid(), pif.param_get('device')) for pif in host.pifs()]}") |
| 66 | + for name in HOST_FREE_NICS[0:2]: |
| 67 | + [pif] = host.pifs(device=name) |
| 68 | + pifs.append(pif) |
| 69 | + |
| 70 | + bond = host.create_bond(empty_network, pifs, mode="lacp") |
| 71 | + yield bond |
| 72 | + bond.destroy() |
| 73 | + |
| 74 | +@pytest.fixture(scope='function') |
| 75 | +def bond_activebackup(host: Host, empty_network: Network): |
| 76 | + if len(HOST_FREE_NICS) < 2: |
| 77 | + pytest.fail("This fixture needs at least 2 free NICs") |
| 78 | + |
| 79 | + pifs = [] |
| 80 | + logging.info(f"bond: resolve PIFs on {host.hostname_or_ip} using \ |
| 81 | + {[(pif.network_uuid(), pif.param_get('device')) for pif in host.pifs()]}") |
| 82 | + for name in HOST_FREE_NICS[0:2]: |
| 83 | + [pif] = host.pifs(device=name) |
| 84 | + pifs.append(pif) |
| 85 | + |
| 86 | + bond = host.create_bond(empty_network, pifs, mode="active-backup") |
| 87 | + yield bond |
| 88 | + bond.destroy() |
| 89 | + |
| 90 | +@pytest.fixture(scope='function') |
| 91 | +def bond_balanceslb(host: Host, empty_network: Network): |
| 92 | + if len(HOST_FREE_NICS) < 2: |
| 93 | + pytest.fail("This fixture needs at least 2 free NICs") |
| 94 | + |
| 95 | + pifs = [] |
| 96 | + logging.info(f"bond: resolve PIFs on {host.hostname_or_ip} using \ |
| 97 | + {[(pif.network_uuid(), pif.param_get('device')) for pif in host.pifs()]}") |
| 98 | + for name in HOST_FREE_NICS[0:2]: |
| 99 | + [pif] = host.pifs(device=name) |
| 100 | + pifs.append(pif) |
| 101 | + |
| 102 | + bond = host.create_bond(empty_network, pifs, mode="balance-slb") |
| 103 | + yield bond |
| 104 | + bond.destroy() |
0 commit comments