Skip to content

Commit

Permalink
Add SetBiosConfigurationInterfaces alongside GetBiosConfigurationInte…
Browse files Browse the repository at this point in the history
…rfaces
  • Loading branch information
splaspood committed Feb 20, 2024
1 parent ffd3733 commit 6495779
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 3 deletions.
63 changes: 63 additions & 0 deletions bmc/bios.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,20 @@ type BiosConfigurationGetter interface {
GetBiosConfiguration(ctx context.Context) (biosConfig map[string]string, err error)
}

type BiosConfigurationSetter interface {
SetBiosConfiguration(ctx context.Context, biosConfig map[string]string) (err error)
}

type biosConfigurationGetterProvider struct {
name string
BiosConfigurationGetter
}

type biosConfigurationSetterProvider struct {
name string
BiosConfigurationSetter
}

func biosConfiguration(ctx context.Context, generic []biosConfigurationGetterProvider) (biosConfig map[string]string, metadata Metadata, err error) {
var metadataLocal Metadata
Loop:
Expand Down Expand Up @@ -46,6 +55,34 @@ Loop:
return biosConfig, metadataLocal, multierror.Append(err, errors.New("failure to get bios configuration"))
}

func setBiosConfiguration(ctx context.Context, generic []biosConfigurationSetterProvider, toSet map[string]string) (metadata Metadata, err error) {
var metadataLocal Metadata
Loop:
for _, elem := range generic {
if elem.BiosConfigurationSetter == nil {
continue

Check warning on line 63 in bmc/bios.go

View check run for this annotation

Codecov / codecov/patch

bmc/bios.go#L58-L63

Added lines #L58 - L63 were not covered by tests
}
select {
case <-ctx.Done():
err = multierror.Append(err, ctx.Err())
break Loop
default:
metadataLocal.ProvidersAttempted = append(metadataLocal.ProvidersAttempted, elem.name)
vErr := elem.SetBiosConfiguration(ctx, toSet)
if vErr != nil {
err = multierror.Append(err, errors.WithMessagef(vErr, "provider: %v", elem.name))
err = multierror.Append(err, vErr)
continue

Check warning on line 75 in bmc/bios.go

View check run for this annotation

Codecov / codecov/patch

bmc/bios.go#L65-L75

Added lines #L65 - L75 were not covered by tests

}
metadataLocal.SuccessfulProvider = elem.name
return metadataLocal, nil

Check warning on line 79 in bmc/bios.go

View check run for this annotation

Codecov / codecov/patch

bmc/bios.go#L78-L79

Added lines #L78 - L79 were not covered by tests
}
}

return metadataLocal, multierror.Append(err, errors.New("failure to set bios configuration"))

Check warning on line 83 in bmc/bios.go

View check run for this annotation

Codecov / codecov/patch

bmc/bios.go#L83

Added line #L83 was not covered by tests
}

func GetBiosConfigurationInterfaces(ctx context.Context, generic []interface{}) (biosConfig map[string]string, metadata Metadata, err error) {
implementations := make([]biosConfigurationGetterProvider, 0)
for _, elem := range generic {
Expand All @@ -71,3 +108,29 @@ func GetBiosConfigurationInterfaces(ctx context.Context, generic []interface{})

return biosConfiguration(ctx, implementations)
}

func SetBiosConfigurationInterfaces(ctx context.Context, generic []interface{}, toSet map[string]string) (metadata Metadata, err error) {
implementations := make([]biosConfigurationSetterProvider, 0)
for _, elem := range generic {
temp := biosConfigurationSetterProvider{name: getProviderName(elem)}
switch p := elem.(type) {
case BiosConfigurationSetter:
temp.BiosConfigurationSetter = p
implementations = append(implementations, temp)
default:
e := fmt.Sprintf("not a BiosConfigurationSetter implementation: %T", p)
err = multierror.Append(err, errors.New(e))

Check warning on line 122 in bmc/bios.go

View check run for this annotation

Codecov / codecov/patch

bmc/bios.go#L112-L122

Added lines #L112 - L122 were not covered by tests
}
}
if len(implementations) == 0 {
return metadata, multierror.Append(
err,
errors.Wrap(
bmclibErrs.ErrProviderImplementation,
("no BiosConfigurationGetter implementations found"),
),
)

Check warning on line 132 in bmc/bios.go

View check run for this annotation

Codecov / codecov/patch

bmc/bios.go#L125-L132

Added lines #L125 - L132 were not covered by tests
}

return setBiosConfiguration(ctx, implementations, toSet)

Check warning on line 135 in bmc/bios.go

View check run for this annotation

Codecov / codecov/patch

bmc/bios.go#L135

Added line #L135 was not covered by tests
}
11 changes: 11 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,17 @@ func (c *Client) GetBiosConfiguration(ctx context.Context) (biosConfig map[strin
return biosConfig, err
}

func (c *Client) SetBiosConfiguration(ctx context.Context, biosConfig map[string]string) (err error) {
ctx, span := c.traceprovider.Tracer(pkgName).Start(ctx, "SetBiosConfiguration")
defer span.End()

Check warning on line 561 in client.go

View check run for this annotation

Codecov / codecov/patch

client.go#L559-L561

Added lines #L559 - L561 were not covered by tests

metadata, err := bmc.SetBiosConfigurationInterfaces(ctx, c.registry().GetDriverInterfaces(), biosConfig)
c.setMetadata(metadata)
metadata.RegisterSpanAttributes(c.Auth.Host, span)

Check warning on line 565 in client.go

View check run for this annotation

Codecov / codecov/patch

client.go#L563-L565

Added lines #L563 - L565 were not covered by tests

return err

Check warning on line 567 in client.go

View check run for this annotation

Codecov / codecov/patch

client.go#L567

Added line #L567 was not covered by tests
}

// FirmwareInstall pass through library function to upload firmware and install firmware
func (c *Client) FirmwareInstall(ctx context.Context, component string, operationApplyTime string, forceInstall bool, reader io.Reader) (taskID string, err error) {
ctx, span := c.traceprovider.Tracer(pkgName).Start(ctx, "FirmwareInstall")
Expand Down
6 changes: 3 additions & 3 deletions internal/redfishwrapper/bios.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ func (c *Client) GetBiosConfiguration(ctx context.Context) (biosConfig map[strin
return biosConfig, nil
}

func (c *Conn) SetBiosConfiguration(ctx context.Context, toSet map[string]string) (err error) {
systems, err := c.redfishwrapper.Systems()
func (c *Client) SetBiosConfiguration(ctx context.Context, toSet map[string]string) (err error) {
systems, err := c.Systems()
if err != nil {
return err

Check warning on line 42 in internal/redfishwrapper/bios.go

View check run for this annotation

Codecov / codecov/patch

internal/redfishwrapper/bios.go#L39-L42

Added lines #L39 - L42 were not covered by tests
}
Expand All @@ -49,7 +49,7 @@ func (c *Conn) SetBiosConfiguration(ctx context.Context, toSet map[string]string
}

for _, sys := range systems {
if !compatibleOdataID(sys.ODataID, systemsOdataIDs) {
if !c.compatibleOdataID(sys.ODataID, knownSystemsOdataIDs) {
continue

Check warning on line 53 in internal/redfishwrapper/bios.go

View check run for this annotation

Codecov / codecov/patch

internal/redfishwrapper/bios.go#L51-L53

Added lines #L51 - L53 were not covered by tests
}

Expand Down
2 changes: 2 additions & 0 deletions providers/dell/idrac.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ var (
providers.FeatureFirmwareTaskStatus,
providers.FeatureInventoryRead,
providers.FeatureBmcReset,
providers.FeatureBiosConfigurationGetting,
providers.FeatureBiosConfigurationSetting,
}

errManufacturerUnknown = errors.New("error identifying device manufacturer")
Expand Down
7 changes: 7 additions & 0 deletions providers/redfish/redfish.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ var (
providers.FeatureInventoryRead,
providers.FeatureBmcReset,
providers.FeatureClearSystemEventLog,
providers.FeatureBiosConfigurationGetting,
providers.FeatureBiosConfigurationSetting,
}
)

Expand Down Expand Up @@ -217,3 +219,8 @@ func (c *Conn) Inventory(ctx context.Context) (device *common.Device, err error)
func (c *Conn) GetBiosConfiguration(ctx context.Context) (biosConfig map[string]string, err error) {
return c.redfishwrapper.GetBiosConfiguration(ctx)
}

// SetBiosConfiguration changes existing bios configuration
func (c *Conn) SetBiosConfiguration(ctx context.Context, biosConfig map[string]string) (err error) {
return c.redfishwrapper.SetBiosConfiguration(ctx, biosConfig)

Check warning on line 225 in providers/redfish/redfish.go

View check run for this annotation

Codecov / codecov/patch

providers/redfish/redfish.go#L224-L225

Added lines #L224 - L225 were not covered by tests
}

0 comments on commit 6495779

Please sign in to comment.