diff --git a/pkg/cmd/roachtest/cluster.go b/pkg/cmd/roachtest/cluster.go index 57ea85016154..175b6713ee3f 100644 --- a/pkg/cmd/roachtest/cluster.go +++ b/pkg/cmd/roachtest/cluster.go @@ -554,6 +554,20 @@ func execCmdWithBuffer(ctx context.Context, l *logger, args ...string) ([]byte, return out, nil } +// execCmdWithStdout executes the given command and returns its stdout +// output. If the return code is not 0, an error is also returned. +// l is used to log the command before running it. No output is logged. +func execCmdWithStdout(ctx context.Context, l *logger, args ...string) ([]byte, error) { + l.Printf("> %s\n", strings.Join(args, " ")) + cmd := exec.CommandContext(ctx, args[0], args[1:]...) + + out, err := cmd.Output() + if err != nil { + return out, errors.Wrapf(err, `%s`, strings.Join(args, ` `)) + } + return out, nil +} + func makeGCEClusterName(name string) string { name = strings.ToLower(name) name = regexp.MustCompile(`[^-a-z0-9]+`).ReplaceAllString(name, "-") @@ -2283,6 +2297,18 @@ func (c *cluster) RunWithBuffer( append([]string{roachprod, "run", c.makeNodes(node), "--"}, args...)...) } +// RunWithStdout runs a command on the specified node, returning the resulting +// stdout. +func (c *cluster) RunWithStdout( + ctx context.Context, l *logger, node nodeListOption, args ...string, +) ([]byte, error) { + if err := errors.Wrap(ctx.Err(), "cluster.RunWithStdout"); err != nil { + return nil, err + } + return execCmdWithStdout(ctx, l, + append([]string{roachprod, "run", c.makeNodes(node), "--"}, args...)...) +} + // pgURL returns the Postgres endpoint for the specified node. It accepts a flag // specifying whether the URL should include the node's internal or external IP // address. In general, inter-cluster communication and should use internal IPs diff --git a/pkg/cmd/roachtest/dump.go b/pkg/cmd/roachtest/dump.go index 3c02b6209a61..6ea5ae1f1cd5 100644 --- a/pkg/cmd/roachtest/dump.go +++ b/pkg/cmd/roachtest/dump.go @@ -62,7 +62,7 @@ func runDump(nodes nodeListOption, mainVersion, expected string) versionStep { return func(ctx context.Context, t *test, u *versionUpgradeTest) { // Put the new version of Cockroach onto the node. u.uploadVersion(ctx, t, nodes, mainVersion) - raw, err := u.c.RunWithBuffer(ctx, t.logger(), nodes, `./cockroach dump --insecure d`) + raw, err := u.c.RunWithStdout(ctx, t.logger(), nodes, `./cockroach dump --insecure d`) if err != nil { t.Fatal(err) }