1+ from __future__ import annotations
2+
13import pytest
24
35import logging
46
7+ from lib .bond import Bond
58from lib .host import Host
69from lib .network import Network
10+ from lib .tunnel import Tunnel
11+ from lib .vlan import VLAN
712
813from typing import Generator
914
@@ -14,6 +19,7 @@ def host_no_sdn_controller(host: Host):
1419 pytest .skip ("This test requires an XCP-ng with no SDN controller" )
1520
1621
22+ # ---- Network ----
1723@pytest .fixture (scope = 'module' )
1824def empty_network (host : Host ) -> Generator [Network , None , None ]:
1925 try :
@@ -22,6 +28,56 @@ def empty_network(host: Host) -> Generator[Network, None, None]:
2228 finally :
2329 net .destroy ()
2430
31+
32+ # ---- VLAN ----
33+ @pytest .fixture (params = ["eth0" ])
34+ def vlan_device (request : pytest .FixtureRequest ) -> str :
35+ return request .param
36+
37+ @pytest .fixture (params = [0 ])
38+ def vlan_tag (request : pytest .FixtureRequest ) -> int :
39+ return request .param
40+
41+ @pytest .fixture
42+ def vlan (host : Host , empty_network : Network , vlan_tag : int , vlan_device : str ) -> Generator [VLAN , None , None ]:
43+ logging .info (f"vlan: resolve PIF on { host .hostname_or_ip } using \
44+ { [(pif .network_uuid (), pif .param_get ('device' )) for pif in host .pifs ()]} " )
45+
46+ [pif ] = host .pifs (device = vlan_device )
47+ vlan = host .create_vlan (empty_network , pif , vlan_tag )
48+ try :
49+ yield vlan
50+ finally :
51+ vlan .destroy ()
52+
53+
54+ # ---- Tunnel ----
55+ @pytest .fixture (params = ["eth0" ])
56+ def tunnel_device (request : pytest .FixtureRequest ) -> str :
57+ return request .param
58+
59+ @pytest .fixture (params = ["gre" , "vxlan" ])
60+ def tunnel_protocol (request : pytest .FixtureRequest ) -> str :
61+ return request .param
62+
63+ @pytest .fixture
64+ def tunnel (
65+ host : Host , empty_network : Network ,
66+ tunnel_device : str , tunnel_protocol : str ,
67+ ) -> Generator [Tunnel , None , None ]:
68+ logging .info (f"tunnel: resolve PIF on { host .hostname_or_ip } using \
69+ { [(pif .network_uuid (), pif .param_get ('device' )) for pif in host .pifs ()]} " )
70+
71+ [pif ] = host .pifs (device = tunnel_device )
72+ assert pif .ip_configuration_mode () != "None" , "Tunnel requires tunnel_device with IP configured"
73+ tunnel = host .create_tunnel (empty_network , pif , tunnel_protocol )
74+ try :
75+ yield tunnel
76+ finally :
77+ tunnel .destroy ()
78+
79+
80+ # ---- Bond ----
2581@pytest .fixture (params = [])
2682def bond_devices (request : pytest .FixtureRequest ) -> list [str ]:
2783 return request .param
@@ -31,7 +87,7 @@ def bond_mode(request: pytest.FixtureRequest) -> str:
3187 return request .param
3288
3389@pytest .fixture
34- def bond (host : Host , empty_network : Network , bond_devices : list [str ], bond_mode : str ):
90+ def bond (host : Host , empty_network : Network , bond_devices : list [str ], bond_mode : str ) -> Generator [ Bond , None , None ] :
3591 pifs = []
3692 logging .info (f"bond: resolve PIFs on { host .hostname_or_ip } using \
3793 { [(pif .network_uuid (), pif .param_get ('device' )) for pif in host .pifs ()]} " )
0 commit comments