66from lib .common import strtobool
77from lib .host import Host
88
9+ from typing import Generator
10+
911# Requirements:
1012# From --hosts parameter:
1113# - A XCP-ng >= 8.3 pool with at least two hosts
2123XAPI_POOL_PEM_FILEPATH = f'/etc/xensource/{ XAPI_POOL_PEM_FILENAME } '
2224
2325@pytest .fixture (scope = "module" )
24- def host_with_tls_verification_enabled (hostA1 ) :
26+ def host_with_tls_verification_enabled (hostA1 : Host ) -> Generator [ Host , None , None ] :
2527 for h in hostA1 .pool .hosts :
2628 logging .info (f"Check that TLS verification is enabled on host { h } " )
2729 assert strtobool (h .param_get ("tls-verification-enabled" )), f"TLS verification must be enabled on host { h } "
2830 logging .info (f"Check that the host certificate exists on host { h } " )
2931 cert_uuid = hostA1 .xe ('certificate-list' , {'host' : h .uuid , 'type' : 'host_internal' }, minimal = True )
3032 assert len (cert_uuid ) > 0 , f"A host_internal certificate must exist on host { h } "
33+ yield hostA1
3134
3235
3336@pytest .mark .usefixtures ("host_at_least_8_3" , "host_with_tls_verification_enabled" )
3437class TestTLSVerification :
35- def _test_tls_verification (self , hostA1 : Host , with_toolstack_restart = False ):
38+ def _test_tls_verification (self , hostA1 : Host , with_toolstack_restart : bool = False ) -> None :
3639 for h in hostA1 .pool .hosts [1 :]:
3740 logging .info (f"Establish a connexion from host { hostA1 } to host { h } by running 'xe host-dmesg'" )
3841 hostA1 .xe ('host-dmesg' , {'host' : h .uuid })
@@ -44,10 +47,10 @@ def _test_tls_verification(self, hostA1: Host, with_toolstack_restart=False):
4447 logging .info (f"Test connexion from host { h } to host { hostA1 } by running 'xe host-dmesg'" )
4548 h .xe ('host-dmesg' , {'host' : hostA1 .uuid })
4649
47- def test_tls_verification (self , hostA1 ) :
50+ def test_tls_verification (self , hostA1 : Host ) -> None :
4851 self ._test_tls_verification (hostA1 )
4952
50- def test_refresh_certificate (self , hostA1 ) :
53+ def test_refresh_certificate (self , hostA1 : Host ) -> None :
5154 logging .info ("Refresh the xapi:pool certificate on every pool member" )
5255 for h in hostA1 .pool .hosts :
5356 old_checksum = h .ssh (f'md5sum { XAPI_POOL_PEM_FILEPATH } ' ).split ()[0 ]
@@ -58,7 +61,7 @@ def test_refresh_certificate(self, hostA1):
5861 self ._test_tls_verification (hostA1 , with_toolstack_restart = True )
5962
6063 @pytest .fixture (scope = "function" )
61- def hostA2_with_saved_cert (self , hostA2 : Host ):
64+ def hostA2_with_saved_cert (self , hostA2 : Host ) -> Generator [ Host , None , None ] :
6265 tmp_dir = hostA2 .ssh ('mktemp -d' )
6366 logging .info (f"Save { XAPI_POOL_PEM_FILEPATH } on { hostA2 } " )
6467 hostA2 .ssh (f'cp { XAPI_POOL_PEM_FILEPATH } { tmp_dir } ' )
@@ -68,7 +71,7 @@ def hostA2_with_saved_cert(self, hostA2: Host):
6871 hostA2 .ssh (f'rm -r { tmp_dir } ' )
6972 hostA2 .ssh ('systemctl reload-or-restart stunnel@xapi' )
7073
71- def test_break_cert (self , hostA1 : Host , hostA2_with_saved_cert : Host ):
74+ def test_break_cert (self , hostA1 : Host , hostA2_with_saved_cert : Host ) -> None :
7275 hostA2 = hostA2_with_saved_cert
7376 logging .info (f"Replace the certificate on host { hostA2 } " )
7477 hostA2 .ssh (f'rm { XAPI_POOL_PEM_FILEPATH } ' )
@@ -88,7 +91,7 @@ def test_break_cert(self, hostA1: Host, hostA2_with_saved_cert: Host):
8891 The server may be switched off or there may be network connectivity problems." in excinfo .value .stdout
8992 )
9093
91- def test_toolstack_restart (self , hostA1 : Host , hostA2 : Host ):
94+ def test_toolstack_restart (self , hostA1 : Host , hostA2 : Host ) -> None :
9295 """
9396 Same test as the previous one, but we don't break the cert.
9497
0 commit comments