2323"""
2424
2525import os
26- import time
2726import getpass
2827from avocado import Test
2928from avocado .utils import archive
30- from avocado .utils import wait
3129from avocado .utils import build
3230from avocado .utils import disk
3331from avocado .utils import dmesg
3735from avocado .utils .partition import Partition
3836from avocado .utils .software_manager .manager import SoftwareManager
3937from avocado .utils .partition import PartitionError
38+ from disk_cleanup import cleanup_disks
4039
4140
4241class Bonnie (Test ):
@@ -197,135 +196,11 @@ def pre_cleanup(self):
197196 cleanup the disk and directory before test starts on it
198197 """
199198 self .log .info ("Pre_cleaning of disk and directories..." )
200- disk_list = ['/dev/mapper/avocado_vg-avocado_lv' , self .raid_name ,
201- self .disk ]
202- for disk in disk_list :
203- self .delete_fs (disk )
204- self .log .info ("checking ...lv/vg existence..." )
205- if lv_utils .lv_check (self .vgname , self .lvname ):
206- self .log .info ("found lv existence... deleting it" )
207- self .delete_lv ()
208- elif lv_utils .vg_check (self .vgname ):
209- self .log .info ("found vg existence ... deleting it" )
210- lv_utils .vg_remove (self .vgname )
211- self .log .info ("checking for softwareraid existence..." )
212- if self .sw_raid .exists ():
213- self .log .info ("found softwareraid existence... deleting it" )
214- self .delete_raid ()
215- else :
216- self .log .info ("No softwareraid detected " )
217- self .log .info ("\n End of pre_cleanup" )
218-
219- def delete_raid (self ):
220- """
221- it checks for existing of raid and deletes it if exists
222- """
223- self .log .info ("deleting Sraid %s" % self .raid_name )
224-
225- def is_raid_deleted ():
226- self .sw_raid .stop ()
227- self .sw_raid .clear_superblock ()
228- self .log .info ("checking for raid metadata" )
229- cmd = "wipefs -af %s" % self .disk
230- process .system (cmd , shell = True , ignore_status = True )
231- if self .sw_raid .exists ():
232- return False
233- return True
234- self .log .info ("checking lvm_metadata on %s" % self .raid_name )
235- cmd = 'blkid -o value -s TYPE %s' % self .raid_name
236- out = process .system_output (cmd , shell = True ,
237- ignore_status = True ).decode ("utf-8" )
238- if out == 'LVM2_member' :
239- cmd = "wipefs -af %s" % self .raid_name
240- process .system (cmd , shell = True , ignore_status = True )
241- if wait .wait_for (is_raid_deleted , timeout = 10 ):
242- self .log .info ("software raid %s deleted" % self .raid_name )
243- else :
244- self .err_mesg .append ("failed to delete sraid %s" % self .raid_name )
245-
246- def delete_lv (self ):
247- """
248- checks if lv/vg exists and delete them along with its metadata
249- if exists.
250- """
251- def is_lv_deleted ():
252- lv_utils .lv_remove (self .vgname , self .lvname )
253- time .sleep (5 )
254- lv_utils .vg_remove (self .vgname )
255- if lv_utils .lv_check (self .vgname , self .lvname ):
256- return False
257- return True
258- if wait .wait_for (is_lv_deleted , timeout = 10 ):
259- self .log .info ("lv %s deleted" % self .lvname )
260- else :
261- self .err_mesg .append ("failed to delete lv %s" % self .lvname )
262- # checking and deleting if lvm_meta_data exists after lv removed
263- cmd = 'blkid -o value -s TYPE %s' % self .lv_disk
264- out = process .system_output (cmd , shell = True ,
265- ignore_status = True ).decode ("utf-8" )
266- if out == 'LVM2_member' :
267- cmd = "wipefs -af %s" % self .lv_disk
268- process .system (cmd , shell = True , ignore_status = True )
269-
270- def delete_fs (self , l_disk ):
271- """
272- checks for disk/dir mount, unmount if mounted and checks for
273- filesystem existence and wipe it off after dir/disk unmount.
274-
275- :param l_disk: disk name for which you want to check the mount status
276- :return: None
277- """
278- def is_fs_deleted ():
279- cmd = "wipefs -af %s" % l_disk
280- process .system (cmd , shell = True , ignore_status = True )
281- if disk .fs_exists (l_disk ):
282- return False
283- return True
284-
285- def is_disk_unmounted ():
286- cmd = "umount %s" % l_disk
287- cmd1 = 'umount /dev/mapper/avocado_vg-avocado_lv'
288- process .system (cmd , shell = True , ignore_status = True )
289- process .system (cmd1 , shell = True , ignore_status = True )
290- if disk .is_disk_mounted (l_disk ):
291- return False
292- return True
293-
294- def is_dir_unmounted ():
295- cmd = 'umount %s' % self .dir
296- process .system (cmd , shell = True , ignore_status = True )
297- if disk .is_dir_mounted (self .dir ):
298- return False
299- return True
300-
301- self .log .info ("checking if disk is mounted." )
302- if disk .is_disk_mounted (l_disk ):
303- self .log .info ("%s is mounted, unmounting it ...." , l_disk )
304- if wait .wait_for (is_disk_unmounted , timeout = 10 ):
305- self .log .info ("%s unmounted successfully" % l_disk )
306- else :
307- self .err_mesg .append ("%s unmount failed" , l_disk )
308- else :
309- self .log .info ("disk %s not mounted." % l_disk )
310- self .log .info ("checking if dir %s is mounted." % self .dir )
311- if disk .is_dir_mounted (self .dir ):
312- self .log .info ("%s is mounted, unmounting it ...." , self .dir )
313- if wait .wait_for (is_dir_unmounted , timeout = 10 ):
314- self .log .info ("%s unmounted successfully" % self .dir )
315- else :
316- self .err_mesg .append ("failed to unount %s" , self .dir )
317- else :
318- self .log .info ("dir %s not mounted." % self .dir )
319- self .log .info ("checking if fs exists in {}" .format (l_disk ))
320- if disk .fs_exists (l_disk ):
321- self .log .info ("found fs on %s, removing it...." , l_disk )
322- if wait .wait_for (is_fs_deleted , timeout = 10 ):
323- self .log .info ("fs removed successfully.." )
324- else :
325- self .err_mesg .append (f'failed to delete fs on { l_disk } ' )
326- else :
327- self .log .info (f'No fs detected on { self .disk } ' )
328- self .log .info ("Running dd..." )
199+ try :
200+ cleanup_disks ([self .disk ], logger = self .log , mode = "full" )
201+ self .log .info ("Pre-cleanup completed successfully" )
202+ except Exception as e :
203+ self .log .warning ("Pre-cleanup encountered issues: %s" , e )
329204
330205 def test (self ):
331206 """
@@ -345,12 +220,16 @@ def tearDown(self):
345220 '''
346221 Cleanup of disk used to perform this test
347222 '''
348- if self .fs_create :
349- self .delete_fs (self .target )
350- if self .lv_create :
351- self .delete_lv ()
352- if self .raid_create :
353- self .delete_raid ()
354- dmesg .clear_dmesg ()
223+ if hasattr (self , 'disk' ) and self .disk :
224+ try :
225+ cleanup_disks ([self .disk ], logger = self .log , mode = "full" )
226+ except Exception as e :
227+ self .log .error ("Disk cleanup failed for %s: %s" , self .disk , e )
228+
229+ try :
230+ dmesg .clear_dmesg ()
231+ except Exception as e :
232+ self .log .warning ("Failed to clear dmesg: %s" , e )
233+
355234 if self .err_mesg :
356235 self .warn ("test failed due to following errors %s" % self .err_mesg )
0 commit comments