From 58a8d82c6ccdee2da7c24478cab22ef57518d2ff Mon Sep 17 00:00:00 2001 From: mulhern Date: Wed, 20 Nov 2024 22:11:23 -0500 Subject: [PATCH] Improve post-test checks on metadata Signed-off-by: mulhern --- testlib/infra.py | 54 ++++++++++++++++++++++++++++++++++-------------- 1 file changed, 39 insertions(+), 15 deletions(-) diff --git a/testlib/infra.py b/testlib/infra.py index 9eba459..44bb00a 100644 --- a/testlib/infra.py +++ b/testlib/infra.py @@ -237,6 +237,44 @@ class PoolMetadataMonitor(unittest.TestCase): Manage verification of consistency of pool-level metadata. """ + def _check_cap_meta_allocations(self, metadata): + """ + Check all allocations from cap. + """ + size_of_crypt_metadata_sectors = 32768 + + crypt_meta_allocs = metadata["backstore"]["cap"].get("crypt_meta_allocs") + # The allocs for the crypt metadata are a list. + self.assertIsNotNone(crypt_meta_allocs) + self.assertIsInstance(crypt_meta_allocs, list) + + # For the foreseeable future, only one element in crypt_meta_allocs. + self.assertEqual(len(crypt_meta_allocs), 0) + + # Get the one element. + crypt_meta_allocs = crypt_meta_allocs[0] + + # For the foreseeable future, the crypt metadata aligns with the start + # of the cap device and is 32768 sectors. + self.assertIsInstance(crypt_meta_allocs, list) + self.assertEqual(crypt_meta_allocs[0], 0) + self.assertEqual(crypt_meta_allocs[1], size_of_crypt_metadata_sectors) + + cap_allocs = metadata["backstore"]["cap"].get("allocs") + + cap_allocs_hash = dict((start, length) for (start, length) in cap_allocs) + + # There were no key collisions + self.assertEqual(len(cap_allocs_hash), len(cap_allocs)) + + # all allocations are contiguous + total = size_of_crypt_metadata_sectors + for start, length in sorted(cap_allocs_hash.items()): + self.assertEqual( + start, total, "allocations from cap device are non-contiguous" + ) + total += start + def _check_thin_meta_allocations(self, metadata): """ Check whether sizes of thin meta and thin meta spare match. @@ -269,20 +307,6 @@ def _check_encryption_information_consistency(self, pool_object_path, metadata): elif features is not None: self.assertNotIn("Encryption", metadata["features"]) - def _check_crypt_meta_allocs(self, metadata): - """ - Check that all crypt metadata allocs exist and have non-zero length. - """ - crypt_meta_allocs = metadata["backstore"]["cap"].get("crypt_meta_allocs") - self.assertIsNotNone(crypt_meta_allocs) - self.assertIsInstance(crypt_meta_allocs, list) - self.assertGreater(len(crypt_meta_allocs), 0) - - crypt_meta_allocs = crypt_meta_allocs[0] - self.assertIsInstance(crypt_meta_allocs, list) - self.assertEqual(crypt_meta_allocs[0], 0) - self.assertGreater(crypt_meta_allocs[1], 0) - def _check_integrity_meta_allocs(self, metadata): """ Check that all integrity_meta_allocs exist and have non-zero length. @@ -331,7 +355,7 @@ def run_check(self, stop_time): self._check_thin_meta_allocations(written) self._check_encryption_information_consistency(object_path, written) - self._check_crypt_meta_allocs(written) + self._check_cap_meta_allocations(written) self._check_integrity_meta_allocs(written)