@@ -146,6 +146,34 @@ def wait_for_session_count(count: int, retries: int = 5, delay: int = 1, raise_e
146146 raise ValueError (f'Expected { count } sessions, but have { len (sessions )} ' )
147147
148148
149+ @contextlib .contextmanager
150+ def nvmet_implementation (name ):
151+ old_config = call ('nvmet.global.config' )
152+ match name :
153+ case 'kernel' :
154+ if old_config ['kernel' ]:
155+ # No change necessary
156+ yield
157+ else :
158+ # Change necessary, so restore when done
159+ call ('nvmet.global.update' , {'kernel' : True })
160+ try :
161+ yield
162+ finally :
163+ call ('nvmet.global.update' , {'kernel' : False })
164+ case 'SPDK' :
165+ if not old_config ['kernel' ]:
166+ # No change necessary
167+ yield
168+ else :
169+ # Change necessary, so restore when done
170+ call ('nvmet.global.update' , {'kernel' : False })
171+ try :
172+ yield
173+ finally :
174+ call ('nvmet.global.update' , {'kernel' : True })
175+
176+
149177class NVMeCLIClient :
150178 DEBUG = False
151179
@@ -264,11 +292,12 @@ def loopback_client():
264292
265293class NVMeRunning :
266294
267- @pytest .fixture (scope = 'class' )
268- def fixture_nvmet_running (self ):
269- with ensure_service_enabled (SERVICE_NAME ):
270- with ensure_service_started (SERVICE_NAME , 3 ):
271- yield
295+ @pytest .fixture (params = ['kernel' , 'SPDK' ], scope = 'class' )
296+ def fixture_nvmet_running (self , request ):
297+ with nvmet_implementation (request .param ):
298+ with ensure_service_enabled (SERVICE_NAME ):
299+ with ensure_service_started (SERVICE_NAME , 3 ):
300+ yield
272301
273302 @contextlib .contextmanager
274303 def subsys (self , name , port , ** kwargs ):
@@ -860,9 +889,13 @@ def test__discovery_referrals(self, fixture_port, loopback_client: NVMeCLIClient
860889 """
861890 Test that a client can see expected referrals.
862891
892+ Note that kernel and SPDK behavior is different (SPDK makes more visible).
893+
863894 For HA this includes the implicit referral for a port when ANA is enabled.
864895 """
865- assert call ('nvmet.global.config' )['xport_referral' ]
896+ config = call ('nvmet.global.config' )
897+ assert config ['xport_referral' ]
898+ use_spdk = not config ['kernel' ]
866899 port = fixture_port
867900 nc = loopback_client
868901 subsys1_nqn = f'{ basenqn ()} :{ SUBSYS_NAME1 } '
@@ -890,12 +923,21 @@ def test__discovery_referrals(self, fixture_port, loopback_client: NVMeCLIClient
890923 with nvmet_port_subsys (subsys_id , port2 ['id' ]):
891924 # Check that we can see each port point at the other
892925 data = nc .discover ()
893- assert len (data ['records' ]) == 3
926+ if use_spdk :
927+ assert len (data ['records' ]) == 4
928+ assert self .discovery_present (data , SUBSYS1_ALT1_PORT )
929+ else :
930+ assert len (data ['records' ]) == 3
894931 assert self .discovery_present (data , DISCOVERY_DEFAULT_PORT )
895932 assert self .discovery_present (data , SUBSYS1_DEFAULT_PORT )
896933 assert self .discovery_present (data , DISCOVERY_ALT1_PORT )
897934 data = nc .discover (port = NVME_ALT1_TCP_PORT )
898- assert len (data ['records' ]) == 3
935+
936+ if use_spdk :
937+ assert len (data ['records' ]) == 4
938+ assert self .discovery_present (data , SUBSYS1_DEFAULT_PORT )
939+ else :
940+ assert len (data ['records' ]) == 3
899941 assert self .discovery_present (data , DISCOVERY_DEFAULT_PORT )
900942 assert self .discovery_present (data , SUBSYS1_ALT1_PORT )
901943 assert self .discovery_present (data , DISCOVERY_ALT1_PORT )
@@ -904,22 +946,22 @@ def test__discovery_referrals(self, fixture_port, loopback_client: NVMeCLIClient
904946 with nvmet_xport_referral (False ):
905947 # Check that we can see each port point at the other
906948 data = nc .discover ()
907- assert len (data ['records' ]) == 2
949+ assert len (data ['records' ]) == 2 if not use_spdk else 4
908950 assert self .discovery_present (data , DISCOVERY_DEFAULT_PORT )
909951 assert self .discovery_present (data , SUBSYS1_DEFAULT_PORT )
910952 data = nc .discover (port = NVME_ALT1_TCP_PORT )
911- assert len (data ['records' ]) == 2
953+ assert len (data ['records' ]) == 2 if not use_spdk else 4
912954 assert self .discovery_present (data , SUBSYS1_ALT1_PORT )
913955 assert self .discovery_present (data , DISCOVERY_ALT1_PORT )
914956
915957 if ha :
916958 data = nc .discover ()
917- assert len (data ['records' ]) == 3
959+ assert len (data ['records' ]) == 3 if not use_spdk else 4
918960 assert self .discovery_present (data , DISCOVERY_DEFAULT_PORT )
919961 assert self .discovery_present (data , SUBSYS1_DEFAULT_PORT )
920962 assert self .discovery_present (data , DISCOVERY_ALT1_PORT )
921963 data = nc .discover (port = NVME_ALT1_TCP_PORT )
922- assert len (data ['records' ]) == 3
964+ assert len (data ['records' ]) == 3 if not use_spdk else 4
923965 assert self .discovery_present (data , DISCOVERY_DEFAULT_PORT )
924966 assert self .discovery_present (data , SUBSYS1_ALT1_PORT )
925967 assert self .discovery_present (data , DISCOVERY_ALT1_PORT )
@@ -930,13 +972,13 @@ def test__discovery_referrals(self, fixture_port, loopback_client: NVMeCLIClient
930972 this_node = {'traddr' : node_ip }
931973 other_node = {'traddr' : other_node_ip }
932974 data = nc .discover (addr = node_ip )
933- assert len (data ['records' ]) == 4
975+ assert len (data ['records' ]) == 4 if not use_spdk else 6
934976 assert self .discovery_present (data , DISCOVERY_DEFAULT_PORT | this_node )
935977 assert self .discovery_present (data , SUBSYS1_DEFAULT_PORT | this_node )
936978 assert self .discovery_present (data , DISCOVERY_ALT1_PORT | this_node )
937979 assert self .discovery_present (data , DISCOVERY_DEFAULT_PORT | other_node )
938980 data = nc .discover (addr = node_ip , port = NVME_ALT1_TCP_PORT )
939- assert len (data ['records' ]) == 4
981+ assert len (data ['records' ]) == 4 if not use_spdk else 6
940982 assert self .discovery_present (data , DISCOVERY_DEFAULT_PORT | this_node )
941983 assert self .discovery_present (data , SUBSYS1_ALT1_PORT | this_node )
942984 assert self .discovery_present (data , DISCOVERY_ALT1_PORT | this_node )
@@ -947,9 +989,13 @@ def test__connect_all_referrals(self, fixture_port, loopback_client: NVMeCLIClie
947989 Test that when a client does a nvme connect-all, it adds the paths defined
948990 by the referrals.
949991
992+ Note that kernel and SPDK behavior is different (SPDK makes more visible).
993+
950994 For HA this includes the implicit referral for a port when ANA is enabled.
951995 """
952- assert call ('nvmet.global.config' )['xport_referral' ]
996+ config = call ('nvmet.global.config' )
997+ assert config ['xport_referral' ]
998+ use_spdk = not config ['kernel' ]
953999 nc = loopback_client
9541000 zvol1_path = f'zvol/{ zvol1 ["name" ]} '
9551001 with self .subsys (SUBSYS_NAME1 , fixture_port , allow_any_host = True ) as subsys1 :
@@ -1036,7 +1082,7 @@ def test__connect_all_referrals(self, fixture_port, loopback_client: NVMeCLIClie
10361082 with nvmet_xport_referral (False ):
10371083 with nc .connect_all_ctx ():
10381084 data = nc .nvme_list_subsys ()
1039- assert self .subsys_path_count (data , subsys_nqn ) == 1
1085+ assert self .subsys_path_count (data , subsys_nqn ) == 1 if not use_spdk else 2
10401086 assert self .subsys_path_present (data , subsys_nqn ,
10411087 truenas_server .ip , NVME_DEFAULT_TCP_PORT )
10421088
@@ -1055,7 +1101,7 @@ def test__connect_all_referrals(self, fixture_port, loopback_client: NVMeCLIClie
10551101 assert False , 'Unexpected failover.node'
10561102 with nc .connect_all_ctx (active_ip ):
10571103 data = nc .nvme_list_subsys ()
1058- assert self .subsys_path_count (data , subsys_nqn ) == 2
1104+ assert self .subsys_path_count (data , subsys_nqn ) == 2 if not use_spdk else 4
10591105 assert self .subsys_path_present (data ,
10601106 subsys_nqn ,
10611107 active_ip ,
@@ -1067,7 +1113,7 @@ def test__connect_all_referrals(self, fixture_port, loopback_client: NVMeCLIClie
10671113
10681114 with nc .connect_all_ctx (active_ip , NVME_ALT1_TCP_PORT ):
10691115 data = nc .nvme_list_subsys ()
1070- assert self .subsys_path_count (data , subsys_nqn ) == 2
1116+ assert self .subsys_path_count (data , subsys_nqn ) == 2 if not use_spdk else 4
10711117 assert self .subsys_path_present (data ,
10721118 subsys_nqn ,
10731119 active_ip ,
@@ -1079,7 +1125,7 @@ def test__connect_all_referrals(self, fixture_port, loopback_client: NVMeCLIClie
10791125
10801126 with nc .connect_all_ctx (standby_ip ):
10811127 data = nc .nvme_list_subsys ()
1082- assert self .subsys_path_count (data , subsys_nqn ) == 2
1128+ assert self .subsys_path_count (data , subsys_nqn ) == 2 if not use_spdk else 4
10831129 assert self .subsys_path_present (data ,
10841130 subsys_nqn ,
10851131 active_ip ,
@@ -1091,7 +1137,7 @@ def test__connect_all_referrals(self, fixture_port, loopback_client: NVMeCLIClie
10911137
10921138 with nc .connect_all_ctx (standby_ip , NVME_ALT1_TCP_PORT ):
10931139 data = nc .nvme_list_subsys ()
1094- assert self .subsys_path_count (data , subsys_nqn ) == 2
1140+ assert self .subsys_path_count (data , subsys_nqn ) == 2 if not use_spdk else 4
10951141 assert self .subsys_path_present (data ,
10961142 subsys_nqn ,
10971143 active_ip ,
0 commit comments