Skip to content

Commit

Permalink
Also check against the pool-level metadata
Browse files Browse the repository at this point in the history
Signed-off-by: mulhern <[email protected]>
  • Loading branch information
mulkieran committed Aug 8, 2024
1 parent 1111b29 commit 62bfd6b
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions tests/client-dbus/tests/udev/test_predict.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,32 +203,42 @@ def _check_fs_prediction(
# actual used for any filesystem.
self.assertLess(change, prediction_change)

def _check_prediction(self, prediction, mopool):
def _check_prediction(self, prediction, mopool, pool_metadata):
"""
Check the prediction against the values obtained from the D-Bus.
:param str prediction: result of calling script, JSON format
:param MOPool mopool: object with pool properties
:param dict pool_metadata: metadata just obtained from pool
"""
(success, total_physical_used) = mopool.TotalPhysicalUsed()
if not success:
raise RuntimeError("Pool's TotalPhysicalUsed property was invalid.")

(used_prediction, total_prediction) = (
(used_prediction, total_prediction, crypt_metadata_space) = (
prediction["used"],
prediction["total"],
prediction["crypt-metadata-space"],
)

self.assertEqual(
mopool.TotalPhysicalSize(),
total_prediction,
msg=f"Predicted sizes: {prediction}",
)

self.assertEqual(
Range(crypt_metadata_space),
Range(pool_metadata["backstore"]["cap"]["crypt_meta_allocs"], 512),
)

self.assertEqual(
total_physical_used, used_prediction, msg=f"Predicted sizes: {prediction}"
)

def _test_prediction(self, pool_name, *, fs_specs=None, overprovision=True):
def _test_prediction(
self, pool_name, *, fs_specs=None, overprovision=True
): # pylint: disable=too-many-locals
"""
Helper function to verify that the prediction matches the reality to
an acceptable degree.
Expand All @@ -251,11 +261,19 @@ def _test_prediction(self, pool_name, *, fs_specs=None, overprovision=True):
mopool = MOPool(pool)

physical_sizes = _get_block_device_sizes(pool_object_path, managed_objects)
pool_proxy = get_object(pool_object_path)
(pool_metadata, return_code, message) = Pool.Methods.Metadata(
pool_proxy, {"current": False}
)

if return_code != 0:
raise RuntimeError(f"Failed to create a requested filesystem: {message}")

pre_prediction = _call_predict_usage(
mopool.Encrypted(), physical_sizes, overprovision=overprovision
)

self._check_prediction(pre_prediction, mopool)
self._check_prediction(pre_prediction, mopool, pool_metadata)

change = _possibly_add_filesystems(pool_object_path, fs_specs=fs_specs)

Expand Down

0 comments on commit 62bfd6b

Please sign in to comment.