Skip to content

Commit

Permalink
Add error handling for remote serial console
Browse files Browse the repository at this point in the history
Fixes #358

Signed-off-by: Pau Capdevila <pau@githedgehog.com>
  • Loading branch information
pau-hedgehog committed Feb 1, 2025
1 parent 0b9ea04 commit 0262a03
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
28 changes: 18 additions & 10 deletions pkg/hhfab/vlabhelpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,21 +342,29 @@ func (c *Config) VLABSwitchReinstall(ctx context.Context, opts SwitchReinstallOp
cmd.Stderr = logutil.NewSink(ctx, slog.Debug, sw.Name+": ")

if err := cmd.Run(); err != nil {
mu.Lock()
defer mu.Unlock()

var exitErr *exec.ExitError
if errors.As(err, &exitErr) {
errs = append(errs, wrapError(sw.Name, exitErr.ExitCode()))
// Handle both exit code 1 and 255 as critical errors
if exitErr.ExitCode() == 1 || exitErr.ExitCode() == 255 {
mu.Lock()
errs = append(errs, wrapError(sw.Name, exitErr.ExitCode()))
mu.Unlock()
slog.Error("Failed to reinstall switch", "name", sw.Name, "error", err)
return

Check failure on line 353 in pkg/hhfab/vlabhelpers.go

View workflow job for this annotation

GitHub Actions / test

return with no blank line before (nlreturn)
}
} else if errors.Is(ctx.Err(), context.DeadlineExceeded) {
errs = append(errs, fmt.Errorf("%s: timeout (context deadline exceeded)", sw.Name)) //nolint:goerr113
mu.Lock()
errs = append(errs, fmt.Errorf("%s: timeout (context deadline exceeded)", sw.Name))

Check failure on line 357 in pkg/hhfab/vlabhelpers.go

View workflow job for this annotation

GitHub Actions / test

do not define dynamic errors, use wrapped static errors instead: "fmt.Errorf(\"%s: timeout (context deadline exceeded)\", sw.Name)" (err113)
mu.Unlock()
slog.Error("Failed to reinstall switch", "name", sw.Name, "error", err)
return

Check failure on line 360 in pkg/hhfab/vlabhelpers.go

View workflow job for this annotation

GitHub Actions / test

return with no blank line before (nlreturn)
} else {
errs = append(errs, fmt.Errorf("%s: %w", sw.Name, err)) //nolint:goerr113
mu.Lock()
errs = append(errs, fmt.Errorf("%s: %w", sw.Name, err))
mu.Unlock()
slog.Error("Failed to reinstall switch", "name", sw.Name, "error", err)
return

Check failure on line 366 in pkg/hhfab/vlabhelpers.go

View workflow job for this annotation

GitHub Actions / test

return with no blank line before (nlreturn)
}

slog.Error("Failed to reinstall switch", "name", sw.Name, "error", err)

return
}

if opts.WaitReady {
Expand Down
4 changes: 4 additions & 0 deletions pkg/hhfab/vlabhelpers_reinstall.exp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ if {$spawn_result != 0} {
}

expect {
-re "This connection is in use.*" {
log_message "ERR" $SW_NAME "Serial port is in use by another session"
exit $ERROR_CONSOLE
}
-ex "Type the hot key to suspend the connection: <CTRL>Z" {
send "\r"
}
Expand Down

0 comments on commit 0262a03

Please sign in to comment.