Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

roachprod: fix fileExistsOnFirstNode check #105514

Merged
merged 1 commit into from
Jun 27, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions pkg/roachprod/install/cluster_synced.go
Original file line number Diff line number Diff line change
Expand Up @@ -1531,8 +1531,19 @@ func (c *SyncedCluster) fileExistsOnFirstNode(
ctx context.Context, l *logger.Logger, path string,
) (bool, error) {
l.Printf("%s: checking %s", c.Name, path)
result, err := c.runCmdOnSingleNode(ctx, l, c.Nodes[0], `$(test -e `+path+`); echo $?`, false, l.Stdout, l.Stderr)
return result.Stdout == "0", err
testCmd := `$(test -e ` + path + `);`
// Do not log output to stdout/stderr because in some cases this call will be expected to exit 1.
result, err := c.runCmdOnSingleNode(ctx, l, c.Nodes[0], testCmd, true, nil, nil)
if (result.RemoteExitStatus != 0 && result.RemoteExitStatus != 1) || err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does result.Err play a role here? Shouldn't we check for it too? (cc @smg260)

// Unexpected exit status (neither 0 nor 1) or non-nil error. Return combined output along with err returned
// from the call if it's not nil.
if err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This logic could be simplified by lifting the shared error (running '%s' ...) and calling Wrapf if err != nil

return false, errors.Wrapf(err, "running '%s' failed with exit code=%d: got %s", testCmd, result.RemoteExitStatus, string(result.CombinedOut))
} else {
return false, errors.Newf("running '%s' failed with exit code=%d: got %s", testCmd, result.RemoteExitStatus, string(result.CombinedOut))
}
}
return result.RemoteExitStatus == 0, nil
}

// createNodeCertArguments returns a list of strings appropriate for use as
Expand Down