From 041dfc8fc0ff93e16c0be2f05825dc05ca6e10ea Mon Sep 17 00:00:00 2001 From: Carsten Date: Wed, 22 Apr 2026 17:48:45 +0200 Subject: [PATCH] test(agent): cover stripe, mixed, and special-vdev pool_type classification --- .../proxmox_agent/collectors/zfs_test.exs | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/agent/test/proxmox_agent/collectors/zfs_test.exs b/agent/test/proxmox_agent/collectors/zfs_test.exs index 0a8bbdd..122d48c 100644 --- a/agent/test/proxmox_agent/collectors/zfs_test.exs +++ b/agent/test/proxmox_agent/collectors/zfs_test.exs @@ -53,6 +53,57 @@ defmodule ProxmoxAgent.Collectors.ZfsTest do assert sample.pools == [] assert length(sample.errors) >= 1 end + + test "classifies pool_type for stripe, mixed, and special vdevs" do + list_json = + Jason.encode!(%{ + "pools" => %{ + "stripe" => %{"name" => "stripe", "size" => 1, "alloc" => 0, "free" => 1, + "frag" => 0, "cap" => 0, "health" => "ONLINE"}, + "mixed" => %{"name" => "mixed", "size" => 1, "alloc" => 0, "free" => 1, + "frag" => 0, "cap" => 0, "health" => "ONLINE"}, + "mirror_with_log" => %{"name" => "mirror_with_log", "size" => 1, "alloc" => 0, "free" => 1, + "frag" => 0, "cap" => 0, "health" => "ONLINE"} + } + }) + + vdev = fn name, type -> + {name, %{"name" => name, "vdev_type" => type, "state" => "ONLINE", + "read_errors" => "0", "write_errors" => "0", "checksum_errors" => "0"}} + end + + status_json = + Jason.encode!(%{ + "pools" => %{ + "stripe" => %{ + "name" => "stripe", "state" => "ONLINE", "error_count" => "0", + "vdevs" => Map.new([vdev.("sda", "disk"), vdev.("sdb", "disk")]) + }, + "mixed" => %{ + "name" => "mixed", "state" => "ONLINE", "error_count" => "0", + "vdevs" => Map.new([vdev.("mirror-0", "mirror"), vdev.("raidz1-1", "raidz1")]) + }, + "mirror_with_log" => %{ + "name" => "mirror_with_log", "state" => "ONLINE", "error_count" => "0", + "vdevs" => Map.new([vdev.("mirror-0", "mirror"), vdev.("log-0", "log")]) + } + } + }) + + runner = fn + "zpool", ["list" | _] -> {:ok, list_json} + "zpool", ["status" | _] -> {:ok, status_json} + end + + sample = Zfs.collect_pools(runner: runner) + by_name = Map.new(sample.pools, &{&1.name, &1}) + + assert by_name["stripe"].pool_type == "stripe" + assert by_name["mixed"].pool_type == "mixed" + assert by_name["mirror_with_log"].pool_type == "mirror" + # log vdev is retained in the per-pool vdevs list even though it's ignored for layout classification + assert Enum.any?(by_name["mirror_with_log"].vdevs, &(&1.type == "log")) + end end describe "collect_datasets/1" do