Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
155 changes: 17 additions & 138 deletions io/disk/bonnie.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,9 @@
"""

import os
import time
import getpass
from avocado import Test
from avocado.utils import archive
from avocado.utils import wait
from avocado.utils import build
from avocado.utils import disk
from avocado.utils import dmesg
Expand All @@ -37,6 +35,7 @@
from avocado.utils.partition import Partition
from avocado.utils.software_manager.manager import SoftwareManager
from avocado.utils.partition import PartitionError
from avocado.utils.disk import cleanup_disks


class Bonnie(Test):
Expand Down Expand Up @@ -197,135 +196,11 @@ def pre_cleanup(self):
cleanup the disk and directory before test starts on it
"""
self.log.info("Pre_cleaning of disk and directories...")
disk_list = ['/dev/mapper/avocado_vg-avocado_lv', self.raid_name,
self.disk]
for disk in disk_list:
self.delete_fs(disk)
self.log.info("checking ...lv/vg existence...")
if lv_utils.lv_check(self.vgname, self.lvname):
self.log.info("found lv existence... deleting it")
self.delete_lv()
elif lv_utils.vg_check(self.vgname):
self.log.info("found vg existence ... deleting it")
lv_utils.vg_remove(self.vgname)
self.log.info("checking for softwareraid existence...")
if self.sw_raid.exists():
self.log.info("found softwareraid existence... deleting it")
self.delete_raid()
else:
self.log.info("No softwareraid detected ")
self.log.info("\n End of pre_cleanup")

def delete_raid(self):
"""
it checks for existing of raid and deletes it if exists
"""
self.log.info("deleting Sraid %s" % self.raid_name)

def is_raid_deleted():
self.sw_raid.stop()
self.sw_raid.clear_superblock()
self.log.info("checking for raid metadata")
cmd = "wipefs -af %s" % self.disk
process.system(cmd, shell=True, ignore_status=True)
if self.sw_raid.exists():
return False
return True
self.log.info("checking lvm_metadata on %s" % self.raid_name)
cmd = 'blkid -o value -s TYPE %s' % self.raid_name
out = process.system_output(cmd, shell=True,
ignore_status=True).decode("utf-8")
if out == 'LVM2_member':
cmd = "wipefs -af %s" % self.raid_name
process.system(cmd, shell=True, ignore_status=True)
if wait.wait_for(is_raid_deleted, timeout=10):
self.log.info("software raid %s deleted" % self.raid_name)
else:
self.err_mesg.append("failed to delete sraid %s" % self.raid_name)

def delete_lv(self):
"""
checks if lv/vg exists and delete them along with its metadata
if exists.
"""
def is_lv_deleted():
lv_utils.lv_remove(self.vgname, self.lvname)
time.sleep(5)
lv_utils.vg_remove(self.vgname)
if lv_utils.lv_check(self.vgname, self.lvname):
return False
return True
if wait.wait_for(is_lv_deleted, timeout=10):
self.log.info("lv %s deleted" % self.lvname)
else:
self.err_mesg.append("failed to delete lv %s" % self.lvname)
# checking and deleting if lvm_meta_data exists after lv removed
cmd = 'blkid -o value -s TYPE %s' % self.lv_disk
out = process.system_output(cmd, shell=True,
ignore_status=True).decode("utf-8")
if out == 'LVM2_member':
cmd = "wipefs -af %s" % self.lv_disk
process.system(cmd, shell=True, ignore_status=True)

def delete_fs(self, l_disk):
"""
checks for disk/dir mount, unmount if mounted and checks for
filesystem existence and wipe it off after dir/disk unmount.

:param l_disk: disk name for which you want to check the mount status
:return: None
"""
def is_fs_deleted():
cmd = "wipefs -af %s" % l_disk
process.system(cmd, shell=True, ignore_status=True)
if disk.fs_exists(l_disk):
return False
return True

def is_disk_unmounted():
cmd = "umount %s" % l_disk
cmd1 = 'umount /dev/mapper/avocado_vg-avocado_lv'
process.system(cmd, shell=True, ignore_status=True)
process.system(cmd1, shell=True, ignore_status=True)
if disk.is_disk_mounted(l_disk):
return False
return True

def is_dir_unmounted():
cmd = 'umount %s' % self.dir
process.system(cmd, shell=True, ignore_status=True)
if disk.is_dir_mounted(self.dir):
return False
return True

self.log.info("checking if disk is mounted.")
if disk.is_disk_mounted(l_disk):
self.log.info("%s is mounted, unmounting it ....", l_disk)
if wait.wait_for(is_disk_unmounted, timeout=10):
self.log.info("%s unmounted successfully" % l_disk)
else:
self.err_mesg.append("%s unmount failed", l_disk)
else:
self.log.info("disk %s not mounted." % l_disk)
self.log.info("checking if dir %s is mounted." % self.dir)
if disk.is_dir_mounted(self.dir):
self.log.info("%s is mounted, unmounting it ....", self.dir)
if wait.wait_for(is_dir_unmounted, timeout=10):
self.log.info("%s unmounted successfully" % self.dir)
else:
self.err_mesg.append("failed to unount %s", self.dir)
else:
self.log.info("dir %s not mounted." % self.dir)
self.log.info("checking if fs exists in {}" .format(l_disk))
if disk.fs_exists(l_disk):
self.log.info("found fs on %s, removing it....", l_disk)
if wait.wait_for(is_fs_deleted, timeout=10):
self.log.info("fs removed successfully..")
else:
self.err_mesg.append(f'failed to delete fs on {l_disk}')
else:
self.log.info(f'No fs detected on {self.disk}')
self.log.info("Running dd...")
try:
cleanup_disks([self.disk], logger=self.log, mode="full")
self.log.info("Pre-cleanup completed successfully")
except Exception as e:
self.log.warning("Pre-cleanup encountered issues: %s", e)

def test(self):
"""
Expand All @@ -345,12 +220,16 @@ def tearDown(self):
'''
Cleanup of disk used to perform this test
'''
if self.fs_create:
self.delete_fs(self.target)
if self.lv_create:
self.delete_lv()
if self.raid_create:
self.delete_raid()
dmesg.clear_dmesg()
if hasattr(self, 'disk') and self.disk:
try:
cleanup_disks([self.disk], logger=self.log, mode="full")
except Exception as e:
self.log.error("Disk cleanup failed for %s: %s", self.disk, e)

try:
dmesg.clear_dmesg()
except Exception as e:
self.log.warning("Failed to clear dmesg: %s", e)

if self.err_mesg:
self.warn("test failed due to following errors %s" % self.err_mesg)
45 changes: 15 additions & 30 deletions io/disk/dbench.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
from avocado.utils.partition import Partition
from avocado.utils.partition import PartitionError
from avocado.utils.software_manager.manager import SoftwareManager
from avocado.utils.disk import cleanup_disks


class Dbench(Test):
Expand Down Expand Up @@ -127,30 +128,21 @@ def setUp(self):
self.fs_create = True

def pre_cleanup(self):
umount_dir = "umount -f %s" % self.mountpoint
process.system(umount_dir, shell=True, ignore_status=True)
delete_lv = "lvremove -f /dev/mapper/avocado_vg-avocado_lv"
process.system(delete_lv, shell=True, ignore_status=True)
delete_vg = "vgremove -f avocado_vg"
process.system(delete_vg, shell=True, ignore_status=True)
delete_rd = 'mdadm --stop /dev/%s' % self.md_name
process.system(delete_rd, shell=True, ignore_status=True)

def clear_disk(self, obj, disk):
obj.unmount()
delete_fs = "dd if=/dev/zero bs=512 count=512 of=%s" % disk
if process.system(delete_fs, shell=True, ignore_status=False):
self.fail("Failed to delete filesystem on %s", disk)
"""
cleanup the disk and directory before test starts on it
"""
self.log.info("Pre_cleaning of disk and directories...")
try:
cleanup_disks([self.disk], logger=self.log)
self.log.info("Pre-cleanup completed successfully")
except Exception as e:
self.log.warning("Pre-cleanup encountered issues: %s", e)

def create_raid(self, l_disk, l_raid_name):
self.sraid = softwareraid.SoftwareRaid(l_raid_name, '0',
l_disk.split(), '1.2')
self.sraid.create()

def delete_raid(self):
self.sraid.stop()
self.sraid.clear_superblock()

def create_lv(self, l_disk):
vgname = 'avocado_vg'
lvname = 'avocado_lv'
Expand All @@ -159,12 +151,6 @@ def create_lv(self, l_disk):
lv_utils.lv_create(vgname, lvname, lv_size)
return '/dev/mapper/%s-%s' % (vgname, lvname)

def delete_lv(self):
vgname = 'avocado_vg'
lvname = 'avocado_lv'
lv_utils.lv_remove(vgname, lvname)
lv_utils.vg_remove(vgname)

def create_fs(self, l_disk, fstype):
self.part_obj = Partition(l_disk, mountpoint=self.mountpoint)
self.part_obj.unmount(force=True)
Expand Down Expand Up @@ -200,9 +186,8 @@ def tearDown(self):
'''
Cleanup of disk used to perform this test
'''
if self.fs_create:
self.clear_disk(self.part_obj, self.disk)
if self.lv_create:
self.delete_lv()
if self.raid_create:
self.delete_raid()
if hasattr(self, 'disk') and self.disk:
try:
cleanup_disks([self.disk], logger=self.log, mode="full")
except Exception as e:
self.log.error("Disk cleanup failed for %s: %s", self.disk, e)
22 changes: 14 additions & 8 deletions io/disk/disk_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
from avocado.utils.software_manager.manager import SoftwareManager
from avocado.utils.process import CmdError
from avocado.utils.partition import PartitionError
from avocado.utils.disk import cleanup_disks


class DiskInfo(Test):
Expand Down Expand Up @@ -297,11 +298,16 @@ def tearDown(self):
'''
Unmount the directory at the end if in case of test fails in between
'''
if hasattr(self, "part_obj"):
if self.disk is not None:
self.log.info("Unmounting directory %s" % self.dirs)
self.part_obj.unmount()
self.log.info("Removing the filesystem created on %s" % self.disk)
delete_fs = f"dd if=/dev/zero bs=512 count=512 of={self.disk}"
if process.system(delete_fs, shell=True, ignore_status=True):
self.fail(f"Failed to delete filesystem on {self.disk}")
try:
if hasattr(self, "part_obj"):
if self.disk is not None:
self.log.info("Unmounting directory %s" % self.dirs)
self.part_obj.unmount()
except Exception as e:
self.log.warning("Failed to unmount: %s", e)

if hasattr(self, 'disk') and self.disk:
try:
cleanup_disks([self.disk], logger=self.log, mode="full")
except Exception as e:
self.log.error("Disk cleanup failed for %s: %s", self.disk, e)
Loading
Loading