Skip to content

Commit 4581cec

Browse files
committed
host_no_sdn_controller: do not fail, but reconfigure the host.
when a 'no-sdn-controller' host is required (for test_vif_allowed_ip.py for example), do not fail if sdn-controller is active, but disable it for the test (and restore it after). we get the sdn-controller configuration to reapply it after the test, and reconfigure the ovs bridges to accept both OpenFlow10 and OpenFlow11 versions. OpenFlow11 is usual used for sdn-controller (xapi-plugin) and OpenFlow10 for allowed-ip (see xen-api ocaml/xenopsd/scripts/setup-vif-rules). Signed-off-by: Sebastien Rodot <sebastien.rodot@vates.tech>
1 parent a8d96b6 commit 4581cec

1 file changed

Lines changed: 41 additions & 4 deletions

File tree

tests/network/conftest.py

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,55 @@
55
import logging
66

77
from data import HOST_FREE_NICS
8-
from lib.common import PackageManagerEnum
8+
from lib.common import PackageManagerEnum, safe_split
99
from lib.host import Host
1010
from lib.network import Network
1111
from lib.vm import VM
1212

1313
from typing import Generator
1414

1515
@pytest.fixture(scope='package')
16-
def host_no_sdn_controller(host: Host) -> None:
16+
def host_no_sdn_controller(host: Host) -> Generator[Host, None, None]:
1717
""" An XCP-ng with no SDN controller. """
18-
if host.xe('sdn-controller-list', minimal=True):
19-
pytest.fail("This test requires an XCP-ng with no SDN controller")
18+
sdn_configured = []
19+
20+
uuids = safe_split(host.xe('sdn-controller-list', minimal=True), ',')
21+
if len(uuids) > 0:
22+
for uuid in uuids:
23+
logging.info(f"Forgetting sdn-controller: {uuid}")
24+
25+
sdn_configured.append({
26+
'protocol': host.xe('sdn-controller-param-get', {'uuid': uuid, 'param-name': 'protocol'}),
27+
'address': host.xe('sdn-controller-param-get', {'uuid': uuid, 'param-name': 'address'}),
28+
'port': host.xe('sdn-controller-param-get', {'uuid': uuid, 'param-name': 'port'}),
29+
})
30+
31+
host.xe('sdn-controller-forget', {'uuid': uuid})
32+
33+
# when using sdn-controller, we are usually using OpenFlow11 only
34+
# but allow-id is using OpenFlow10 and it fails to sets rules if OpenFlow11 is enabled only.
35+
host.ssh("ovs-vsctl list-br "
36+
"| xargs -n1 -d '\n' -r -I{} ovs-vsctl add bridge {} protocols OpenFlow10")
37+
38+
assert len(safe_split(host.xe('sdn-controller-list', minimal=True), ',')) == 0
39+
40+
yield host
41+
42+
if len(uuids) > 0:
43+
host.ssh("ovs-vsctl list-br "
44+
"| xargs -n1 -d '\n' -r -I{} ovs-vsctl remove bridge {} protocols OpenFlow10")
45+
46+
for cfg in sdn_configured:
47+
args: dict[str, str | bool | dict[str, str]] = {}
48+
if cfg.get('protocol') is not None:
49+
args['protocol'] = cfg.get('protocol', '')
50+
if cfg.get('address') is not None:
51+
args['address'] = cfg.get('address', '')
52+
if cfg.get('port') is not None:
53+
args['tcp-port'] = cfg.get('port', '0')
54+
55+
logging.info("Re-introducing sdn-controller")
56+
host.xe('sdn-controller-introduce', args)
2057

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

0 commit comments

Comments
 (0)