From e42b165f80fced80c253ef13545f2366ddf43add Mon Sep 17 00:00:00 2001 From: Joel Rebello Date: Thu, 15 Aug 2024 10:37:23 +0200 Subject: [PATCH] UpdateRequirements getters to return a pointer to struct instead of a copy of the struct --- actions/interface.go | 4 ++-- actions/update.go | 7 +++---- providers/asrockrack/asrockrack.go | 4 ++-- providers/dell/dell.go | 4 ++-- providers/generic/generic.go | 4 ++-- providers/supermicro/supermicro.go | 2 +- utils/mlxup.go | 4 ++-- 7 files changed, 14 insertions(+), 15 deletions(-) diff --git a/actions/interface.go b/actions/interface.go index c0ee5fb7..52d64749 100644 --- a/actions/interface.go +++ b/actions/interface.go @@ -46,7 +46,7 @@ type Getter interface { // Retrieve BIOS configuration for device GetBIOSConfiguration(ctx context.Context) (map[string]string, error) // UpdateRequirements returns requirements to be met before and after a firmware install - UpdateRequirements(ctx context.Context, componentSlug, componentVendor, componentModel string) (model.UpdateRequirements, error) + UpdateRequirements(ctx context.Context, componentSlug, componentVendor, componentModel string) (*model.UpdateRequirements, error) } // Utility interface couples the configuration, collection and update interfaces @@ -154,7 +154,7 @@ type UEFIVarsCollector interface { // UpdateRequirements returns requirements to be met before and after a firmware install, // the caller may use the information to determine if a powercycle, reconfiguration or other actions are required on the component. type UpdateRequirementsGetter interface { - UpdateRequirements(componentModel string) model.UpdateRequirements + UpdateRequirements(componentModel string) *model.UpdateRequirements } // DriveUpdater defines an interface to update drive firmware diff --git a/actions/update.go b/actions/update.go index ef866a20..204b1cf7 100644 --- a/actions/update.go +++ b/actions/update.go @@ -75,22 +75,21 @@ func UpdateAll(ctx context.Context, device *common.Device, options []*model.Upda // UpdateRequirements returns requirements to be met before and after a firmware install, // the caller may use the information to determine if a powercycle, reconfiguration or other actions are required on the component. -func UpdateRequirements(componentSlug, componentVendor, componentModel string) (model.UpdateRequirements, error) { +func UpdateRequirements(componentSlug, componentVendor, componentModel string) (*model.UpdateRequirements, error) { slug := strings.ToUpper(componentSlug) vendor := common.FormatVendorName(componentVendor) - req := model.UpdateRequirements{} switch componentSlug { case common.SlugNIC: updater, err := GetNICUpdater(vendor) if err != nil { - return req, err + return nil, err } return updater.UpdateRequirements(componentModel), nil default: - return req, errors.Wrap(errs.ErrNoUpdateHandlerForComponent, "component: "+slug) + return nil, errors.Wrap(errs.ErrNoUpdateHandlerForComponent, "component: "+slug) } } diff --git a/providers/asrockrack/asrockrack.go b/providers/asrockrack/asrockrack.go index 15cd0937..1e97905d 100644 --- a/providers/asrockrack/asrockrack.go +++ b/providers/asrockrack/asrockrack.go @@ -95,8 +95,8 @@ func (a *asrockrack) InstallUpdates(context.Context, *model.UpdateOptions) error // UpdateRequirements returns requirements to be met before and after a firmware install, // the caller may use the information to determine if a powercycle, reconfiguration or other actions are required on the component. -func (a *asrockrack) UpdateRequirements(_ context.Context, _, _, _ string) (model.UpdateRequirements, error) { - return model.UpdateRequirements{}, errors.Wrap(errs.ErrUpdateReqNotImplemented, "provider: asrockrack") +func (a *asrockrack) UpdateRequirements(_ context.Context, _, _, _ string) (*model.UpdateRequirements, error) { + return nil, errors.Wrap(errs.ErrUpdateReqNotImplemented, "provider: asrockrack") } // GetInventoryOEM collects device inventory using vendor specific tooling diff --git a/providers/dell/dell.go b/providers/dell/dell.go index 08b06107..73b8072a 100644 --- a/providers/dell/dell.go +++ b/providers/dell/dell.go @@ -166,8 +166,8 @@ func (d *dell) ListAvailableUpdates(ctx context.Context, options *model.UpdateOp // UpdateRequirements returns requirements to be met before and after a firmware install, // the caller may use the information to determine if a powercycle, reconfiguration or other actions are required on the component. -func (d *dell) UpdateRequirements(_ context.Context, _, _, _ string) (model.UpdateRequirements, error) { - return model.UpdateRequirements{}, errors.Wrap(errs.ErrUpdateReqNotImplemented, "provider: generic") +func (d *dell) UpdateRequirements(_ context.Context, _, _, _ string) (*model.UpdateRequirements, error) { + return nil, errors.Wrap(errs.ErrUpdateReqNotImplemented, "provider: generic") } // InstallUpdates for Dells based on updateOptions diff --git a/providers/generic/generic.go b/providers/generic/generic.go index cddf23dc..9f3c1321 100644 --- a/providers/generic/generic.go +++ b/providers/generic/generic.go @@ -86,8 +86,8 @@ func (a *Generic) ListAvailableUpdates(_ context.Context, _ *model.UpdateOptions // UpdateRequirements returns requirements to be met before and after a firmware install, // the caller may use the information to determine if a powercycle, reconfiguration or other actions are required on the component. -func (a *Generic) UpdateRequirements(_ context.Context, _, _, _ string) (model.UpdateRequirements, error) { - return model.UpdateRequirements{}, errors.Wrap(errs.ErrUpdateReqNotImplemented, "provider: generic") +func (a *Generic) UpdateRequirements(_ context.Context, _, _, _ string) (*model.UpdateRequirements, error) { + return nil, errors.Wrap(errs.ErrUpdateReqNotImplemented, "provider: generic") } // InstallUpdates installs updates based on updateOptions diff --git a/providers/supermicro/supermicro.go b/providers/supermicro/supermicro.go index bfdd75e0..30856649 100644 --- a/providers/supermicro/supermicro.go +++ b/providers/supermicro/supermicro.go @@ -113,7 +113,7 @@ func (s *supermicro) ListAvailableUpdates(context.Context, *model.UpdateOptions) // UpdateRequirements returns requirements to be met before and after a firmware install, // the caller may use the information to determine if a powercycle, reconfiguration or other actions are required on the component. -func (s *supermicro) UpdateRequirements(_ context.Context, componentSlug, componentVendor, componentModel string) (model.UpdateRequirements, error) { +func (s *supermicro) UpdateRequirements(_ context.Context, componentSlug, componentVendor, componentModel string) (*model.UpdateRequirements, error) { return actions.UpdateRequirements(componentSlug, componentVendor, componentModel) } diff --git a/utils/mlxup.go b/utils/mlxup.go index aa1db768..d728d1c1 100644 --- a/utils/mlxup.go +++ b/utils/mlxup.go @@ -150,8 +150,8 @@ func setNICFirmware(d *MlxupDevice, firmware *common.Firmware) { } // UpdateRequirements implements the actions/NICUpdater interface to return any pre/post firmware install requirements. -func (m *Mlxup) UpdateRequirements(_ string) model.UpdateRequirements { - return model.UpdateRequirements{PostInstallHostPowercycle: true} +func (m *Mlxup) UpdateRequirements(_ string) *model.UpdateRequirements { + return &model.UpdateRequirements{PostInstallHostPowercycle: true} } // UpdateNIC updates mellanox NIC with the given update file