Files
ilker f74859d138 hpcod phase 1: multi-provider discovery
First code for the HPC-on-demand portal. The portal is meant to front more
than Proxmox - OpenStack is expected next - so the provider abstraction comes
first and Proxmox is simply its first implementation. internal/model holds the
vocabulary everything above reasons in; adding a provider means writing one
package and registering it.

The layered capability detection from the design is implemented and enforced.
A PCI class code cannot identify InfiniBand: a ConnectX-4 Lx reports class
0x0200 because that variant is Ethernet-only, while a ConnectX-6 reports
0x0207 in IB mode and 0x0200 in Ethernet mode. Every capability claim
therefore records how it was made - class, curated vendor:device map, or live
agent - and Capability.Trusted refuses to schedule on a fabric until an agent
confirms the link. Unconfirmed devices are still reported, since that gap is
what an operator has to close. Passthrough viability comes from IOMMU group
membership rather than device presence: sibling functions of one card are
fine, an unrelated device in the group is not.

Verified against a live Proxmox site, where it correctly classifies the
Mellanox cards as roce rather than infiniband and withholds them from the
schedulable set, while offering the Quadro K620 that does sit alone in its
IOMMU group.

Two bugs found and fixed while running it for real:

- Query strings were appended to url.URL.Path, which is the decoded path, so
  String() escaped the "?" and /cluster/resources?type=vm silently stopped
  filtering. Guests were ignored and a node running 22 VMs reported all cores
  free. Regression test added.
- Physical cores are now the schedulable total by default rather than being
  ignored, with a per-site cpu_overcommit for hosts where oversubscription is
  acceptable. An HPC tenant given oversubscribed cores just runs slowly.

Secrets stay out of the catalogue: any setting may be written env:NAME. The
Proxmox token needs PVEAuditor only.
2026-09-01 11:53:35 +02:00

91 lines
2.8 KiB
Go

package proxmox
import (
"context"
"net/http"
"net/http/httptest"
"testing"
"time"
)
// Regression test. The client originally appended the whole path, query string
// included, to url.URL.Path. Because Path is the decoded path, String() then
// escaped the "?" and Proxmox received a request for a resource literally
// named "resources%3Ftype=vm" - the filter never applied, every guest was
// ignored, and a node with 22 running VMs reported all of its cores free.
func TestGetSeparatesQueryString(t *testing.T) {
var gotPath, gotQuery string
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
gotPath = r.URL.Path
gotQuery = r.URL.RawQuery
w.Header().Set("Content-Type", "application/json")
_, _ = w.Write([]byte(`{"data":[]}`))
}))
defer srv.Close()
c, err := newClient(srv.URL, "u@pve!t=x", true, 5*time.Second)
if err != nil {
t.Fatal(err)
}
var out []struct{}
if err := c.get(context.Background(), "/cluster/resources?type=vm", &out); err != nil {
t.Fatal(err)
}
if want := "/api2/json/cluster/resources"; gotPath != want {
t.Errorf("path = %q, want %q", gotPath, want)
}
if want := "type=vm"; gotQuery != want {
t.Errorf("query = %q, want %q - the filter must survive URL building", gotQuery, want)
}
}
func TestGetSendsTokenHeader(t *testing.T) {
var auth string
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
auth = r.Header.Get("Authorization")
_, _ = w.Write([]byte(`{"data":null}`))
}))
defer srv.Close()
c, _ := newClient(srv.URL, "hpcod@pve!discovery=uuid", true, 5*time.Second)
var out []struct{}
if err := c.get(context.Background(), "/nodes", &out); err != nil {
t.Fatal(err)
}
if want := "PVEAPIToken=hpcod@pve!discovery=uuid"; auth != want {
t.Errorf("Authorization = %q, want %q", auth, want)
}
}
// Proxmox returns numbers as strings on some endpoints and versions.
func TestFlexInt(t *testing.T) {
for _, tc := range []struct {
in string
want flexInt
}{
{`123`, 123}, {`"123"`, 123}, {`""`, 0}, {`null`, 0}, {`1.9`, 1},
} {
var f flexInt
if err := f.UnmarshalJSON([]byte(tc.in)); err != nil {
t.Fatalf("%s: %v", tc.in, err)
}
if f != tc.want {
t.Errorf("%s -> %d, want %d", tc.in, f, tc.want)
}
}
}
// A device sharing its IOMMU group with an unrelated card cannot be passed
// through; sibling functions of the same card do not disqualify it.
func TestGroupIsolation(t *testing.T) {
gpuAndItsAudio := []string{"0000:01:00.0", "0000:01:00.1"}
if !groupIsolated(gpuAndItsAudio, "0000:01:00.0") {
t.Error("a card plus its own audio function should still be passthrough-safe")
}
sharedWithNIC := []string{"0000:01:00.0", "0000:02:00.0"}
if groupIsolated(sharedWithNIC, "0000:01:00.0") {
t.Error("a group holding an unrelated device must not be offerable")
}
}