@@ -233,18 +233,12 @@ def do_setup(self, ctxt):
233233 svm_lib .do_setup (ctxt )
234234 self ._libraries [svm_name ] = svm_lib
235235
236- def _remove_svm_lib (self , svm_name : str , svm_lib : NetAppMinimalLibrary ):
236+ def _remove_svm_lib (self , svm_lib : NetAppMinimalLibrary ):
237237 """Remove resources for a given SVM library."""
238238 # TODO: Need to free up resources here.
239- LOG .info ("Removing resources for SVM library %s" , svm_name )
240- # Stop any looping calls if they exist
241- if svm_lib ._looping_call and hasattr (svm_lib , "loopingcalls" ):
242- LOG .info ("Stopping looping call for SVM library %s" , svm_name )
243- svm_lib .loopingcalls .stop_tasks ()
244- # Adding None coz it has a reference to the looping call
245- svm_lib .looping_call = None
246- # There are other attributes which are in svm_lib even after
247- # Stopping the looping.
239+ for task in svm_lib .loopingcalls .tasks :
240+ task .looping_call .stop ()
241+ svm_lib .loopingcalls .tasks = []
248242
249243 def _refresh_svm_libraries (self ):
250244 return self ._actual_refresh_svm_libraries (context .get_admin_context ())
@@ -262,17 +256,16 @@ def _actual_refresh_svm_libraries(self, ctxt):
262256 stale_svms = existing_libs - current_svms
263257 for svm_name in stale_svms :
264258 LOG .info ("Removing stale NVMe library for SVM: %s" , svm_name )
265- # TODO : stop looping calls, free resources.
266- svm_lib = self ._libraries .get (svm_name )
267- self ._remove_svm_lib (svm_name , svm_lib )
259+ svm_lib = self ._libraries [svm_name ]
260+ self ._remove_svm_lib (svm_lib )
268261 del self ._libraries [svm_name ]
269262
270263 # Add new SVM libraries
271264 new_svms = current_svms - existing_libs
272265 for svm_name in new_svms :
273266 LOG .info ("Creating NVMe library for new SVM: %s" , svm_name )
267+ lib = self ._create_svm_lib (svm_name )
274268 try :
275- lib = self ._create_svm_lib (svm_name )
276269 # Call do_setup to initialize the library
277270 lib .do_setup (ctxt )
278271 lib .check_for_setup_error ()
@@ -283,13 +276,21 @@ def _actual_refresh_svm_libraries(self, ctxt):
283276 "Failed to create library for SVM %s" ,
284277 svm_name ,
285278 )
279+ self ._remove_svm_lib (lib )
286280 LOG .info ("Final libraries loaded: %s" , list (self ._libraries .keys ()))
287281
288282 def check_for_setup_error (self ):
289283 """Check for setup errors."""
290- for svm_name , svm_lib in self ._libraries .items ():
284+ svm_to_init = set (self ._libraries .keys ())
285+ for svm_name in svm_to_init :
291286 LOG .info ("Checking NVMe library for errors for SVM %s" , svm_name )
292- svm_lib .check_for_setup_error ()
287+ svm_lib = self ._libraries [svm_name ]
288+ try :
289+ svm_lib .check_for_setup_error ()
290+ except Exception :
291+ LOG .exception ("Failed to initialize SVM %s, skipping" , svm_name )
292+ self ._remove_svm_lib (svm_lib )
293+ del self ._libraries [svm_name ]
293294
294295 # looping call to refresh SVM libraries
295296 if not self ._looping_call :
0 commit comments