From c6ca534fc4c68dad38f1c9a9cbcc6bf686001af6 Mon Sep 17 00:00:00 2001 From: Pau Capdevila Date: Tue, 14 Jan 2025 23:08:04 +0100 Subject: [PATCH] Add --ready switch-reinstall command Adds capability to run hhfab whole hardware test: hhfab vlab up -v --ready switch-reinstall --ready \ setup-vpcs --ready test-connectivity --ready exit switch-reinstall is equivalent to run hhfab vlab switch reinstall --all --yes -mode hard-reset Signed-off-by: Pau Capdevila tbs --- pkg/hhfab/vlabhelpers.go | 2 +- pkg/hhfab/vlabrunner.go | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/pkg/hhfab/vlabhelpers.go b/pkg/hhfab/vlabhelpers.go index 96ffcf3a7..c9160b550 100644 --- a/pkg/hhfab/vlabhelpers.go +++ b/pkg/hhfab/vlabhelpers.go @@ -349,7 +349,7 @@ func (c *Config) SwitchReinstall(ctx context.Context, opts SwitchReinstallOpts) cmd.Stderr = os.Stderr // Expect messages logged to stderr to show progress } - slog.Debug("Running cmd " + cmdName + " " + strings.Join(args, " ") + "...") + slog.Debug("Running command", "cmdName", cmdName, "args", []string{sw.Name, opts.Username, "REDACTED"}) if err := cmd.Run(); err != nil { mu.Lock() defer mu.Unlock() diff --git a/pkg/hhfab/vlabrunner.go b/pkg/hhfab/vlabrunner.go index 61377dc1d..af8eefc53 100644 --- a/pkg/hhfab/vlabrunner.go +++ b/pkg/hhfab/vlabrunner.go @@ -91,12 +91,14 @@ type OnReady string const ( OnReadyExit OnReady = "exit" OnReadySetupVPCs OnReady = "setup-vpcs" + OnReadySwitchReinstall OnReady = "switch-reinstall" OnReadyTestConnectivity = "test-connectivity" ) var AllOnReady = []OnReady{ OnReadyExit, OnReadySetupVPCs, + OnReadySwitchReinstall, OnReadyTestConnectivity, } @@ -422,8 +424,16 @@ func (c *Config) VLABRun(ctx context.Context, vlab *VLAB, opts VLABRunOpts) erro for _, cmd := range opts.OnReady { slog.Info("Running on-ready command", "command", cmd) - switch OnReady(cmd) { + case OnReadySwitchReinstall: + if err := c.SwitchReinstall(ctx, SwitchReinstallOpts{ + Name: AllSwitches, + Mode: "hard-reset", + Verbose: false, + WaitReady: false, + }); err != nil { + return fmt.Errorf("setting up VPCs: %w", err) + } case OnReadySetupVPCs: // TODO make it configurable if err := c.SetupVPCs(ctx, vlab, SetupVPCsOpts{