Skip to content

Commit

Permalink
revise override criteria for component namespaces
Browse files Browse the repository at this point in the history
  • Loading branch information
DoctorVin committed Mar 11, 2024
1 parent ef7e48b commit 9e07088
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
22 changes: 13 additions & 9 deletions fleetdb/methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,13 @@ func UnpackAttribute(attr *ss.Attributes, dst any) error {

// RecordToComponent takes a single incoming FleetDB component record and creates
// a rivets Component from it. An important difference from ConvertComponents (cf.
// below) is that this sets a given attribute/variable attribute preferentially
// from in-band data, using out-of-band only when there is no in-band inventory.
// We find that in-band inventory data is more complete, especially for SuperMicro.
// below) is that this sets a given attribute/versioned-attribute preferentially
// based on some domain-specific factors. For most things, we prefer in-band data,
// as we find that it is more complete, depending on the vendor. Dell is generally
// equivalent information, but SMC is far more detailed in-band. The exception is
// firmware versions, where Dell and SMC provide equivalent information in-band
// vs. not, and biasing in-band inventory would actually hide updates from firmware
// installs because the new versions are discovered via the BMC.
//
//nolint:gocyclo,gocritic
func RecordToComponent(rec *ss.ServerComponent) (*rt.Component, error) {
Expand All @@ -55,19 +59,19 @@ func RecordToComponent(rec *ss.ServerComponent) (*rt.Component, error) {
// versioned attributes from FleetDB.
switch va.Namespace {
case FirmwareVersionInbandNS:
fwva := &FirmwareVersionedAttribute{}
if err := UnpackVersionedAttribute(&va, fwva); err != nil {
return nil, err
}
component.Firmware = fwva.Firmware
case FirmwareVersionOutofbandNS:
if component.Firmware == nil {
fwva := &FirmwareVersionedAttribute{}
if err := UnpackVersionedAttribute(&va, fwva); err != nil {
return nil, err
}
component.Firmware = fwva.Firmware
}
case FirmwareVersionOutofbandNS:
fwva := &FirmwareVersionedAttribute{}
if err := UnpackVersionedAttribute(&va, fwva); err != nil {
return nil, err
}
component.Firmware = fwva.Firmware
case StatusInbandNS:
st := &StatusVersionedAttribute{}
if err := UnpackVersionedAttribute(&va, st); err != nil {
Expand Down
10 changes: 5 additions & 5 deletions fleetdb/methods_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func TestRecordToComponent(t *testing.T) {
require.NotNil(t, got.Attributes)
require.Equal(t, "my-id", got.Attributes.ID)
})
t.Run("out-of-band populates empty fields", func(t *testing.T) {
t.Run("populate empty fields", func(t *testing.T) {
t.Parallel()
record := &ss.ServerComponent{
UUID: uuid.New(),
Expand All @@ -169,7 +169,7 @@ func TestRecordToComponent(t *testing.T) {
Attributes: []ss.Attributes{},
VersionedAttributes: []ss.VersionedAttributes{
{
Namespace: FirmwareVersionOutofbandNS,
Namespace: FirmwareVersionInbandNS,
Data: json.RawMessage(`{"firmware": {"installed": "1.2.3"}}`),
},
{
Expand All @@ -189,7 +189,7 @@ func TestRecordToComponent(t *testing.T) {
require.Equal(t, "1.2.3", got.Firmware.Installed)
require.Equal(t, "ok", got.Status.State)
})
t.Run("in-band trumps out-of-band", func(t *testing.T) {
t.Run("specific overrides", func(t *testing.T) {
t.Parallel()
record := &ss.ServerComponent{
UUID: uuid.New(),
Expand Down Expand Up @@ -226,8 +226,8 @@ func TestRecordToComponent(t *testing.T) {

got, err := RecordToComponent(record)
require.NoError(t, err)
require.Equal(t, "1.2.3-45", got.Firmware.Installed)
require.Equal(t, "ok, but could be better", got.Status.State)
require.Equal(t, "1.2.3", got.Firmware.Installed, "firmware version does not favor out-of-band")
require.Equal(t, "ok, but could be better", got.Status.State, "status does not favor in-band")
})
t.Run("malformed variable attribute returns an error", func(t *testing.T) {
t.Parallel()
Expand Down

0 comments on commit 9e07088

Please sign in to comment.