Skip to content

Commit

Permalink
Drop non-unique Cleanup logic from expect step
Browse files Browse the repository at this point in the history
Summary:
To enable actual clean ups and prevent errors like

```
ERROR   failed to run command:
        could not load TTP at /home/nesusvet/security-ttpcode/ttps/infra/tupperware/ssh-to-container-as-root.yaml:
        could not parse action for step "start-tupperware-container": action fields did not match any valid action type
```

Differential Revision: D64108097
  • Loading branch information
inesusvet authored and facebook-github-bot committed Oct 9, 2024
1 parent 50f6817 commit 2835510
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 36 deletions.
2 changes: 2 additions & 0 deletions example-ttps/actions/expect/expect.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,5 @@ steps:
response: "John"
- prompt: "Enter your age:"
response: "30"
cleanup:
inline: echo "Wipe it"
36 changes: 0 additions & 36 deletions pkg/blocks/expectstep.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import (
"github.com/Netflix/go-expect"
"github.com/facebookincubator/ttpforge/pkg/logging"
"github.com/facebookincubator/ttpforge/pkg/outputs"
"go.uber.org/zap"
)

// ExpectStep represents an expect command.
Expand All @@ -52,7 +51,6 @@ type ExpectStep struct {
Executor string `yaml:"executor,omitempty"`
Expect *ExpectSpec `yaml:"expect,omitempty"`
Environment map[string]string `yaml:"env,omitempty"`
CleanupStep string `yaml:"cleanup,omitempty"`
Outputs map[string]outputs.Spec `yaml:"outputs,omitempty"`
}

Expand Down Expand Up @@ -263,40 +261,6 @@ func (s *ExpectStep) prepareCommand(ctx context.Context, execCtx TTPExecutionCon
return cmd
}

// Cleanup runs the cleanup command if specified.
//
// **Parameters:**
//
// execCtx: Execution context containing environment variables and working
// directory.
//
// **Returns:**
//
// *ActResult: A pointer to the action result.
// error: An error if cleanup fails.
func (s *ExpectStep) Cleanup(execCtx TTPExecutionContext) (*ActResult, error) {
if s.CleanupStep == "" {
return &ActResult{}, nil
}

logging.L().Info("Running cleanup step")

envAsList := os.Environ()
cmd := s.prepareCommand(context.Background(), execCtx, envAsList, s.CleanupStep)

cmd.Stdout = os.Stdout
cmd.Stdin = os.Stdin
cmd.Stderr = os.Stderr

if err := cmd.Run(); err != nil {
logging.L().Error("Failed to run cleanup command", zap.Error(err))
return nil, fmt.Errorf("failed to run cleanup command: %w", err)
}

logging.L().Info("Cleanup step completed successfully")
return &ActResult{}, nil
}

// CanBeUsedInCompositeAction enables this action to be used in a composite
// action.
//
Expand Down

0 comments on commit 2835510

Please sign in to comment.