Skip to content

Commit

Permalink
Improve post-test checks on metadata
Browse files Browse the repository at this point in the history
Signed-off-by: mulhern <[email protected]>
  • Loading branch information
mulkieran committed Nov 21, 2024
1 parent e30395c commit 58a8d82
Showing 1 changed file with 39 additions and 15 deletions.
54 changes: 39 additions & 15 deletions testlib/infra.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 58a8d82

Please sign in to comment.