From 390f18a3a4943a17fb911deb323f0c31c430950e Mon Sep 17 00:00:00 2001 From: Franziska Kunsmann Date: Wed, 29 Dec 2021 13:23:07 +0100 Subject: [PATCH] hooks: test zfs metadata consistency --- bundles/zfs/items.py | 2 ++ hooks/test_backup_metadata.py | 16 ++++++++++++++- hooks/test_zfs_consistency.py | 38 +++++++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 hooks/test_zfs_consistency.py diff --git a/bundles/zfs/items.py b/bundles/zfs/items.py index 11661d5..c21dd3c 100644 --- a/bundles/zfs/items.py +++ b/bundles/zfs/items.py @@ -81,6 +81,8 @@ for name, attrs in node.metadata.get('zfs/datasets', {}).items(): if 'mountpoint' not in attrs: zfs_datasets[name]['canmount'] = 'off' + # https://github.com/bundlewrap/bundlewrap/commit/76647590d684446f146cedb89518458f18dd229e + # zfs_datasets[name]['mountpoint'] = 'none' else: zfs_datasets[name]['canmount'] = 'on' diff --git a/hooks/test_backup_metadata.py b/hooks/test_backup_metadata.py index 337121b..4937989 100644 --- a/hooks/test_backup_metadata.py +++ b/hooks/test_backup_metadata.py @@ -1,8 +1,22 @@ +from bundlewrap.exceptions import BundleError +from bundlewrap.utils.text import bold, green, yellow +from bundlewrap.utils.ui import io + def test_node(repo, node, **kwargs): if not node.has_bundle('backup-client'): return if node.metadata.get('backups/exclude_from_backups', False): + io.stderr('{x} {node} exclude_from_backups=True'.format( + x=yellow("»"), + node=bold(node.name), + )) return - assert len(node.metadata.get('backups/paths', set())) > 0, f'{node.name} has backups configured, but no backup paths defined!' + if not len(node.metadata.get('backups/paths', set())): + raise BundleError(f'{node.name} has backups configured, but no backup paths defined!') + + io.stdout('{x} {node} backup metadata conforms to standards'.format( + x=green("✓"), + node=bold(node.name), + )) diff --git a/hooks/test_zfs_consistency.py b/hooks/test_zfs_consistency.py new file mode 100644 index 0000000..d7231e5 --- /dev/null +++ b/hooks/test_zfs_consistency.py @@ -0,0 +1,38 @@ +from bundlewrap.exceptions import BundleError +from bundlewrap.utils.text import bold, green +from bundlewrap.utils.ui import io + +# https://github.com/bundlewrap/bundlewrap/commit/a261304b583b78a16ad44def5508cbc27d5f1c3f +# https://github.com/bundlewrap/bundlewrap/commit/76647590d684446f146cedb89518458f18dd229e + +def test_node(repo, node, **kwargs): + if not node.has_bundle('zfs'): + return + + zfs_pools = set(node.metadata.get('zfs/pools', {}).keys()) + zfs_mountpoints = {} + + for name, attrs in node.metadata.get('zfs/datasets', {}).items(): + if attrs.get('mountpoint'): + if attrs['mountpoint'] in zfs_mountpoints: + raise BundleError('{n} zfs_dataset:{ds} mountpoint is already taken by {o}'.format( + n=node.name, + ds=name, + o=zfs_mountpoints[attrs['mountpoint']], + )) + + zfs_mountpoints[attrs['mountpoint']] = name + + pool_name = name.split('/', 1)[0] + + if pool_name not in zfs_pools: + raise BundleError('{n} zfs_dataset:{ds} wants zfs_pool:{pool}, which wasn\'t found'.format( + n=node.name, + ds=name, + pool=pool_name, + )) + + io.stdout('{x} {node} zfs metadata is consistent'.format( + x=green("✓"), + node=bold(node.name), + ))