diff --git a/.golangci.yml b/.golangci.yml index bbc5aafa..8276cd44 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -44,8 +44,6 @@ linters-settings: - wrapperFunc gofumpt: extra-rules: true - wsl: - auto-fix: true linters: enable: @@ -72,7 +70,6 @@ linters: - noctx - stylecheck - whitespace - - wsl enable-all: false disable-all: true diff --git a/actions/inventory.go b/actions/inventory.go index a140410c..d06c56c2 100644 --- a/actions/inventory.go +++ b/actions/inventory.go @@ -10,6 +10,7 @@ import ( "github.com/bmc-toolbox/common" "github.com/pkg/errors" "github.com/r3labs/diff/v2" + "github.com/sirupsen/logrus" "golang.org/x/exp/slices" "github.com/metal-toolbox/ironlib/firmware" @@ -27,6 +28,9 @@ type InventoryCollectorAction struct { // collectors registered for inventory collection. collectors Collectors + // something to track our execution + log *logrus.Logger + // device is the model in which the collected inventory is recorded. device *common.Device @@ -127,8 +131,10 @@ func WithDisabledCollectorUtilities(utilityNames []model.CollectorUtility) Optio } // NewActionrunner returns an Actions runner that is capable of collecting inventory. -func NewInventoryCollectorAction(options ...Option) *InventoryCollectorAction { - a := &InventoryCollectorAction{} +func NewInventoryCollectorAction(ll *logrus.Logger, options ...Option) *InventoryCollectorAction { + a := &InventoryCollectorAction{ + log: ll, + } // set options to override for _, opt := range options { @@ -198,55 +204,73 @@ func (a *InventoryCollectorAction) Collect(ctx context.Context, device *common.D // one drive/nic/storagecontroller/psu component returns an error. // Collect initial device inventory + a.log.Debug("collect initial inventory") err := a.collectors.InventoryCollector.Collect(ctx, a.device) + a.log.WithError(err).Debug("collect initial done") if err != nil && a.failOnError { return errors.Wrap(err, "error retrieving device inventory") } // Collect drive smart data + a.log.Debug("collect drives") err = a.CollectDrives(ctx) + a.log.WithError(err).Debug("collect drives done") if err != nil && a.failOnError { return errors.Wrap(err, "error retrieving drive inventory") } // Collect NIC info + a.log.Debug("collect nics") err = a.CollectNICs(ctx) + a.log.WithError(err).Debug("collect nics done") if err != nil && a.failOnError { return errors.Wrap(err, "error retrieving NIC inventory") } // Collect BIOS info + a.log.Debug("collect bios") err = a.CollectBIOS(ctx) + a.log.WithError(err).Debug("collect bios done") if err != nil && a.failOnError { return errors.Wrap(err, "error retrieving BIOS inventory") } // Collect CPLD info + a.log.Debug("collect cpld") err = a.CollectCPLDs(ctx) + a.log.WithError(err).Debug("collect cpld done") if err != nil && a.failOnError { return errors.Wrap(err, "error retrieving CPLD inventory") } // Collect BMC info + a.log.Debug("collect bmc") err = a.CollectBMC(ctx) + a.log.WithError(err).Debug("collect bmc done") if err != nil && a.failOnError { return errors.Wrap(err, "error retrieving BMC inventory") } // Collect TPM info + a.log.Debug("collect tpm") err = a.CollectTPMs(ctx) + a.log.WithError(err).Debug("collect tpm done") if err != nil && a.failOnError { return errors.Wrap(err, "error retrieving TPM inventory") } // Collect Firmware checksums + a.log.Debug("collect firmware checksum") err = a.CollectFirmwareChecksums(ctx) + a.log.WithError(err).Debug("collect firmware checksum done") if err != nil && a.failOnError { return errors.Wrap(err, "error retrieving Firmware checksums") } // Collect UEFI variables + a.log.Debug("collect uefi variables") err = a.CollectUEFIVariables(ctx) + a.log.WithError(err).Debug("collect uefi variables done") if err != nil && a.failOnError { return errors.Wrap(err, "error retrieving UEFI variables") } @@ -261,7 +285,9 @@ func (a *InventoryCollectorAction) Collect(ctx context.Context, device *common.D } // Collect StorageController info + a.log.Debug("collect storage controller") err = a.CollectStorageControllers(ctx) + a.log.WithError(err).Debug("collect storage controller done") if err != nil && a.failOnError { return errors.Wrap(err, "error retrieving StorageController inventory") } @@ -275,7 +301,9 @@ func (a *InventoryCollectorAction) Collect(ctx context.Context, device *common.D } if len(a.collectors.DriveCollectors) > 0 { + a.log.Debug("dynamic collect drive") err = a.CollectDrives(ctx) + a.log.WithError(err).Debug("dynamic collect drive done") if err != nil && a.failOnError { return errors.Wrap(err, "error retrieving drive inventory") @@ -284,10 +312,12 @@ func (a *InventoryCollectorAction) Collect(ctx context.Context, device *common.D } // CollectDriveCapabilities is to be invoked after Drives() + a.log.Debug("collect drive capabilities") err = a.CollectDriveCapabilities(ctx) if err != nil && a.failOnError { return errors.Wrap(err, "error retrieving DriveCapabilities") } + a.log.WithError(err).Debug("collect drive capabilities done") a.setDefaultAttributes() @@ -687,6 +717,7 @@ func (a *InventoryCollectorAction) CollectFirmwareChecksums(ctx context.Context) }() if a.collectors.FirmwareChecksumCollector == nil { + a.log.Info("nil firmware checksum collector") return nil } @@ -695,16 +726,19 @@ func (a *InventoryCollectorAction) CollectFirmwareChecksums(ctx context.Context) if slices.Contains(a.disabledCollectorUtilities, collectorKind) || slices.Contains(a.disabledCollectorUtilities, firmware.FirmwareDumpUtility) || slices.Contains(a.disabledCollectorUtilities, firmware.UEFIParserUtility) { + a.log.Info("firmware checksum disabled") return nil } sumStr, err := a.collectors.FirmwareChecksumCollector.BIOSLogoChecksum(ctx) if err != nil { + a.log.WithError(err).Warn("error collecting BIOS Logo checksum") return err } if a.device.BIOS == nil { // XXX: how did we get here? + a.log.Error("nil device bios data") return nil } diff --git a/actions/inventory_test.go b/actions/inventory_test.go index 6dd4fffd..fa6d1738 100644 --- a/actions/inventory_test.go +++ b/actions/inventory_test.go @@ -11,6 +11,7 @@ import ( smcFixtures "github.com/metal-toolbox/ironlib/fixtures/supermicro" "github.com/metal-toolbox/ironlib/model" "github.com/metal-toolbox/ironlib/utils" + "github.com/sirupsen/logrus" "github.com/stretchr/testify/assert" ) @@ -46,7 +47,7 @@ func Test_Inventory_dell(t *testing.T) { WithDisabledCollectorUtilities([]model.CollectorUtility{"dmidecode"}), } - collector := NewInventoryCollectorAction(options...) + collector := NewInventoryCollectorAction(logrus.New(), options...) if err := collector.Collect(context.TODO(), &device); err != nil { t.Error(err) } @@ -123,7 +124,7 @@ func Test_Inventory_smc(t *testing.T) { StorageControllerCollectors: []StorageControllerCollector{storecli}, } - collector := NewInventoryCollectorAction(WithCollectors(collectors), WithTraceLevel()) + collector := NewInventoryCollectorAction(logrus.New(), WithCollectors(collectors), WithTraceLevel()) if err := collector.Collect(context.TODO(), &device); err != nil { t.Error(err) } @@ -186,7 +187,7 @@ func TestNewInventoryCollectorAction(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - got := NewInventoryCollectorAction(tt.options...) + got := NewInventoryCollectorAction(logrus.New(), tt.options...) switch tt.name { case "trace-enabled": diff --git a/examples/inventory/inventory.go b/examples/inventory/inventory.go index 105f6c78..9630b48b 100644 --- a/examples/inventory/inventory.go +++ b/examples/inventory/inventory.go @@ -14,6 +14,8 @@ import ( func main() { logger := logrus.New() + logger.Formatter = new(logrus.JSONFormatter) + logger.SetLevel(logrus.TraceLevel) device, err := ironlib.New(logger) if err != nil { logger.Fatal(err) diff --git a/providers/asrockrack/asrockrack.go b/providers/asrockrack/asrockrack.go index 5c7718f1..e3049923 100644 --- a/providers/asrockrack/asrockrack.go +++ b/providers/asrockrack/asrockrack.go @@ -57,7 +57,7 @@ func (a *asrockrack) GetInventory(ctx context.Context, options ...actions.Option deviceObj := common.NewDevice() a.hw.Device = &deviceObj - collector := actions.NewInventoryCollectorAction(options...) + collector := actions.NewInventoryCollectorAction(a.logger, options...) if err := collector.Collect(ctx, a.hw.Device); err != nil { return nil, err } diff --git a/providers/dell/dell.go b/providers/dell/dell.go index 2fd58fb4..7bafcb59 100644 --- a/providers/dell/dell.go +++ b/providers/dell/dell.go @@ -116,7 +116,7 @@ func (d *dell) GetInventory(ctx context.Context, options ...actions.Option) (*co // Collect device inventory d.logger.Info("Collecting hardware inventory") - collector := actions.NewInventoryCollectorAction(options...) + collector := actions.NewInventoryCollectorAction(d.logger, options...) if err := collector.Collect(ctx, d.hw.Device); err != nil { return nil, err } diff --git a/providers/generic/generic.go b/providers/generic/generic.go index c7cbb53a..f9b73f87 100644 --- a/providers/generic/generic.go +++ b/providers/generic/generic.go @@ -61,7 +61,7 @@ func (a *Generic) GetInventory(ctx context.Context, options ...actions.Option) ( // Collect device inventory a.logger.Info("Collecting inventory") - collector := actions.NewInventoryCollectorAction(options...) + collector := actions.NewInventoryCollectorAction(a.logger, options...) if err := collector.Collect(ctx, a.hw.Device); err != nil { return nil, err } diff --git a/providers/supermicro/supermicro.go b/providers/supermicro/supermicro.go index 96c54771..f5829e85 100644 --- a/providers/supermicro/supermicro.go +++ b/providers/supermicro/supermicro.go @@ -103,7 +103,7 @@ func (s *supermicro) GetInventory(ctx context.Context, options ...actions.Option options = append(options, actions.WithCollectors(collectors)) - collector := actions.NewInventoryCollectorAction(options...) + collector := actions.NewInventoryCollectorAction(s.logger, options...) if err := collector.Collect(ctx, s.hw.Device); err != nil { return nil, err }