Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

redfishwrapper changes #374

Merged
merged 28 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
bc60233
redfish/inventory: move Inventory method under internal/redfishwrapper
joelrebel Nov 27, 2023
551b709
providers/redfish: firmware methods moved into redfishwrapper
joelrebel Nov 27, 2023
1cb2383
providers/redfish: moved GetBiosConfiguration method under redfishwra…
joelrebel Nov 27, 2023
f595026
redfishwrapper/power: move implementation here for re-use
joelrebel Nov 27, 2023
79d80d0
providers/redfish: Inventory, FirmwareInstall, PowerSet, PowerState m…
joelrebel Nov 27, 2023
b9c4846
redfishwrapper: minor lint fixes
joelrebel Nov 27, 2023
05d943e
redfishwrapper/task: include task message in info
joelrebel Nov 27, 2023
619188e
redfishwrapper/task: lowercase task status before match
joelrebel Nov 27, 2023
d58aaec
bmc/firmware: fix up inconsistent metadata obj init and error collection
joelrebel Nov 27, 2023
3e6a6f1
providers/redfish: purge un-used methods
joelrebel Nov 27, 2023
b7f3de9
supermicro: implement Inventory, PowerSet, PowerStateGet methods
joelrebel Nov 27, 2023
bbc734d
providers/supermicro: fix up redfish session init and purge unused me…
joelrebel Nov 27, 2023
d22930a
providers/supermicro: fix TestOpen()
joelrebel Nov 28, 2023
5622adc
redfish/GetBiosconfiguration: tests and fixtures moved under redfishw…
joelrebel Nov 27, 2023
63f4d53
redfishwrapper/firmware: lets not strip the JID_ prefix, since the me…
joelrebel Nov 27, 2023
9f0b439
bmc/firmware: initialize metadata object properly
joelrebel Nov 27, 2023
37d8981
bmc/firmware: defines interface to upload and install firmware in the…
joelrebel Nov 27, 2023
e14321b
providers/dell: adds a helper method and implements Inventory(), Powe…
joelrebel Nov 27, 2023
ba60fa0
providers/dell: Implements FirmwareInstallSteps(), FirmwareInstallUpl…
joelrebel Nov 27, 2023
6ee715b
go: update gofish to include Task Oem data fix
joelrebel Nov 27, 2023
41cb5fa
providers/redfish: task methods moved under redfishwrapper package
joelrebel Nov 28, 2023
04eb8ca
squash
joelrebel Nov 28, 2023
cdc6f14
providers/redfish: dell tests moved under dell provider
joelrebel Nov 28, 2023
8c3aefb
redfishwrapper: minor fix for test
joelrebel Nov 28, 2023
95d52c0
Merge pull request #372 from bmc-toolbox/redfish-dell
joelrebel Nov 29, 2023
ef9c38c
Merge pull request #371 from bmc-toolbox/redfishwrapper-bios
joelrebel Nov 29, 2023
ee0f228
Merge pull request #370 from bmc-toolbox/smc-redfish-fixes
joelrebel Nov 29, 2023
afda0c3
Merge pull request #369 from bmc-toolbox/redfishwrapper-methods
joelrebel Nov 29, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
152 changes: 114 additions & 38 deletions bmc/firmware.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

// firmwareInstall uploads and initiates firmware update for the component
func firmwareInstall(ctx context.Context, component, operationApplyTime string, forceInstall bool, reader io.Reader, generic []firmwareInstallerProvider) (taskID string, metadata Metadata, err error) {
var metadataLocal Metadata
metadata = newMetadata()

for _, elem := range generic {
if elem.FirmwareInstaller == nil {
Expand All @@ -49,20 +49,20 @@

return taskID, metadata, err
default:
metadataLocal.ProvidersAttempted = append(metadataLocal.ProvidersAttempted, elem.name)
metadata.ProvidersAttempted = append(metadata.ProvidersAttempted, elem.name)
taskID, vErr := elem.FirmwareInstall(ctx, component, operationApplyTime, forceInstall, reader)
if vErr != nil {
err = multierror.Append(err, errors.WithMessagef(vErr, "provider: %v", elem.name))
err = multierror.Append(err, vErr)
metadata.FailedProviderDetail[elem.name] = err.Error()
continue

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

return taskID, metadataLocal, multierror.Append(err, errors.New("failure in FirmwareInstall"))
return taskID, metadata, multierror.Append(err, errors.New("failure in FirmwareInstall"))
}

// FirmwareInstallFromInterfaces identifies implementations of the FirmwareInstaller interface and passes the found implementations to the firmwareInstall() wrapper
Expand Down Expand Up @@ -118,7 +118,7 @@

// firmwareInstallStatus returns the status of the firmware install process
func firmwareInstallStatus(ctx context.Context, installVersion, component, taskID string, generic []firmwareInstallVerifierProvider) (status string, metadata Metadata, err error) {
var metadataLocal Metadata
metadata = newMetadata()

for _, elem := range generic {
if elem.FirmwareInstallVerifier == nil {
Expand All @@ -130,20 +130,20 @@

return status, metadata, err
default:
metadataLocal.ProvidersAttempted = append(metadataLocal.ProvidersAttempted, elem.name)
metadata.ProvidersAttempted = append(metadata.ProvidersAttempted, elem.name)
status, vErr := elem.FirmwareInstallStatus(ctx, installVersion, component, taskID)
if vErr != nil {
err = multierror.Append(err, errors.WithMessagef(vErr, "provider: %v", elem.name))
err = multierror.Append(err, vErr)
metadata.FailedProviderDetail[elem.name] = err.Error()
continue

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

return status, metadataLocal, multierror.Append(err, errors.New("failure in FirmwareInstallStatus"))
return status, metadata, multierror.Append(err, errors.New("failure in FirmwareInstallStatus"))
}

// FirmwareInstallStatusFromInterfaces identifies implementations of the FirmwareInstallVerifier interface and passes the found implementations to the firmwareInstallStatus() wrapper.
Expand Down Expand Up @@ -175,7 +175,82 @@
return firmwareInstallStatus(ctx, installVersion, component, taskID, implementations)
}

// FirmwareInstallerWithOpts defines an interface to install firmware that was previously uploaded with FirmwareUpload
// FirmwareInstallProvider defines an interface to upload and initiate a firmware install in the same implementation method
//
// Its intended to deprecate the FirmwareInstall interface
type FirmwareInstallProvider interface {
// FirmwareInstallUploadAndInitiate uploads _and_ initiates the firmware install process.
//
// return values:
// taskID - A taskID is returned if the update process on the BMC returns an identifier for the update process.
FirmwareInstallUploadAndInitiate(ctx context.Context, component string, file *os.File) (taskID string, err error)
}

// firmwareInstallProvider is an internal struct to correlate an implementation/provider and its name
type firmwareInstallProvider struct {
name string
FirmwareInstallProvider
}

// firmwareInstall uploads and initiates firmware update for the component
func firmwareInstallUploadAndInitiate(ctx context.Context, component string, file *os.File, generic []firmwareInstallProvider) (taskID string, metadata Metadata, err error) {
metadata = newMetadata()

for _, elem := range generic {
if elem.FirmwareInstallProvider == nil {
continue

Check warning on line 201 in bmc/firmware.go

View check run for this annotation

Codecov / codecov/patch

bmc/firmware.go#L201

Added line #L201 was not covered by tests
}
select {
case <-ctx.Done():
err = multierror.Append(err, ctx.Err())

return taskID, metadata, err
default:
metadata.ProvidersAttempted = append(metadata.ProvidersAttempted, elem.name)
taskID, vErr := elem.FirmwareInstallUploadAndInitiate(ctx, component, file)
if vErr != nil {
err = multierror.Append(err, errors.WithMessagef(vErr, "provider: %v", elem.name))
metadata.FailedProviderDetail[elem.name] = err.Error()
continue
}
metadata.SuccessfulProvider = elem.name
return taskID, metadata, nil
}
}

return taskID, metadata, multierror.Append(err, errors.New("failure in FirmwareInstallUploadAndInitiate"))
}

// FirmwareInstallUploadAndInitiateFromInterfaces identifies implementations of the FirmwareInstallProvider interface and passes the found implementations to the firmwareInstallUploadAndInitiate() wrapper
func FirmwareInstallUploadAndInitiateFromInterfaces(ctx context.Context, component string, file *os.File, generic []interface{}) (taskID string, metadata Metadata, err error) {
metadata = newMetadata()

implementations := make([]firmwareInstallProvider, 0)
for _, elem := range generic {
temp := firmwareInstallProvider{name: getProviderName(elem)}
switch p := elem.(type) {
case FirmwareInstallProvider:
temp.FirmwareInstallProvider = p
implementations = append(implementations, temp)
default:
e := fmt.Sprintf("not a FirmwareInstallProvider implementation: %T", p)
err = multierror.Append(err, errors.New(e))
}
}
if len(implementations) == 0 {
return taskID, metadata, multierror.Append(
err,
errors.Wrap(
bmclibErrs.ErrProviderImplementation,
("no FirmwareInstallProvider implementations found"),
),
)
}

return firmwareInstallUploadAndInitiate(ctx, component, file, implementations)
}

// FirmwareInstallerUploaded defines an interface to install firmware that was previously uploaded with FirmwareUpload
type FirmwareInstallerUploaded interface {
// FirmwareInstallUploaded uploads firmware update payload to the BMC returning the firmware install task ID
//
Expand All @@ -196,7 +271,7 @@

// firmwareInstallUploaded uploads and initiates firmware update for the component
func firmwareInstallUploaded(ctx context.Context, component, uploadTaskID string, generic []firmwareInstallerWithOptionsProvider) (installTaskID string, metadata Metadata, err error) {
var metadataLocal Metadata
metadata = newMetadata()

for _, elem := range generic {
if elem.FirmwareInstallerUploaded == nil {
Expand All @@ -208,21 +283,21 @@

return installTaskID, metadata, err
default:
metadataLocal.ProvidersAttempted = append(metadataLocal.ProvidersAttempted, elem.name)
metadata.ProvidersAttempted = append(metadata.ProvidersAttempted, elem.name)
var vErr error
installTaskID, vErr = elem.FirmwareInstallUploaded(ctx, component, uploadTaskID)
if vErr != nil {
err = multierror.Append(err, errors.WithMessagef(vErr, "provider: %v", elem.name))
err = multierror.Append(err, vErr)
metadata.FailedProviderDetail[elem.name] = err.Error()
continue

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

return installTaskID, metadataLocal, multierror.Append(err, errors.New("failure in FirmwareInstallUploaded"))
return installTaskID, metadata, multierror.Append(err, errors.New("failure in FirmwareInstallUploaded"))
}

// FirmwareInstallerUploadedFromInterfaces identifies implementations of the FirmwareInstallUploaded interface and passes the found implementations to the firmwareInstallUploaded() wrapper
Expand Down Expand Up @@ -294,7 +369,7 @@
}

func firmwareInstallSteps(ctx context.Context, component string, generic []firmwareInstallStepsGetterProvider) (steps []constants.FirmwareInstallStep, metadata Metadata, err error) {
var metadataLocal Metadata
metadata = newMetadata()

for _, elem := range generic {
if elem.FirmwareInstallStepsGetter == nil {
Expand All @@ -306,20 +381,20 @@

return steps, metadata, err
default:
metadataLocal.ProvidersAttempted = append(metadataLocal.ProvidersAttempted, elem.name)
metadata.ProvidersAttempted = append(metadata.ProvidersAttempted, elem.name)
steps, vErr := elem.FirmwareInstallSteps(ctx, component)
if vErr != nil {
err = multierror.Append(err, errors.WithMessagef(vErr, "provider: %v", elem.name))
err = multierror.Append(err, vErr)
metadata.FailedProviderDetail[elem.name] = err.Error()
continue

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

return steps, metadataLocal, multierror.Append(err, errors.New("failure in FirmwareInstallSteps"))
return steps, metadata, multierror.Append(err, errors.New("failure in FirmwareInstallSteps"))
}

type FirmwareUploader interface {
Expand Down Expand Up @@ -362,7 +437,7 @@
}

func firmwareUpload(ctx context.Context, component string, file *os.File, generic []firmwareUploaderProvider) (taskID string, metadata Metadata, err error) {
var metadataLocal Metadata
metadata = newMetadata()

for _, elem := range generic {
if elem.FirmwareUploader == nil {
Expand All @@ -374,20 +449,20 @@

return taskID, metadata, err
default:
metadataLocal.ProvidersAttempted = append(metadataLocal.ProvidersAttempted, elem.name)
metadata.ProvidersAttempted = append(metadata.ProvidersAttempted, elem.name)
taskID, vErr := elem.FirmwareUpload(ctx, component, file)
if vErr != nil {
err = multierror.Append(err, errors.WithMessagef(vErr, "provider: %v", elem.name))
err = multierror.Append(err, vErr)
metadata.FailedProviderDetail[elem.name] = err.Error()
continue

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

return taskID, metadataLocal, multierror.Append(err, errors.New("failure in FirmwareUpload"))
return taskID, metadata, multierror.Append(err, errors.New("failure in FirmwareUpload"))
}

// FirmwareTaskVerifier defines an interface to check the status for firmware related tasks queued on the BMC.
Expand Down Expand Up @@ -416,8 +491,9 @@
}

// firmwareTaskStatus returns the status of the firmware upload process.

func firmwareTaskStatus(ctx context.Context, kind bconsts.FirmwareInstallStep, component, taskID, installVersion string, generic []firmwareTaskVerifierProvider) (state constants.TaskState, status string, metadata Metadata, err error) {
var metadataLocal Metadata
metadata = newMetadata()

for _, elem := range generic {
if elem.FirmwareTaskVerifier == nil {
Expand All @@ -429,20 +505,20 @@

return state, status, metadata, err
default:
metadataLocal.ProvidersAttempted = append(metadataLocal.ProvidersAttempted, elem.name)
metadata.ProvidersAttempted = append(metadata.ProvidersAttempted, elem.name)
state, status, vErr := elem.FirmwareTaskStatus(ctx, kind, component, taskID, installVersion)
if vErr != nil {
err = multierror.Append(err, errors.WithMessagef(vErr, "provider: %v", elem.name))
err = multierror.Append(err, vErr)
metadata.FailedProviderDetail[elem.name] = err.Error()
continue

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

metadata.SuccessfulProvider = elem.name
return state, status, metadata, nil
}
}

return state, status, metadataLocal, multierror.Append(err, errors.New("failure in FirmwareTaskStatus"))
return state, status, metadata, multierror.Append(err, errors.New("failure in FirmwareTaskStatus"))
}

// FirmwareTaskStatusFromInterfaces identifies implementations of the FirmwareTaskVerifier interface and passes the found implementations to the firmwareTaskStatus() wrapper.
Expand Down
Loading