- Refactored enrichContainerMetadata to not return early when container is stopped - Status API calls are still skipped for stopped containers (as expected) - Config fetch now runs regardless of status, enabling OCI detection - Added test for OCI detection on stopped containers Discovered: Proxmox 9.1 requires VM.Config.Options permission to read OCI container configs (not just VM.Audit). Document this in setup guides.
65 lines
1.6 KiB
Go
65 lines
1.6 KiB
Go
package monitoring
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/rcourtman/pulse-go-rewrite/internal/models"
|
|
"github.com/rcourtman/pulse-go-rewrite/pkg/proxmox"
|
|
)
|
|
|
|
type stubPVEClientContainerMetadata struct {
|
|
stubPVEClient
|
|
|
|
config map[string]interface{}
|
|
|
|
configCalls int
|
|
statusCalls int
|
|
}
|
|
|
|
func (s *stubPVEClientContainerMetadata) GetContainerConfig(ctx context.Context, node string, vmid int) (map[string]interface{}, error) {
|
|
s.configCalls++
|
|
return s.config, nil
|
|
}
|
|
|
|
func (s *stubPVEClientContainerMetadata) GetContainerStatus(ctx context.Context, node string, vmid int) (*proxmox.Container, error) {
|
|
s.statusCalls++
|
|
return nil, nil
|
|
}
|
|
|
|
func TestEnrichContainerMetadata_DetectsOCIForStoppedContainer(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
monitor := &Monitor{}
|
|
client := &stubPVEClientContainerMetadata{
|
|
config: map[string]interface{}{
|
|
"entrypoint": "/bin/sh",
|
|
"ostype": "unmanaged",
|
|
"cmode": "console",
|
|
"lxc": "lxc.signal.halt: SIGTERM",
|
|
},
|
|
}
|
|
|
|
container := &models.Container{
|
|
VMID: 300,
|
|
Name: "oci-alpine",
|
|
Status: "stopped",
|
|
Type: "lxc",
|
|
}
|
|
|
|
monitor.enrichContainerMetadata(context.Background(), client, "delly", "delly", container)
|
|
|
|
if client.configCalls != 1 {
|
|
t.Fatalf("expected 1 config call, got %d", client.configCalls)
|
|
}
|
|
if client.statusCalls != 0 {
|
|
t.Fatalf("expected 0 status calls for stopped container, got %d", client.statusCalls)
|
|
}
|
|
if !container.IsOCI {
|
|
t.Fatalf("expected container.IsOCI true, got false")
|
|
}
|
|
if container.Type != "oci" {
|
|
t.Fatalf("expected container.Type oci, got %q", container.Type)
|
|
}
|
|
}
|
|
|