Skip to content

Commit

Permalink
internal/outofband: a few debug logging improvements, shadow err var …
Browse files Browse the repository at this point in the history
…fixes
  • Loading branch information
joelrebel committed Apr 18, 2024
1 parent 7bfa9fd commit ef1343a
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 15 deletions.
9 changes: 7 additions & 2 deletions internal/outofband/bmc.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ func (b *bmc) tracelog() {

b.logger.WithFields(
logrus.Fields{
"asset.Vendor": b.asset.Vendor,
"asset.Model": b.asset.Model,
"attemptedProviders": strings.Join(b.client.GetMetadata().ProvidersAttempted, ","),
"successfulProvider": b.client.GetMetadata().SuccessfulProvider,
"successfulOpens": strings.Join(b.client.GetMetadata().SuccessfulOpenConns, ","),
Expand Down Expand Up @@ -253,15 +255,18 @@ func (b *bmc) FirmwareInstallSteps(ctx context.Context, component string) (steps

// pin the install provider once its identified
// this makes sure the subsequent firmware requests are performed using this provider.
b.installProvider = b.client.GetMetadata().SuccessfulProvider
provider := b.client.GetMetadata().SuccessfulProvider

// Validate we have a provider
//
// generally if the FirmwareInstallSteps method returned successfully this should not occur
if b.installProvider == "" {
if provider == "" || provider == "unknown" {
return nil, ErrFirmwareInstallProvider
}

b.installProvider = provider
b.logger.WithField("install-provider", b.installProvider).Trace("install provider")

return steps, nil
}

Expand Down
40 changes: 27 additions & 13 deletions internal/outofband/bmc_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,26 @@ func (b *bmc) with(provider string) *bmclib.Client {

if !slices.Contains(b.availableProviders, provider) {
b.logger.WithFields(
logrus.Fields{"require": provider, "available": strings.Join(b.availableProviders, ",")},
).Trace(funcName + ": required provider not in available list")
logrus.Fields{
"vendor": b.asset.Vendor,
"model": b.asset.Model,
"required": provider,
"available": strings.Join(b.availableProviders, ","),
"caller": funcName,
},
).Trace("required provider not in available list")

return b.client
}

b.logger.WithFields(
logrus.Fields{"require": provider, "available": strings.Join(b.availableProviders, ",")},
logrus.Fields{
"vendor": b.asset.Vendor,
"model": b.asset.Model,
"required": provider,
"available": strings.Join(b.availableProviders, ","),
"caller": funcName,
},
).Info(funcName + ": with bmclib provider")

return b.client.For(provider)
Expand Down Expand Up @@ -196,12 +208,13 @@ func (b *bmc) loginWithRetries(ctx context.Context, maxAttempts int, provider st
}

// attempt login
err := b.with(provider).Open(attemptCtx)
if err != nil {
errLogin := b.with(provider).Open(attemptCtx)
if errLogin != nil {
var errRetry error
// failed to open connection
attempts, err = b.retry(ctx, maxAttempts, attempts, err, provider)
if err != nil {
return err
attempts, errRetry = b.retry(ctx, maxAttempts, attempts, errLogin, provider)
if errRetry != nil {
return errRetry
}

continue
Expand All @@ -215,10 +228,11 @@ func (b *bmc) loginWithRetries(ctx context.Context, maxAttempts int, provider st
_ = b.client.Close(attemptCtx)
}

err := errors.New("required bmclib install provider not available: " + provider)
attempts, err = b.retry(ctx, maxAttempts, attempts, err, provider)
if err != nil {
return err
var errRetry error
errFmt := errors.New("required bmclib install provider not available: " + provider)
attempts, errRetry = b.retry(ctx, maxAttempts, attempts, errFmt, provider)
if errRetry != nil {
return errRetry
}

continue
Expand Down Expand Up @@ -252,7 +266,7 @@ func (b *bmc) retry(ctx context.Context, maxAttempts, attempts int, cause error,
"attempt": trystr,
"successfulOpens": b.client.GetMetadata().SuccessfulOpenConns,
"cause": cause,
}).Debug("bmc login to be retried")
}).Debug("retrying bmc login")

// return if attempts match tries
if attempts >= maxAttempts {
Expand Down

0 comments on commit ef1343a

Please sign in to comment.