Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 28 additions & 4 deletions tests/network/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,42 @@
import logging

from data import HOST_FREE_NICS
from lib.common import PackageManagerEnum
from lib.common import PackageManagerEnum, safe_split
from lib.host import Host
from lib.network import Network
from lib.vm import VM

from typing import Generator

@pytest.fixture(scope='package')
def host_no_sdn_controller(host: Host) -> None:
def host_no_sdn_controller(host: Host) -> Generator[Host, None, None]:
""" An XCP-ng with no SDN controller. """
if host.xe('sdn-controller-list', minimal=True):
pytest.fail("This test requires an XCP-ng with no SDN controller")
sdn_configured: list[dict[str, str | bool | dict[str, str]]] = []

for uuid in safe_split(host.xe('sdn-controller-list', minimal=True), ','):
logging.info(f"Forgetting sdn-controller: {uuid}")

sdn_configured.append({
'protocol': host.xe('sdn-controller-param-get', {'uuid': uuid, 'param-name': 'protocol'}),
'address': host.xe('sdn-controller-param-get', {'uuid': uuid, 'param-name': 'address'}),
'tcp-port': host.xe('sdn-controller-param-get', {'uuid': uuid, 'param-name': 'port'}),
})

host.xe('sdn-controller-forget', {'uuid': uuid})

# when using sdn-controller, we are usually using OpenFlow11 only
# but allow-id is using OpenFlow10 and it fails to sets rules if OpenFlow11 is enabled only.
host.ssh("set -o pipefail; ovs-vsctl list-br "

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if ovs-vsctl raised all forgotten sdn will remain forgotten. Not sure if it is a real issue.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it shouldn't be a problem. the set -o pipefail was added due to @glehmann remark as "if it raises it means OVS is completely off, and we are already in bad shape"

"| xargs -n1 -d '\n' -r -I{} ovs-vsctl add bridge {} protocols OpenFlow10")

yield host

host.ssh("set -o pipefail; ovs-vsctl list-br "
"| xargs -n1 -d '\n' -r -I{} ovs-vsctl remove bridge {} protocols OpenFlow10")

for cfg in sdn_configured:
logging.info("Re-introducing sdn-controller")
host.xe('sdn-controller-introduce', cfg)

# a clone of imported_vm in which we've added tcpdump
# not to be used by tests directly
Expand Down