feat(agent): zfs collector for pools + datasets/snapshots with fixture tests
This commit is contained in:
parent
6fca450d7e
commit
8c3e953e4e
5 changed files with 305 additions and 0 deletions
62
agent/test/proxmox_agent/collectors/zfs_test.exs
Normal file
62
agent/test/proxmox_agent/collectors/zfs_test.exs
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
defmodule ProxmoxAgent.Collectors.ZfsTest do
|
||||
use ExUnit.Case, async: true
|
||||
|
||||
alias ProxmoxAgent.Collectors.Zfs
|
||||
|
||||
@fixtures Path.expand("../../fixtures/zfs", __DIR__)
|
||||
|
||||
defp fake_runner do
|
||||
fn
|
||||
"zpool", ["list", "-j", "--json-int"] ->
|
||||
{:ok, File.read!(Path.join(@fixtures, "zpool_list.json"))}
|
||||
|
||||
"zpool", ["status", "-j", "--json-flat-vdevs", "--json-int"] ->
|
||||
{:ok, File.read!(Path.join(@fixtures, "zpool_status.json"))}
|
||||
|
||||
"zfs", ["list", "-j", "--json-int", "-t", "all"] ->
|
||||
{:ok, File.read!(Path.join(@fixtures, "zfs_list.json"))}
|
||||
end
|
||||
end
|
||||
|
||||
describe "collect_pools/1" do
|
||||
test "returns a summary per pool" do
|
||||
sample = Zfs.collect_pools(runner: fake_runner())
|
||||
assert is_list(sample.pools)
|
||||
assert length(sample.pools) == 2
|
||||
rpool = Enum.find(sample.pools, &(&1.name == "rpool"))
|
||||
tank = Enum.find(sample.pools, &(&1.name == "tank"))
|
||||
|
||||
assert rpool.health == "ONLINE"
|
||||
assert rpool.capacity_percent == 40
|
||||
assert rpool.fragmentation_percent == 17
|
||||
assert rpool.size_bytes == 500_000_000_000
|
||||
assert rpool.error_count == 0
|
||||
assert rpool.degraded_vdev_count == 0
|
||||
|
||||
assert tank.health == "DEGRADED"
|
||||
assert tank.error_count == 2
|
||||
assert tank.degraded_vdev_count == 1
|
||||
end
|
||||
|
||||
test "populates errors list when zpool fails" do
|
||||
failing = fn _, _ -> {:error, {:enoent, "zpool"}} end
|
||||
sample = Zfs.collect_pools(runner: failing)
|
||||
assert sample.pools == []
|
||||
assert length(sample.errors) >= 1
|
||||
end
|
||||
end
|
||||
|
||||
describe "collect_datasets/1" do
|
||||
test "returns datasets and per-dataset snapshot summary" do
|
||||
sample = Zfs.collect_datasets(runner: fake_runner())
|
||||
assert length(sample.datasets) == 2
|
||||
|
||||
rpool_data = Enum.find(sample.datasets, &(&1.name == "rpool/data"))
|
||||
assert rpool_data.used_bytes == 100_000_000_000
|
||||
assert rpool_data.usedbysnapshots_bytes == 2_000_000_000
|
||||
assert rpool_data.snapshot_count == 2
|
||||
assert rpool_data.newest_snapshot_unix == 1_745_193_600
|
||||
assert rpool_data.oldest_snapshot_unix == 1_745_107_200
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue