-
Notifications
You must be signed in to change notification settings - Fork 498
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cdae959
commit e2e5369
Showing
1 changed file
with
20 additions
and
12 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
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}", 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." | ||
) |