Skip to content

Commit

Permalink
test with an smb share
Browse files Browse the repository at this point in the history
  • Loading branch information
creatorcary committed Aug 7, 2024
1 parent cdae959 commit e2e5369
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions tests/api2/test_snapshot_count_alert.py
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."
)

0 comments on commit e2e5369

Please sign in to comment.