Skip to content

Commit

Permalink
Add --ready switch-reinstall command
Browse files Browse the repository at this point in the history
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 <[email protected]>

tbs
  • Loading branch information
pau-hedgehog committed Jan 14, 2025
1 parent 96e9c2a commit c6ca534
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pkg/hhfab/vlabhelpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
12 changes: 11 additions & 1 deletion pkg/hhfab/vlabrunner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand Down Expand Up @@ -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{
Expand Down

0 comments on commit c6ca534

Please sign in to comment.