@@ -206,6 +206,53 @@ def test_resize_vdi(self, vm_on_linstor_sr: VM) -> None:
206206 vm .wait_for_os_booted ()
207207 vm .shutdown (verify = True )
208208
209+ def test_forget_and_introduce_sr (self , linstor_sr : SR ):
210+ sr = linstor_sr
211+ sr_name = sr .param_get ('name-label' )
212+ all_pbds = sr .pbd_uuids ()
213+ pbd_config_hosts : list [list [str ]] = []
214+ pbd_config_devices : list [list [str ]] = []
215+ for pbd in all_pbds :
216+ pbd_config_hosts .append (
217+ safe_split (sr .pool .master .xe ('pbd-param-get' , {'uuid' : pbd , 'param-name' : 'host-uuid' }))
218+ )
219+ pbd_config_devices .append (
220+ safe_split (sr .pool .master .xe ('pbd-param-get' , {'uuid' : pbd , 'param-name' : 'device-config' }))
221+ )
222+
223+ sr .forget ()
224+ logging .info (f"Forgot SR { sr .uuid } successfully" )
225+
226+ with pytest .raises (Exception ):
227+ sr_type = sr .param_get ('type' ) # Expecting exception as sr should not exist
228+ sr .plug_pbds () # Plug back pbds and let teardown handle SR destroy
229+ pytest .fail (f"SR still exists; returned type: { sr_type } " )
230+
231+ logging .info (f"Introducing SR { sr .uuid } back" )
232+ new_sr = SR .introduce (sr .pool , type = 'linstor' , shared = True , name_label = sr_name , sr_uuid = sr .uuid )
233+
234+ # Example pbd_config_device
235+ # {provisioning: thin; redundancy: 3; group-name: linstor_group/thin_device}
236+ for pbd_config_host , pbd_config_device in zip (pbd_config_hosts , pbd_config_devices ):
237+ pbd_config_dict = dict (
238+ (kv .split (": " )[0 ].strip (), kv .split (": " )[1 ].strip ())
239+ for kv in pbd_config_device [0 ].split (";" )
240+ if ": " in kv # Ensure key-value pair
241+ )
242+
243+ sr .pool .master .xe (
244+ "pbd-create" ,
245+ {
246+ "sr-uuid" : new_sr .uuid ,
247+ "host-uuid" : pbd_config_host [0 ],
248+ "content-type" : "user" ,
249+ "device-config" : pbd_config_dict ,
250+ },
251+ )
252+
253+ new_sr .plug_pbds (verify = True )
254+ logging .info (f"Introduced SR { new_sr .uuid } successfully" )
255+
209256 # *** tests with reboots (longer tests).
210257
211258 @pytest .mark .reboot
0 commit comments