Skip to content

Commit

Permalink
outofband/bmc: simplify time.Duration consts, lint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
joelrebel committed May 4, 2023
1 parent 42f8c53 commit c5f9397
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 18 deletions.
21 changes: 4 additions & 17 deletions internal/outofband/bmc.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import (

var (
// logoutTimeout is the timeout value when logging out of a bmc
logoutTimeout = "1m"
//loginTimeout = "1m"
logoutTimeout = 1 * time.Minute
loginTimeout = 1 * time.Minute
loginAttempts = 3

// login errors
Expand Down Expand Up @@ -71,13 +71,7 @@ func (b *bmc) Open(ctx context.Context) error {
}

// login to the bmc with retries
if err := b.loginWithRetries(ctx, loginAttempts); err != nil {
return err
}



return nil
return b.loginWithRetries(ctx, loginAttempts)
}

// Close logs out of the BMC
Expand All @@ -86,12 +80,7 @@ func (b *bmc) Close() error {
return nil
}

timeout, err := time.ParseDuration(logoutTimeout)
if err != nil {
return errors.Wrap(errBMCLogout, err.Error())
}

ctx, cancel := context.WithDeadline(context.Background(), time.Now().Add(timeout))
ctx, cancel := context.WithTimeout(context.Background(), logoutTimeout)
defer cancel()

if err := b.client.Close(ctx); err != nil {
Expand Down Expand Up @@ -190,14 +179,12 @@ func (b *bmc) FirmwareInstallStatus(ctx context.Context, installVersion, compone
// if hostWasReset {
// return false, nil
// }

return model.StatusInstallPowerCycleHostRequired, nil
case bmclibv2consts.FirmwareInstallPowerCycleBMC:
// if BMC is under reset return false (this is the final state only for queuing the update)
// if bmcWasReset {
// return false, nil
// }

return model.StatusInstallPowerCycleBMCRequired, nil
case bmclibv2consts.FirmwareInstallComplete:
return model.StatusInstallComplete, nil
Expand Down
6 changes: 5 additions & 1 deletion internal/outofband/bmc_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,18 @@ import (
"github.com/sirupsen/logrus"
)

func newHttpClient() *http.Client {
func newHTTPClient() *http.Client {
jar, err := cookiejar.New(&cookiejar.Options{PublicSuffixList: publicsuffix.List})
if err != nil {
panic(err)
}

// nolint:gomnd // time duration declarations are clear as is.
return &http.Client{
Timeout: time.Second * 600,
Jar: jar,
Transport: &http.Transport{
// nolint:gosec // BMCs don't have valid certs.
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
DisableKeepAlives: true,
Dial: (&net.Dialer{
Expand Down Expand Up @@ -134,6 +136,8 @@ func (b *bmc) sessionActive(ctx context.Context) error {
// check and the login attempt is ignored.
func (b *bmc) loginWithRetries(ctx context.Context, tries int) error {
attempts := 1

// nolint:gomnd // time duration definitions are clear as is.
delay := &backoff.Backoff{
Min: 5 * time.Second,
Max: 30 * time.Second,
Expand Down

0 comments on commit c5f9397

Please sign in to comment.