|
| 1 | +from __future__ import annotations |
| 2 | + |
| 3 | +import pytest |
| 4 | + |
| 5 | +import logging |
| 6 | + |
| 7 | +from lib.bond import Bond |
| 8 | +from lib.host import Host |
| 9 | +from lib.pif import PIF |
| 10 | +from lib.vm import VM |
| 11 | + |
| 12 | +# Requirements: |
| 13 | +# From --hosts parameter: |
| 14 | +# - host(A1): an XCP-ng host, with at least 2 free NICs |
| 15 | +# From --vm parameter |
| 16 | +# - A VM to import |
| 17 | + |
| 18 | +def _wait_for_packet(host: Host | VM, interface: str | list[str], sfilter: str, timeout: int = 30) -> None: |
| 19 | + if isinstance(interface, list): |
| 20 | + interface = ' '.join([f"-i {iface}" for iface in interface]) |
| 21 | + else: |
| 22 | + interface = f"-i {interface}" |
| 23 | + |
| 24 | + host.ssh(f"timeout {timeout} tcpdump {interface} -n -c1 '{sfilter}'") |
| 25 | + |
| 26 | +@pytest.mark.complex_prerequisites |
| 27 | +@pytest.mark.small_vm |
| 28 | +class TestBond: |
| 29 | + def test_lacp(self, host: Host, vm_with_tcpdump_scope_function: VM, bond_lacp: Bond): |
| 30 | + # expect host with eth1 and eth2 NICs free for use |
| 31 | + logging.info(f"Bond = {bond_lacp.uuid} mode={bond_lacp.mode()} \ |
| 32 | + slaves={bond_lacp.slaves()}") |
| 33 | + |
| 34 | + # disable LACP fallback (make Bond to require LACP negociation first) |
| 35 | + bond_lacp.param_set("properties", key="lacp-fallback-ab", value="false") |
| 36 | + |
| 37 | + # check bond0 on the host |
| 38 | + output = host.ssh("ovs-appctl bond/show bond0") |
| 39 | + |
| 40 | + if "bond_mode: balance-tcp" not in output: |
| 41 | + pytest.fail(f"string 'bond_mode: balance-tcp' not found in output. output={output}") |
| 42 | + elif "lacp_fallback_ab: false" not in output: |
| 43 | + pytest.fail(f"unexpected lacp_fallback_ab: output={output}") |
| 44 | + elif "lacp_status: configured" not in output and "lacp_status: negotiated" not in output: |
| 45 | + pytest.fail(f"unexpected lacp_status: output={output}") |
| 46 | + |
| 47 | + # on the VM, add a new NIC using the bond |
| 48 | + vm = vm_with_tcpdump_scope_function |
| 49 | + vm.create_vif(1, network_uuid=bond_lacp.master().network_uuid()) |
| 50 | + vm.start() |
| 51 | + vm.wait_for_vm_running_and_ssh_up() |
| 52 | + |
| 53 | + vm.ssh("ip link set eth1 up") |
| 54 | + |
| 55 | + # we are checking if we are seeing LACP packet on *VM side*. |
| 56 | + # |
| 57 | + # OpenvSwitch will send LACP negociation on host.eth1 and host.eth2 |
| 58 | + # to establish LACP link. As we don't have other side, it will keep |
| 59 | + # sending them. |
| 60 | + # On VM side, we could see such packets. So we are checking the VM.eth1 |
| 61 | + # is properly connected to the Bond just created (but we don't check that |
| 62 | + # OpenvSwitch is properly setup) |
| 63 | + logging.info("Waiting for LACP packet") |
| 64 | + _wait_for_packet(vm, "eth1", "ether proto 0x8809") |
| 65 | + |
| 66 | + def test_active_backup(self, host: Host, vm_with_tcpdump_scope_function: VM, bond_activebackup: Bond): |
| 67 | + # expect host with eth1 and eth2 NICs free for use |
| 68 | + logging.info(f"Bond = {bond_activebackup.uuid} mode={bond_activebackup.mode()} \ |
| 69 | + slaves={bond_activebackup.slaves()}") |
| 70 | + |
| 71 | + # get device's PIFs used by the bond on the host |
| 72 | + bond_devices = [PIF(uuid, host).device() for uuid in bond_activebackup.slaves()] |
| 73 | + |
| 74 | + # check bond0 on the host |
| 75 | + output = host.ssh("ovs-appctl bond/show bond0") |
| 76 | + |
| 77 | + if "bond_mode: active-backup" not in output: |
| 78 | + pytest.fail(f"string 'bond_mode: active-backup' not found in output. output={output}") |
| 79 | + |
| 80 | + if "lacp_status: off" not in output: |
| 81 | + pytest.fail(f"unexpected lacp_status: output={output}") |
| 82 | + |
| 83 | + # on the VM, add a new NIC using the bond |
| 84 | + vm = vm_with_tcpdump_scope_function |
| 85 | + vm.create_vif(1, network_uuid=bond_activebackup.master().network_uuid()) |
| 86 | + vm.start() |
| 87 | + vm.wait_for_vm_running_and_ssh_up() |
| 88 | + |
| 89 | + vm.ssh("ip link set eth1 up") |
| 90 | + |
| 91 | + # just check if we see a packet on the *host side*. |
| 92 | + # the VM kernel is expected to send IPv6 packet for Router Solicitation |
| 93 | + # as the VM interface is UP. |
| 94 | + logging.info("Waiting for some IPv6 packet") |
| 95 | + _wait_for_packet(host, bond_devices, "ether proto 0x86dd") |
| 96 | + |
| 97 | + def test_balance_slb(self, host: Host, vm_with_tcpdump_scope_function: VM, bond_balanceslb: Bond): |
| 98 | + # expect host with eth1 and eth2 NICs free for use |
| 99 | + logging.info(f"Bond = {bond_balanceslb.uuid} mode={bond_balanceslb.mode()} \ |
| 100 | + slaves={bond_balanceslb.slaves()}") |
| 101 | + |
| 102 | + # get device's PIFs used by the bond on the host |
| 103 | + bond_devices = [PIF(uuid, host).device() for uuid in bond_balanceslb.slaves()] |
| 104 | + |
| 105 | + # check bond0 on the host |
| 106 | + output = host.ssh("ovs-appctl bond/show bond0") |
| 107 | + |
| 108 | + if "bond_mode: balance-slb" not in output: |
| 109 | + pytest.fail(f"string 'bond_mode: balance-tcp' not found in output. output={output}") |
| 110 | + |
| 111 | + if "lacp_status: off" not in output: |
| 112 | + pytest.fail(f"unexpected lacp_status: output={output}") |
| 113 | + |
| 114 | + # on the VM, add a new NIC using the bond |
| 115 | + vm = vm_with_tcpdump_scope_function |
| 116 | + vm.create_vif(1, network_uuid=bond_balanceslb.master().network_uuid()) |
| 117 | + vm.start() |
| 118 | + vm.wait_for_vm_running_and_ssh_up() |
| 119 | + |
| 120 | + vm.ssh("ip link set eth1 up") |
| 121 | + |
| 122 | + # just check if we see a packet on the *host side*. |
| 123 | + # the VM kernel is expected to send IPv6 packet for Router Solicitation |
| 124 | + # as the VM interface is UP. |
| 125 | + logging.info("Waiting for some IPv6 packet") |
| 126 | + _wait_for_packet(host, bond_devices, "ether proto 0x86dd") |
0 commit comments