|
5 | 5 | import logging |
6 | 6 |
|
7 | 7 | from data import HOST_FREE_NICS |
8 | | -from lib.common import PackageManagerEnum |
| 8 | +from lib.common import PackageManagerEnum, safe_split |
9 | 9 | from lib.host import Host |
10 | 10 | from lib.network import Network |
11 | 11 | from lib.vm import VM |
12 | 12 |
|
13 | 13 | from typing import Generator |
14 | 14 |
|
15 | 15 | @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]: |
17 | 17 | """ 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) |
20 | 57 |
|
21 | 58 | # a clone of imported_vm in which we've added tcpdump |
22 | 59 | # not to be used by tests directly |
|
0 commit comments