def delete_fs(self, l_disk): """ checks for disk/dir mount, unmount if mounted and checks for filesystem exitance 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...")
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