zfs-verify stuff

This commit is contained in:
Edwin Eefting
2022-01-18 23:46:08 +01:00
parent 86d504722c
commit 787e3dba9c
3 changed files with 82 additions and 32 deletions

View File

@ -1,7 +1,11 @@
import os
from .ZfsAuto import ZfsAuto
from .ZfsDataset import ZfsDataset
from .ZfsNode import ZfsNode
import sys
import platform
class ZfsAutoverify(ZfsAuto):
"""The zfs-autoverify class, default agruments and stuff come from ZfsAuto"""
@ -30,7 +34,16 @@ class ZfsAutoverify(ZfsAuto):
return (parser)
def verify_datasets(self, source_node, source_datasets, target_node):
def verify_filesystem(self, source_dataset, source_mnt, target_dataset, target_mnt):
pass
def verify_volume(self, source_dataset, target_dataset):
pass
def verify_datasets(self, source_node, source_mnt, source_datasets, target_node, target_mnt):
fail_count=0
count = 0
@ -47,7 +60,12 @@ class ZfsAutoverify(ZfsAuto):
target_dataset = ZfsDataset(target_node, target_name)
if source_dataset.properties['type']=="filesystem":
print("JOOO")
self.verify_filesystem(source_dataset, source_mnt, target_dataset, target_mnt)
elif source_dataset.properties['type']=="volume":
self.verify_volume(source_dataset, target_dataset)
else:
raise(Exception("{} has unknown type {}".format(source_dataset, source_dataset.properties['type'])))
except Exception as e:
fail_count = fail_count + 1
@ -55,10 +73,31 @@ class ZfsAutoverify(ZfsAuto):
if self.args.debug:
raise
def create_mountpoints(self, source_node, target_node):
# prepare mount points
source_mnt = "/tmp/zfs-autoverify_source_{}_{}".format(platform.node(), os.getpid())
source_node.run(["mkdir", source_mnt])
target_mnt = "/tmp/zfs-autoverify_target_{}_{}".format(platform.node(), os.getpid())
target_node.run(["mkdir", target_mnt])
return source_mnt, target_mnt
def cleanup_mountpoint(self, node, mnt):
node.run([ "umount", mnt ], hide_errors=True, valid_exitcodes=[] )
node.run([ "rmdir", mnt ], hide_errors=True, valid_exitcodes=[] )
def run(self):
source_node=None
source_mnt=None
target_node=None
target_mnt=None
try:
################ create source zfsNode
@ -90,11 +129,32 @@ class ZfsAutoverify(ZfsAuto):
description="[Target]")
target_node.verbose("Verify datasets under: {}".format(self.args.target_path))
source_mnt, target_mnt=self.create_mountpoints(source_node, target_node)
fail_count = self.verify_datasets(
source_node=source_node,
source_mnt=source_mnt,
source_datasets=source_datasets,
target_mnt=target_mnt,
target_node=target_node)
if not fail_count:
if self.args.test:
self.set_title("All tests successful.")
else:
self.set_title("All datasets verified ok")
else:
if fail_count != 255:
self.error("{} dataset(s) failed!".format(fail_count))
if self.args.test:
self.verbose("")
self.warning("TEST MODE - DID NOT VERIFY ANYTHING!")
return fail_count
except Exception as e:
self.error("Exception: " + str(e))
if self.args.debug:
@ -103,6 +163,17 @@ class ZfsAutoverify(ZfsAuto):
except KeyboardInterrupt:
self.error("Aborted")
return 255
finally:
# cleanup
if source_mnt is not None:
self.cleanup_mountpoint(source_node, source_mnt)
if target_mnt is not None:
self.cleanup_mountpoint(target_node, target_mnt)
def cli():
import sys