-
Notifications
You must be signed in to change notification settings - Fork 494
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NAS-130271 / 24.10 / Check SnapshotCountAlert on SMB shares only (#14161
) * only alert on smb shares * fix middleware call * allow multiple alerts * test with an smb share * fix test * address @yocalebo * test * Revert "test" This reverts commit 67e4973. * address @anodos325
- Loading branch information
1 parent
1c6b43e
commit fa1cd29
Showing
2 changed files
with
52 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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}", DATASET_NAME), | ||
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"] == ( | ||
"Dataset tank/snapshot_count has more snapshots (11) than recommended (10). Performance or " | ||
"functionality might degrade." | ||
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." | ||
) |