## Contexte Implémentation des tickets #82, #83, #84, #85 — télémétrie inventaire matériel agent. L'objectif est de fournir au central un maximum d'informations sur les machines des agents (CPU, mémoire, disques, GPU, OS, réseau, conteneur) sans SSH. ## Changements ### Nouveaux collecteurs (src/Heimdall.Agent/Services/) - **CpuInfoProvider** : parse `/proc/cpuinfo` (vendor, modèle, cœurs physiques/logiques, fréquence, flags AVX/AVX2/FMA/AVX512, cache), topologie, détection cgroup CPU (`/sys/fs/cgroup/cpu.max` v2) - **DiskInventoryProvider** : énumère les montages (`/proc/mounts`), capacité/libre/type SSD/HDD via `/sys/block/*/queue/rotation` - **GpuInventoryProvider** : nvidia-smi, sysfs DRM, vainfo, rocm-smi avec fallback silencieux, multi-GPU - **HostInfoProvider** : os-release, uname, `/proc/uptime` (uptime machine ≠ process), températures sysfs - **ContainerInfoProvider** : détection Docker (/.dockerenv, cgroup), ID conteneur, limites CPU/mémoire ### Refonte SystemMetricsProvider - Séparation host vs process (RAM machine ≠ RAM conteneur ≠ WorkingSet64) - Uptime machine (`/proc/uptime`) distinct de l'uptime process - Mémoire swap ### Entité Agent + Migration - Champs structurés CPU/mémoire/disque/GPU/OS/réseau (tous nullable, rétrocompatible) - Migration EF `AddAgentTelemetryInventory` ### Transport heartbeat - Inventaire au register + refresh périodique (5 min, pas à chaque tick) - Champs JSON pour listes (disques, GPU, interfaces réseau, températures) ### UI Admin (AgentDetail.razor) - Sections CPU, Mémoire/Disques, GPU, Machine/Conteneur avec barres de progression et badges ### Tests - 40+ tests unitaires : providers, handlers, entité Agent - Total : 999 tests verts (Domain 149, Application 397, Agent 210, Web 243) ## Tickets liés - Fixes #82 — CPU inventory - Fixes #83 — Mémoire & disque - Fixes #84 — GPU inventory - Fixes #85 — OS, conteneur, réseau ## Résultats des tests - `dotnet build` : 0 erreur, 0 warning - Domain.Tests : 149 passed - Application.Tests : 397 passed - Agent.Tests : 210 passed - Web.Tests : 243 passed - Total : 999 tests ✅ ## Checklist - [x] `dotnet build` vert (TreatWarningsAsErrors) - [x] Tests unitaires verts - [x] Migration EF créée - [x] Champs nullable (rétrocompatible) - [x] Pas de référence Infrastructure dans les contrôleurs - [x] Collecteurs avec fallback silencieux (pas de crash sans GPU/Docker/sysfs) Reviewed-on: https://forgejo.tordais.cc/nonobis/Heimdall/pulls/137
124 lines
3.5 KiB
C#
124 lines
3.5 KiB
C#
using Heimdall.Agent.Services;
|
|
|
|
namespace Heimdall.Agent.Tests.Services;
|
|
|
|
public class ContainerInfoProviderDetailedTests
|
|
{
|
|
[Fact]
|
|
public void Collect_ShouldReturnContainerInfo()
|
|
{
|
|
var provider = new ContainerInfoProvider();
|
|
var result = provider.Collect();
|
|
|
|
result.ShouldNotBeNull();
|
|
}
|
|
|
|
[Fact]
|
|
public void Collect_ShouldNotThrow()
|
|
{
|
|
var provider = new ContainerInfoProvider();
|
|
var act = () => provider.Collect();
|
|
act.ShouldNotThrow();
|
|
}
|
|
|
|
[Fact]
|
|
public void Collect_IsContainer_ShouldBeConsistentWithDockerEnv()
|
|
{
|
|
var provider = new ContainerInfoProvider();
|
|
var result = provider.Collect();
|
|
|
|
var actuallyInContainer = File.Exists("/.dockerenv") || File.Exists("/run/.containerenv");
|
|
result.IsContainer.ShouldBe(actuallyInContainer);
|
|
}
|
|
|
|
[Fact]
|
|
public void Collect_ContainerId_ShouldBeNullOrHex_WhenContainer()
|
|
{
|
|
var provider = new ContainerInfoProvider();
|
|
var result = provider.Collect();
|
|
|
|
if (result.IsContainer && result.ContainerId is not null)
|
|
{
|
|
result.ContainerId.Length.ShouldBeGreaterThanOrEqualTo(12);
|
|
result.ContainerId.All(c => "0123456789abcdef".Contains(c)).ShouldBeTrue();
|
|
}
|
|
}
|
|
|
|
[Fact]
|
|
public void Collect_MemoryLimitBytes_ShouldBeNullOrPositive()
|
|
{
|
|
var provider = new ContainerInfoProvider();
|
|
var result = provider.Collect();
|
|
|
|
if (result.MemoryLimitBytes.HasValue)
|
|
{
|
|
result.MemoryLimitBytes.Value.ShouldBeGreaterThan(0);
|
|
}
|
|
}
|
|
|
|
[Fact]
|
|
public void Collect_CpuLimit_ShouldBeNullOrPositive()
|
|
{
|
|
var provider = new ContainerInfoProvider();
|
|
var result = provider.Collect();
|
|
|
|
if (result.CpuLimit.HasValue)
|
|
{
|
|
result.CpuLimit.Value.ShouldBeGreaterThan(0);
|
|
}
|
|
}
|
|
|
|
[Fact]
|
|
public void Collect_CalledTwice_ShouldReturnConsistentResults()
|
|
{
|
|
var provider = new ContainerInfoProvider();
|
|
var first = provider.Collect();
|
|
var second = provider.Collect();
|
|
|
|
first.IsContainer.ShouldBe(second.IsContainer);
|
|
first.ContainerId.ShouldBe(second.ContainerId);
|
|
}
|
|
|
|
// ── ContainerInfo record tests ──────────────────────────────────
|
|
|
|
[Fact]
|
|
public void ContainerInfo_DefaultValues_ShouldBeCorrect()
|
|
{
|
|
var info = new ContainerInfo();
|
|
|
|
info.IsContainer.ShouldBeFalse();
|
|
info.ContainerId.ShouldBeNull();
|
|
info.ContainerImage.ShouldBeNull();
|
|
info.MemoryLimitBytes.ShouldBeNull();
|
|
info.CpuLimit.ShouldBeNull();
|
|
}
|
|
|
|
[Fact]
|
|
public void ContainerInfo_WithValues_ShouldStoreCorrectly()
|
|
{
|
|
var info = new ContainerInfo
|
|
{
|
|
IsContainer = true,
|
|
ContainerId = "abc123def456",
|
|
ContainerImage = "heimdall/agent:latest",
|
|
MemoryLimitBytes = 4_294_967_296,
|
|
CpuLimit = 200
|
|
};
|
|
|
|
info.IsContainer.ShouldBeTrue();
|
|
info.ContainerId.ShouldBe("abc123def456");
|
|
info.ContainerImage.ShouldBe("heimdall/agent:latest");
|
|
info.MemoryLimitBytes.ShouldBe(4_294_967_296);
|
|
info.CpuLimit.ShouldBe(200);
|
|
}
|
|
|
|
[Fact]
|
|
public void ContainerInfo_RecordEquality_ShouldWork()
|
|
{
|
|
var info1 = new ContainerInfo { IsContainer = true, ContainerId = "abc" };
|
|
var info2 = new ContainerInfo { IsContainer = true, ContainerId = "abc" };
|
|
|
|
info1.ShouldBe(info2);
|
|
}
|
|
}
|