Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions config/components/inventory/crds/fleet.datumapis.com.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,10 @@ spec:
serialNumber: {type: string, maxLength: 253}
sku: {type: string, maxLength: 253}
powerState: {type: string, maxLength: 63}
resetTypes:
type: array
maxItems: 16
items: {type: string, minLength: 1, maxLength: 63}
networkInterfaces:
type: array
maxItems: 32
Expand Down
22 changes: 17 additions & 5 deletions docs/operations/bmc-discovery.md
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ status:
serialNumber: SYNTHETIC-0001
sku: TAG0001
powerState: "On"
resetTypes: ["On", ForceOff, ForceRestart]
networkInterfaces:
- {id: NIC.1, macAddress: "00:00:5e:00:53:01", linkStatus: LinkUp, speedMbps: 25000}
conditions: [...]
Expand Down Expand Up @@ -325,11 +326,22 @@ is `StaleObservation`.
## What is read

Service root, then every Manager and every ComputerSystem (up to 16 of each),
with each one's EthernetInterfaces (up to 32). Collections follow
`Members@odata.nextLink` for up to 8 pages. Every member must sit under its
collection. Documents are decoded leniently: only the named properties are
read, so an off-schema vendor property elsewhere in a document does not fail
the read.
with each one's EthernetInterfaces (up to 32). For each System it records
the `ComputerSystem.Reset` types the BMC advertises, inline or from the
System's own ActionInfo, as `resetTypes`. It reads the action's description
and never invokes it. It keeps at most 16 distinct values. Malformed actions,
a reset target off the System, an ActionInfo off the System or under its
Actions, or an ActionInfo that cannot be read (missing, malformed, a server
error or a timeout) records none and keeps the rest of the inventory. A
rejected credential (401 or 403), a pin mismatch or an unexpected resource
path on the ActionInfo fails the read. Nothing reads `resetTypes` yet: it is
recorded for planned Device power operations, which will refuse an action the
server does not offer.

Collections follow `Members@odata.nextLink` for up to 8 pages. Every member
must sit under its collection. Documents are decoded leniently: only the
named properties are read, so an off-schema vendor property elsewhere in a
document does not fail the read.

Not read: `Chassis`, `NetworkAdapters` and their ports, firmware inventory,
sessions. Basic authentication is used; no Redfish session is created.
Expand Down
4 changes: 3 additions & 1 deletion internal/api/inventory/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,8 @@ type ObservedManager struct {
}

// ObservedSystem is one Redfish ComputerSystem. PowerState is an observation
// only; discovery never changes power.
// only; discovery never changes power. ResetTypes are the ComputerSystem.Reset
// types the BMC advertises for the System, read but never invoked.
type ObservedSystem struct {
ID string `json:"id"`
UUID string `json:"uuid,omitempty"`
Expand All @@ -266,6 +267,7 @@ type ObservedSystem struct {
SKU string `json:"sku,omitempty"`
PowerState string `json:"powerState,omitempty"`
NetworkInterfaces []ObservedNetworkInterface `json:"networkInterfaces,omitempty"`
ResetTypes []string `json:"resetTypes,omitempty"`
}

// ObservedNetworkInterface is one Redfish EthernetInterface.
Expand Down
10 changes: 9 additions & 1 deletion internal/bmcdiscovery/discovery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"fmt"
"net/http"
"net/http/httptest"
"slices"
"strings"
"sync"
"sync/atomic"
Expand Down Expand Up @@ -587,7 +588,9 @@ func TestEndToEndOverTLS(t *testing.T) {
"/redfish/v1/Managers": `{"Members":[{"@odata.id":"/redfish/v1/Managers/BMC"}]}`,
"/redfish/v1/Managers/BMC": `{"Id":"BMC","Model":"Example BMC","FirmwareVersion":"1.2.3"}`,
"/redfish/v1/Systems": `{"Members":[{"@odata.id":"/redfish/v1/Systems/1"}]}`,
"/redfish/v1/Systems/1": `{"Id":"1","UUID":"00000000-0000-4000-8000-000000000001","Model":"Example 1U","SerialNumber":"SYNTHETIC-0001","PowerState":"Off"}`,
"/redfish/v1/Systems/1": `{"Id":"1","UUID":"00000000-0000-4000-8000-000000000001","Model":"Example 1U","SerialNumber":"SYNTHETIC-0001","PowerState":"Off",
"Actions":{"#ComputerSystem.Reset":{"target":"/redfish/v1/Systems/1/Actions/ComputerSystem.Reset","@Redfish.ActionInfo":"/redfish/v1/Systems/1/ResetActionInfo"}}}`,
"/redfish/v1/Systems/1/ResetActionInfo": `{"Parameters":[{"Name":"ResetType","Required":"true","DataType":"String","AllowableValues":["On","ForceOff","ForceRestart"]}]}`,
}
server := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
user, pass, authed := r.BasicAuth()
Expand Down Expand Up @@ -640,6 +643,11 @@ func TestEndToEndOverTLS(t *testing.T) {
if c := condition(t, got.Status, inventory.ConditionIdentityMatched); c.Status != metav1.ConditionTrue {
t.Fatalf("IdentityMatched = %+v", c)
}
// Offered reset types come from the ActionInfo, read with a GET; the
// action itself is never invoked.
if types := got.Status.Discovery.Inventory.Systems[0].ResetTypes; !slices.Equal(types, []string{"On", "ForceOff", "ForceRestart"}) {
t.Fatalf("resetTypes = %v", types)
}
mu.Lock()
defer mu.Unlock()
for _, l := range log {
Expand Down
16 changes: 15 additions & 1 deletion internal/bmcdiscovery/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"errors"
"fmt"
"slices"
"sort"
"strings"
"time"
Expand Down Expand Up @@ -217,7 +218,20 @@ func observedInventory(inv redfish.Inventory, at metav1.Time, endpoint string) *
for _, s := range inv.Systems {
if s.ID != "" && len(out.Systems) < 16 {
out.Systems = append(out.Systems, inventory.ObservedSystem{ID: clip(s.ID, 253), UUID: canonicalUUIDOrEmpty(s.UUID), Manufacturer: clip(s.Manufacturer, 253),
Model: clip(s.Model, 253), SerialNumber: clip(s.SerialNumber, 253), SKU: clip(s.SKU, 253), PowerState: clip(s.PowerState, 63), NetworkInterfaces: nics(s.NetworkInterfaces)})
Model: clip(s.Model, 253), SerialNumber: clip(s.SerialNumber, 253), SKU: clip(s.SKU, 253), PowerState: clip(s.PowerState, 63), NetworkInterfaces: nics(s.NetworkInterfaces),
ResetTypes: resetTypes(s.ResetTypes)})
}
}
return out
}

// resetTypes keeps up to 16 distinct, nonempty advertised reset types.
func resetTypes(in []string) []string {
var out []string
for _, v := range in {
v = clip(v, 63)
if v != "" && !slices.Contains(out, v) && len(out) < 16 {
out = append(out, v)
}
}
return out
Expand Down
21 changes: 21 additions & 0 deletions internal/bmcdiscovery/status_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package bmcdiscovery

import (
"fmt"
"slices"
"strings"
"testing"
)

// Recorded reset types stay within the Device schema: at most 16 distinct,
// nonempty values of at most 63 characters each.
func TestResetTypesStayWithinTheSchema(t *testing.T) {
in := []string{"On", " On ", "", " ", strings.Repeat("x", 80)}
for i := range 20 {
in = append(in, fmt.Sprintf("Vendor%d", i))
}
got := resetTypes(in)
if len(got) != 16 || !slices.Equal(got[:2], []string{"On", strings.Repeat("x", 63)}) || got[15] != "Vendor13" {
t.Fatalf("resetTypes = %v", got)
}
}
36 changes: 2 additions & 34 deletions internal/redfish/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,40 +365,8 @@ func (c *Client) Identify(ctx context.Context, t Target) (System, error) {
if err := json.Unmarshal(s.RawData, &raw); err != nil {
return System{}, classify(err)
}
reset := raw.Actions.Reset
target, err := cleanPath(reset.Target)
if err != nil || !strings.HasPrefix(target, sys.Path+"/") {
return System{}, fmt.Errorf("%w: ComputerSystem.Reset target not on the enrolled System", ErrUnsupported)
}
sys.ResetTarget = target
sys.ResetTypes = reset.Allowed
if len(sys.ResetTypes) == 0 && reset.Info != "" {
info, err := cleanPath(reset.Info)
if err != nil || !strings.HasPrefix(info, sys.Path+"/") {
return System{}, fmt.Errorf("%w: ActionInfo not on the enrolled System", ErrUnsupported)
}
// Not schemas.ActionInfo: its typed decode rejects the whole document
// for one off-schema property, as the DMTF emulator's string
// "Required": "true". Only the ResetType values are read.
resp, err := api.Get(info)
var ai struct {
Parameters []struct {
Name, DataType string
AllowableValues []string
}
}
if err == nil {
err = json.NewDecoder(resp.Body).Decode(&ai)
}
schemas.DeferredCleanupHTTPResponse(resp)
if err != nil {
return System{}, classify(err)
}
for _, p := range ai.Parameters {
if p.Name == "ResetType" && (p.DataType == "" || p.DataType == "String") {
sys.ResetTypes = p.AllowableValues
}
}
if sys.ResetTarget, sys.ResetTypes, err = resetTypes(api, sys.Path, raw); err != nil {
return System{}, err
}
for _, b := range s.Boot.AllowableBootSourceOverrideTargetValues {
sys.BootTargets = append(sys.BootTargets, string(b))
Expand Down
26 changes: 23 additions & 3 deletions internal/redfish/inventory.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ type InventorySystem struct {
PowerState string
// NetworkInterfaces are the System's EthernetInterfaces.
NetworkInterfaces []NetworkInterface
// ResetTypes are the ComputerSystem.Reset types the System advertises.
// Discovery reads them and never invokes the action.
ResetTypes []string
}

// NetworkInterface is one Redfish EthernetInterface.
Expand All @@ -59,7 +62,8 @@ type NetworkInterface struct {
// action, so it cannot change power, boot or any setting. Documents are
// decoded leniently: only the named properties are read, and a vendor
// property with an off-schema type elsewhere in a document is ignored. Any
// failed read fails the whole observation; nothing partial is returned.
// failed read fails the whole observation; nothing partial is returned. The
// optional reset types are the exception: see below.
func (c *Client) Inventory(ctx context.Context) (Inventory, error) {
api, err := c.connect(ctx)
if err != nil {
Expand Down Expand Up @@ -109,6 +113,9 @@ func (c *Client) Inventory(ctx context.Context) (Inventory, error) {
SKU string
PowerState string
EthernetInterfaces link
// Decoded on its own below, so an off-schema action
// annotation cannot fail the rest of the System.
Actions json.RawMessage
}
if err := getJSON(api, p, &doc); err != nil {
return Inventory{}, err
Expand All @@ -117,8 +124,21 @@ func (c *Client) Inventory(ctx context.Context) (Inventory, error) {
if err != nil {
return Inventory{}, err
}
inv.Systems = append(inv.Systems, InventorySystem{ID: doc.ID, UUID: canonicalUUID(doc.UUID), Manufacturer: doc.Manufacturer,
Model: doc.Model, SerialNumber: doc.SerialNumber, SKU: doc.SKU, PowerState: doc.PowerState, NetworkInterfaces: nics})
system := InventorySystem{ID: doc.ID, UUID: canonicalUUID(doc.UUID), Manufacturer: doc.Manufacturer,
Model: doc.Model, SerialNumber: doc.SerialNumber, SKU: doc.SKU, PowerState: doc.PowerState, NetworkInterfaces: nics}
// Reset types are optional. Malformed actions, a reset target or
// ActionInfo off the System, or an ActionInfo that cannot be read
// records none and keeps the rest of the inventory. Only a
// rejected credential, pin or identity fails the read.
var raw resetAction
if json.Unmarshal(doc.Actions, &raw.Actions) == nil && raw.Actions.Reset.Target != "" {
if _, types, err := resetTypes(api, p, raw); err == nil {
system.ResetTypes = types
} else if errors.Is(err, ErrUnauthorized) || errors.Is(err, ErrPinMismatch) || errors.Is(err, ErrIdentity) {
return Inventory{}, err
}
}
inv.Systems = append(inv.Systems, system)
}
}
return inv, nil
Expand Down
45 changes: 45 additions & 0 deletions internal/redfish/reset.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package redfish

import (
"fmt"
"strings"

"github.com/stmcginnis/gofish"
)

// resetTypes returns the ComputerSystem.Reset types a System advertises,
// inline or through its ActionInfo, and the action target. Both must belong to
// the System at sysPath, and the ActionInfo must not sit under its Actions. It
// issues at most one GET, of the ActionInfo, and never invokes the action.
func resetTypes(api *gofish.APIClient, sysPath string, raw resetAction) (target string, types []string, err error) {
reset := raw.Actions.Reset
target, err = cleanPath(reset.Target)
if err != nil || !strings.HasPrefix(target, sysPath+"/") {
return "", nil, fmt.Errorf("%w: ComputerSystem.Reset target not on the System", ErrUnsupported)
}
if len(reset.Allowed) != 0 || reset.Info == "" {
return target, reset.Allowed, nil
}
info, err := cleanPath(reset.Info)
if err != nil || !strings.HasPrefix(info, sysPath+"/") || strings.Contains(info+"/", "/Actions/") {
return "", nil, fmt.Errorf("%w: ActionInfo not on the System", ErrUnsupported)
}
// Not schemas.ActionInfo: its typed decode rejects the whole document
// for one off-schema property, as the DMTF emulator's string
// "Required": "true". Only the ResetType values are read.
var ai struct {
Parameters []struct {
Name, DataType string
AllowableValues []string
}
}
if err := getJSON(api, info, &ai); err != nil {
return "", nil, err
}
for _, p := range ai.Parameters {
if p.Name == "ResetType" && (p.DataType == "" || p.DataType == "String") {
types = p.AllowableValues
}
}
return target, types, nil
}
Loading
Loading