Skip to content

Commit

Permalink
More clean ups (#158)
Browse files Browse the repository at this point in the history
### What does this PR do

#### Make the dmidecode utility act like the others

dmidecode was using a method in the 3rd party library to look up the
binary.
I've changed it to act like the other utilities by supporting binary
tool override via environment variable.

#### Get rid of OemComponents struct

This old setup isn't very generic, we'd have to grow the struct for each
new manufacturer that has OEM devices.
It also doesn't seem very useful like it was.
We already know the manufacturer via Hardware.Vendor so no need to
stutter by having `Dell` in the OEM struct.

#### Move oem specific things out of model/

These belong in utils since they are util specific values.
Now there's no need to export them, so I made them private.

#### Delete UpdateReleaseEnvironments

Its not used in the code base nor any I can find by GitHub search.

### Note

These are "breaking" changes, but ironlib is <1.0 so I think its fine.
I envision more breaking changes as I work on using ironlib in vogelkop
more tightly and need a more ergonomic api.
  • Loading branch information
mmlb authored May 29, 2024
2 parents d783b1f + db22bd9 commit 2883c00
Show file tree
Hide file tree
Showing 11 changed files with 319 additions and 344 deletions.
442 changes: 219 additions & 223 deletions fixtures/dell/r6515.go

Large diffs are not rendered by default.

5 changes: 0 additions & 5 deletions model/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,6 @@ type UpdateOptions struct {
BaseURL string // The BaseURL for the updates
}

// OemComponents are OEM specific device components
type OemComponents struct {
Dell []*Component `json:"dell"`
}

type CreateVirtualDiskOptions struct {
RaidMode string
PhysicalDiskIDs []uint
Expand Down
71 changes: 0 additions & 71 deletions model/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,39 +8,6 @@ import (
// CollectorUtility is the name of a utility defined in utils/
type CollectorUtility string

const (
// Dell specific component slugs
SlugDellSystemCPLD = "Dell System CPLD"
SlugDellBossAdapter = "Boss Adapter"
SlugDellIdracServiceModule = "IDrac Service Module"
SlugDellBossAdapterDisk0 = "Boss Adapter - Disk 0"
SlugDellBossAdapterDisk1 = "Boss Adapter - Disk 1"
SlugDellLifeCycleController = "Lifecycle Controller"
SlugDellOSCollector = "OS Collector"
SlugDell64bitUefiDiagnostics = "Dell 64 bit uEFI diagnostics"
SlugDellBackplaneExpander = "Backplane-Expander"
SlugDellNonExpanderStorageBackplane = "Non-Expander Storage Backplane (SEP)"

// EnvDellDSURelease is the Dell DSU release version
//
// e.g: 21.11.12 from https://linux.dell.com/repo/hardware/DSU_21.11.12/
EnvDellDSURelease = "DELL_DSU_RELEASE"
// EnvDellDSUVersion is the Dell DSU utility package version
//
// e.g: 1.9.2.0-21.07.00 from https://linux.dell.com/repo/hardware/DSU_21.11.12/os_independent/x86_64/dell-system-update-1.9.2.0-21.07.00.x86_64.rpm
EnvDellDSUVersion = "DELL_DSU_VERSION"
// EnvDNFDisableGPGCheck disables GPG checks in DNF package installs
EnvDNFDellDisableGPGCheck = "DNF_DISABLE_GPG_CHECK"
// EnvUpdateStoreURL defines up the update store base URL prefix
EnvUpdateBaseURL = "UPDATE_BASE_URL"
)

// UpdateReleaseEnvironments is the list of update environments
// this is related to the fup tooling
func UpdateReleaseEnvironments() []string {
return []string{"production", "canary", "vanguard"}
}

var (

// ModelDriveTypeSlug is a map of drive models number to slug
Expand All @@ -59,44 +26,6 @@ var (
"HGST HUS728T8TALE6L4": common.SlugDriveTypeSATAHDD,
}

// OemComponentDell is a lookup table for dell OEM components
// these components are specific to the OEMs - in this case Dell
OemComponentDell = map[string]struct{}{
SlugDellSystemCPLD: {},
common.SlugBackplaneExpander: {},
SlugDellIdracServiceModule: {},
SlugDellBossAdapterDisk0: {},
SlugDellBossAdapterDisk1: {},
SlugDellBossAdapter: {},
SlugDellLifeCycleController: {},
SlugDellNonExpanderStorageBackplane: {},
SlugDellOSCollector: {},
SlugDell64bitUefiDiagnostics: {},
}

// DellComponentSlug is an ordered list of dell component identifiers to component slug
// To identify components correctly, if two components contain a similar string
// e.g: "idrac", "dell emc idrac service module" the latter should be positioned before the former in the list.
DellComponentSlug = [][]string{
{"bios", common.SlugBIOS},
{"ethernet", common.SlugNIC},
{"dell emc idrac service module", SlugDellIdracServiceModule},
{"idrac", common.SlugBMC},
{"backplane", common.SlugBackplaneExpander},
{"power supply", common.SlugPSU},
{"hba330", common.SlugStorageController},
{"nvmepcissd", common.SlugDrive},
{"system cpld", SlugDellSystemCPLD},
{"sep firmware", SlugDellNonExpanderStorageBackplane},
{"lifecycle controller", SlugDellLifeCycleController},
{"os collector", SlugDellOSCollector},
{"disk 0 of boss adapter", SlugDellBossAdapterDisk0},
{"disk 1 of boss adapter", SlugDellBossAdapterDisk1},
{"boss", SlugDellBossAdapter},
{"dell 64 bit uefi diagnostics", SlugDell64bitUefiDiagnostics},
{"integrated dell remote access controller", common.SlugBMC},
}

ErrTypeComponentFirmware = errors.New("ironlib.GetComponentFirmware() was passed an object type which is not handled")
)

Expand Down
2 changes: 1 addition & 1 deletion model/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ type Hardware struct {
UpdatesInstalled bool // set when updates were installed on the device
UpdatesAvailable int // -1 == no update lookup as yet, 0 == no updates available, 1 == updates available
Device *common.Device
OemComponents *OemComponents // OemComponents hold OEM specific components that may not show up in dmidecode/lshw and other collectors.
OEMComponents []*Component // OEMComponents hold OEM specific components that may not show up in dmidecode/lshw and other collectors.
}

// NewHardware returns the base Hardware struct that various providers inherit
Expand Down
22 changes: 0 additions & 22 deletions model/supermicro/supermicro.go

This file was deleted.

13 changes: 8 additions & 5 deletions providers/dell/dell.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ import (
"github.com/sirupsen/logrus"
)

// EnvUpdateStoreURL defines up the update store base URL prefix
const EnvUpdateBaseURL = "UPDATE_BASE_URL"

// The dell device provider struct
type dell struct {
DsuPrequisitesInstalled bool
Expand Down Expand Up @@ -58,19 +61,19 @@ func New(dmidecode *utils.Dmidecode, l *logrus.Logger) (actions.DeviceManager, e

// when default, the repo URL will point to the default repository
// this expects a EnvUpdateStoreURL/dell/default/ is made available
dsuReleaseVersion := os.Getenv(model.EnvDellDSURelease)
dsuReleaseVersion := os.Getenv(utils.EnvDellDSURelease)
if dsuReleaseVersion == "" {
dsuReleaseVersion = "default"
}

// when default, whichever version of DSU is available will be installed
dsuPackageVersion := os.Getenv(model.EnvDellDSUVersion)
dsuPackageVersion := os.Getenv(utils.EnvDellDSUVersion)
if dsuPackageVersion == "" {
dsuPackageVersion = "default"
}

// the base url for updates
updateBaseURL := os.Getenv(model.EnvUpdateBaseURL)
updateBaseURL := os.Getenv(EnvUpdateBaseURL)

// set device manager
trace := l.Level >= logrus.TraceLevel
Expand Down Expand Up @@ -131,7 +134,7 @@ func (d *dell) GetInventoryOEM(ctx context.Context, _ *common.Device, options *m
return err
}

d.hw.OemComponents.Dell = append(d.hw.OemComponents.Dell, oemComponents...)
d.hw.OEMComponents = append(d.hw.OEMComponents, oemComponents...)

return nil
}
Expand All @@ -156,7 +159,7 @@ func (d *dell) ListAvailableUpdates(ctx context.Context, options *model.UpdateOp

d.logger.WithField("count", count).Info("component updates identified..")

d.hw.OemComponents.Dell = append(d.hw.OemComponents.Dell, oemUpdates...)
d.hw.OEMComponents = append(d.hw.OEMComponents, oemUpdates...)

return d.hw.Device, nil
}
Expand Down
4 changes: 2 additions & 2 deletions providers/dell/dell_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func newFakeDellDevice(logger *logrus.Logger) *dell {
device.Vendor = "dell"

hardware := model.NewHardware(&device)
hardware.OemComponents = &model.OemComponents{Dell: []*model.Component{}}
hardware.OEMComponents = []*model.Component{}

return &dell{
hw: hardware,
Expand Down Expand Up @@ -96,7 +96,7 @@ func TestGetInventory(t *testing.T) {
}

assert.Equal(t, dellFixtures.R6515_inventory_lshw_smartctl, device)
assert.Equal(t, expectedOemComponents, dell.hw.OemComponents)
assert.Equal(t, expectedOemComponents, dell.hw.OEMComponents)
}

// Get inventory, not listing updates available
Expand Down
19 changes: 15 additions & 4 deletions utils/dmidecode.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package utils

import (
"cmp"
"context"
"os"
"os/exec"
"strings"

"github.com/bmc-toolbox/common"
Expand All @@ -12,24 +14,33 @@ import (
"github.com/pkg/errors"
)

const EnvDmidecodeUtility = "IRONLIB_UTIL_DMIDECODE"

type Dmidecode struct {
dmi *dmidecode.DMI
}

func NewDmidecode() (d *Dmidecode, err error) {
utility := cmp.Or(os.Getenv(EnvDmidecodeUtility), "dmidecode")

dmi := dmidecode.New()
output, err := dmi.ExecDmidecode(utility)
if err != nil {
return nil, err
}

err = dmi.Run()
err = dmi.ParseDmidecode(output)
if err != nil {
return d, err
return nil, err
}

return &Dmidecode{dmi: dmi}, err
return &Dmidecode{dmi: dmi}, nil
}

// Attributes implements the actions.UtilAttributeGetter interface
func (d *Dmidecode) Attributes() (utilName model.CollectorUtility, absolutePath string, err error) {
path, err := d.dmi.FindBin("dmidecode")
utility := cmp.Or(os.Getenv(EnvDmidecodeUtility), "dmidecode")
path, err := exec.LookPath(utility)

return "dmidecode", path, err
}
Expand Down
48 changes: 47 additions & 1 deletion utils/dsu.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"regexp"
"strings"

"github.com/bmc-toolbox/common"
"github.com/metal-toolbox/ironlib/errs"
"github.com/metal-toolbox/ironlib/model"
"github.com/pkg/errors"
Expand All @@ -25,11 +26,56 @@ const (
DSUExitCodeRebootRequired = 8
DSUExitCodeNoUpdatesAvailable = 34

// Dell specific component slugs
slugDellSystemCPLD = "Dell System CPLD"
slugDellBossAdapter = "Boss Adapter"
slugDellBossAdapterDisk0 = "Boss Adapter - Disk 0"
slugDellBossAdapterDisk1 = "Boss Adapter - Disk 1"
slugDellIdracServiceModule = "IDrac Service Module"
slugDellLifeCycleController = "Lifecycle Controller"
slugDellOSCollector = "OS Collector"
slugDell64bitUefiDiagnostics = "Dell 64 bit uEFI diagnostics"
slugDellBackplaneExpander = "Backplane-Expander"
slugDellNonExpanderStorageBackplane = "Non-Expander Storage Backplane (SEP)"

// EnvDellDSURelease is the Dell DSU release version
//
// e.g: 21.11.12 from https://linux.dell.com/repo/hardware/DSU_21.11.12/
EnvDellDSURelease = "DELL_DSU_RELEASE"

// EnvDellDSUVersion is the Dell DSU utility package version
//
// e.g: 1.9.2.0-21.07.00 from https://linux.dell.com/repo/hardware/DSU_21.11.12/os_independent/x86_64/dell-system-update-1.9.2.0-21.07.00.x86_64.rpm
EnvDellDSUVersion = "DELL_DSU_VERSION"

LocalUpdatesDirectory = "/root/dsu"

EnvDsuUtility = "IRONLIB_UTIL_DSU"
)

// DellComponentSlug is an ordered list of dell component identifiers to component slug
// To identify components correctly, if two components contain a similar string
// e.g: "idrac", "dell emc idrac service module" the latter should be positioned before the former in the list.
var dellComponentSlug = [][]string{
{"bios", common.SlugBIOS},
{"ethernet", common.SlugNIC},
{"dell emc idrac service module", slugDellIdracServiceModule},
{"idrac", common.SlugBMC},
{"backplane", common.SlugBackplaneExpander},
{"power supply", common.SlugPSU},
{"hba330", common.SlugStorageController},
{"nvmepcissd", common.SlugDrive},
{"system cpld", slugDellSystemCPLD},
{"sep firmware", slugDellNonExpanderStorageBackplane},
{"lifecycle controller", slugDellLifeCycleController},
{"os collector", slugDellOSCollector},
{"disk 0 of boss adapter", slugDellBossAdapterDisk0},
{"disk 1 of boss adapter", slugDellBossAdapterDisk1},
{"boss", slugDellBossAdapter},
{"dell 64 bit uefi diagnostics", slugDell64bitUefiDiagnostics},
{"integrated dell remote access controller", common.SlugBMC},
}

var (
ErrDsuInventoryCollectorBinMissing = errors.New("dsu inventory collector executable missing 'invcol_*_*.BIN'")
ErrMultipleDsuInventoryCollectorBins = errors.New("multiple inventory collector bins found")
Expand Down Expand Up @@ -282,7 +328,7 @@ func findDSUInventoryCollector(path string) []string {
func dsuComponentNameToSlug(n string) string {
componentName := strings.ToLower(n)

for _, componentSlug := range model.DellComponentSlug {
for _, componentSlug := range dellComponentSlug {
identifier, slug := componentSlug[0], componentSlug[1]
if strings.EqualFold(componentName, identifier) {
return slug
Expand Down
13 changes: 6 additions & 7 deletions utils/dsu_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,25 @@ import (
"testing"

"github.com/bmc-toolbox/common"
"github.com/metal-toolbox/ironlib/model"
"github.com/stretchr/testify/assert"
)

func Test_dsuComponentNameToSlug(t *testing.T) {
kv := map[string]string{
"BIOS": common.SlugBIOS,
"Power Supply": common.SlugPSU,
"Disk 0 of BOSS Adapter ": model.SlugDellBossAdapterDisk0,
"BOSS": model.SlugDellBossAdapter,
"Disk 0 of BOSS Adapter ": slugDellBossAdapterDisk0,
"BOSS": slugDellBossAdapter,
"Dell HBA330 Mini Controller 0 Firmware ": common.SlugStorageController,
"Backplane Expander FW ": model.SlugDellBackplaneExpander,
"Backplane Expander FW ": slugDellBackplaneExpander,
"Intel(R) Ethernet 10G 4P X710 SFP+ rNDC": common.SlugNIC,
"Intel(R) Ethernet 10G X710 rNDC ": common.SlugNIC,
"Intel(R) Ethernet 10G X710 rNDC": common.SlugNIC,
"iDRAC": common.SlugBMC,
"NVMePCISSD Model Number: Micron_9200_MTFDHAL3T8TCT": common.SlugDrive,
"Lifecycle Controller": model.SlugDellLifeCycleController,
"System CPLD": model.SlugDellSystemCPLD,
"Dell EMC iDRAC Service Module Embedded Package v3.5.0, A00": model.SlugDellIdracServiceModule,
"Lifecycle Controller": slugDellLifeCycleController,
"System CPLD": slugDellSystemCPLD,
"Dell EMC iDRAC Service Module Embedded Package v3.5.0, A00": slugDellIdracServiceModule,
}

for componentName, expectedSlug := range kv {
Expand Down
Loading

0 comments on commit 2883c00

Please sign in to comment.