@@ -233,18 +233,12 @@ def do_setup(self, ctxt):
233
233
svm_lib .do_setup (ctxt )
234
234
self ._libraries [svm_name ] = svm_lib
235
235
236
- def _remove_svm_lib (self , svm_name : str , svm_lib : NetAppMinimalLibrary ):
236
+ def _remove_svm_lib (self , svm_lib : NetAppMinimalLibrary ):
237
237
"""Remove resources for a given SVM library."""
238
238
# 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 = []
248
242
249
243
def _refresh_svm_libraries (self ):
250
244
return self ._actual_refresh_svm_libraries (context .get_admin_context ())
@@ -262,17 +256,16 @@ def _actual_refresh_svm_libraries(self, ctxt):
262
256
stale_svms = existing_libs - current_svms
263
257
for svm_name in stale_svms :
264
258
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 )
268
261
del self ._libraries [svm_name ]
269
262
270
263
# Add new SVM libraries
271
264
new_svms = current_svms - existing_libs
272
265
for svm_name in new_svms :
273
266
LOG .info ("Creating NVMe library for new SVM: %s" , svm_name )
267
+ lib = self ._create_svm_lib (svm_name )
274
268
try :
275
- lib = self ._create_svm_lib (svm_name )
276
269
# Call do_setup to initialize the library
277
270
lib .do_setup (ctxt )
278
271
lib .check_for_setup_error ()
@@ -283,13 +276,21 @@ def _actual_refresh_svm_libraries(self, ctxt):
283
276
"Failed to create library for SVM %s" ,
284
277
svm_name ,
285
278
)
279
+ self ._remove_svm_lib (lib )
286
280
LOG .info ("Final libraries loaded: %s" , list (self ._libraries .keys ()))
287
281
288
282
def check_for_setup_error (self ):
289
283
"""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 :
291
286
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 ]
293
294
294
295
# looping call to refresh SVM libraries
295
296
if not self ._looping_call :
0 commit comments