From e2e536978e3c384fdc29e6a5390f321e9e14309d Mon Sep 17 00:00:00 2001 From: Logan Cary Date: Wed, 7 Aug 2024 15:04:21 -0400 Subject: [PATCH] test with an smb share --- tests/api2/test_snapshot_count_alert.py | 32 +++++++++++++++---------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/tests/api2/test_snapshot_count_alert.py b/tests/api2/test_snapshot_count_alert.py index 3d9ad1ff46cce..4cc90d341c6aa 100644 --- a/tests/api2/test_snapshot_count_alert.py +++ b/tests/api2/test_snapshot_count_alert.py @@ -1,44 +1,52 @@ import pytest from pytest_dependency import depends from middlewared.test.integration.assets.pool import dataset +from middlewared.test.integration.assets.smb import smb_share from middlewared.test.integration.utils import call, mock from time import sleep +DATASET_NAME = "snapshot_count" +NUM_SNAPSHOTS = 10 + + def test_snapshot_total_count_alert(request): - with dataset("snapshot_count") as ds: + with dataset(DATASET_NAME) as ds: base = call("zfs.snapshot.query", [], {"count": True}) - with mock("pool.snapshottask.max_total_count", return_value=base + 10): - for i in range(10): + with mock("pool.snapshottask.max_total_count", return_value=base + NUM_SNAPSHOTS): + for i in range(NUM_SNAPSHOTS): call("zfs.snapshot.create", {"dataset": ds, "name": f"snap-{i}"}) assert call("alert.run_source", "SnapshotCount") == [] # snapshots_changed ZFS dataset property has 1 second resolution sleep(1) - call("zfs.snapshot.create", {"dataset": ds, "name": "snap-10"}) + call("zfs.snapshot.create", {"dataset": ds, "name": f"snap-{NUM_SNAPSHOTS}"}) alert = call("alert.run_source", "SnapshotCount")[0] assert alert["text"] % alert["args"] == ( - f"Your system has more snapshots ({base + 11}) than recommended ({base + 10}). Performance or " - "functionality might degrade." + f"Your system has more snapshots ({base + NUM_SNAPSHOTS + 1}) than recommended ({base + NUM_SNAPSHOTS}" + "). Performance or functionality might degrade." ) def test_snapshot_count_alert(request): - with dataset("snapshot_count") as ds: - with mock("pool.snapshottask.max_count", return_value=10): - for i in range(10): + with ( + dataset(DATASET_NAME) as ds, + smb_share(f"/mnt/{ds}", ds), + mock("pool.snapshottask.max_count", return_value=NUM_SNAPSHOTS) + ): + for i in range(NUM_SNAPSHOTS): call("zfs.snapshot.create", {"dataset": ds, "name": f"snap-{i}"}) assert call("alert.run_source", "SnapshotCount") == [] # snapshots_changed ZFS dataset property has 1 second resolution sleep(1) - call("zfs.snapshot.create", {"dataset": ds, "name": "snap-10"}) + call("zfs.snapshot.create", {"dataset": ds, "name": f"snap-{NUM_SNAPSHOTS}"}) alert = call("alert.run_source", "SnapshotCount")[0] assert alert["text"] % alert["args"] == ( - "SMB share tank/snapshot_count has more snapshots (11) than recommended (10). File Explorer may not " - "display all snapshots in the Previous Versions tab." + f"SMB share {ds} has more snapshots ({NUM_SNAPSHOTS + 1}) than recommended ({NUM_SNAPSHOTS}). File " + "Explorer may not display all snapshots in the Previous Versions tab." )