From f58bee2d651fc9aa77579ba190775aa3d8f8a350 Mon Sep 17 00:00:00 2001 From: "James W. Brinkerhoff" Date: Thu, 10 Oct 2024 11:55:03 -0400 Subject: [PATCH] Ensure a 120 second 'provider timeout' with each bmclib client Signed-off-by: James W. Brinkerhoff --- grpc/oob/bmc/bmc.go | 7 +++++++ grpc/oob/bmc/users_bmclibv2.go | 4 ++++ grpc/oob/diagnostic/clearsel.go | 4 ++++ grpc/oob/diagnostic/nmi.go | 4 ++++ grpc/oob/diagnostic/screenshot.go | 4 ++++ grpc/oob/machine/machine.go | 4 ++++ 6 files changed, 27 insertions(+) diff --git a/grpc/oob/bmc/bmc.go b/grpc/oob/bmc/bmc.go index 54c7381..0589191 100644 --- a/grpc/oob/bmc/bmc.go +++ b/grpc/oob/bmc/bmc.go @@ -3,6 +3,7 @@ package bmc import ( "context" "fmt" + "time" "github.com/bmc-toolbox/bmclib/v2" "github.com/bmc-toolbox/bmclib/v2/bmc" @@ -310,6 +311,9 @@ func (m Action) BMCReset(ctx context.Context, rType string) (err error) { span.SetAttributes(attribute.String("bmc.host", host), attribute.String("bmc.username", user)) m.SendStatusMessage("working on bmc reset") + ctx, cancel := context.WithTimeout(ctx, 120*time.Second) + defer cancel() + opts := []bmclib.Option{ bmclib.WithLogger(m.Log), bmclib.WithPerProviderTimeout(common.BMCTimeoutFromCtx(ctx)), @@ -381,6 +385,9 @@ func (m Action) DeactivateSOL(ctx context.Context) error { span.SetAttributes(attribute.String("bmc.host", host), attribute.String("bmc.username", user)) m.SendStatusMessage("working on SOL session deactivation") + ctx, cancel := context.WithTimeout(ctx, 120*time.Second) + defer cancel() + opts := []bmclib.Option{ bmclib.WithLogger(m.Log), bmclib.WithPerProviderTimeout(common.BMCTimeoutFromCtx(ctx)), diff --git a/grpc/oob/bmc/users_bmclibv2.go b/grpc/oob/bmc/users_bmclibv2.go index f93b6e1..0f1d052 100644 --- a/grpc/oob/bmc/users_bmclibv2.go +++ b/grpc/oob/bmc/users_bmclibv2.go @@ -3,6 +3,7 @@ package bmc import ( "context" "fmt" + "time" "github.com/bmc-toolbox/bmclib/v2" "github.com/go-logr/logr" @@ -33,6 +34,9 @@ type bmclibv2UserManagement struct { func (b *bmclibv2UserManagement) Connect(ctx context.Context) error { var errMsg repository.Error + ctx, cancel := context.WithTimeout(ctx, 120*time.Second) + defer cancel() + opts := []bmclib.Option{ bmclib.WithLogger(b.log), bmclib.WithPerProviderTimeout(common.BMCTimeoutFromCtx(ctx)), diff --git a/grpc/oob/diagnostic/clearsel.go b/grpc/oob/diagnostic/clearsel.go index b39b7eb..974aa36 100644 --- a/grpc/oob/diagnostic/clearsel.go +++ b/grpc/oob/diagnostic/clearsel.go @@ -3,6 +3,7 @@ package diagnostic import ( "context" "fmt" + "time" "github.com/bmc-toolbox/bmclib/v2" "github.com/bmc-toolbox/bmclib/v2/providers" @@ -55,6 +56,9 @@ func (m Action) ClearSystemEventLog(ctx context.Context) (result string, err err } span.SetAttributes(attribute.String("bmc.host", host), attribute.String("bmc.username", user)) + ctx, cancel := context.WithTimeout(ctx, 120*time.Second) + defer cancel() + opts := []bmclib.Option{ bmclib.WithLogger(m.Log), bmclib.WithPerProviderTimeout(common.BMCTimeoutFromCtx(ctx)), diff --git a/grpc/oob/diagnostic/nmi.go b/grpc/oob/diagnostic/nmi.go index dc24ad8..b045d3f 100644 --- a/grpc/oob/diagnostic/nmi.go +++ b/grpc/oob/diagnostic/nmi.go @@ -3,6 +3,7 @@ package diagnostic import ( "context" "fmt" + "time" "github.com/bmc-toolbox/bmclib/v2" "github.com/prometheus/client_golang/prometheus" @@ -50,6 +51,9 @@ func (m Action) SendNMI(ctx context.Context) error { } span.SetAttributes(attribute.String("bmc.host", host), attribute.String("bmc.username", user)) + ctx, cancel := context.WithTimeout(ctx, 120*time.Second) + defer cancel() + opts := []bmclib.Option{ bmclib.WithLogger(m.Log), bmclib.WithPerProviderTimeout(common.BMCTimeoutFromCtx(ctx)), diff --git a/grpc/oob/diagnostic/screenshot.go b/grpc/oob/diagnostic/screenshot.go index 33f54b0..b3c424f 100644 --- a/grpc/oob/diagnostic/screenshot.go +++ b/grpc/oob/diagnostic/screenshot.go @@ -3,6 +3,7 @@ package diagnostic import ( "context" "fmt" + "time" "github.com/bmc-toolbox/bmclib/v2" "github.com/bmc-toolbox/bmclib/v2/bmc" @@ -56,6 +57,9 @@ func (m Action) GetScreenshot(ctx context.Context) (image []byte, filetype strin } span.SetAttributes(attribute.String("bmc.host", host), attribute.String("bmc.username", user)) + ctx, cancel := context.WithTimeout(ctx, 120*time.Second) + defer cancel() + opts := []bmclib.Option{ bmclib.WithLogger(m.Log), bmclib.WithPerProviderTimeout(common.BMCTimeoutFromCtx(ctx)), diff --git a/grpc/oob/machine/machine.go b/grpc/oob/machine/machine.go index cd17504..96c0c48 100644 --- a/grpc/oob/machine/machine.go +++ b/grpc/oob/machine/machine.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "strings" + "time" "github.com/bmc-toolbox/bmclib/v2" "github.com/bmc-toolbox/bmclib/v2/bmc" @@ -149,6 +150,9 @@ func (m Action) BootDeviceSet(ctx context.Context, device string, persistent, ef msg := "working on " + base m.SendStatusMessage(msg) + ctx, cancel := context.WithTimeout(ctx, 120*time.Second) + defer cancel() + opts := []bmclib.Option{ bmclib.WithLogger(m.Log), bmclib.WithPerProviderTimeout(common.BMCTimeoutFromCtx(ctx)),