Skip to content

Commit 2045f0b

Browse files
craig[bot]Renato Costa
andcommitted
106275: roachtest: support `versions-binary-override` in `mixedversion` r=srosenberg a=renatolabs The `BinaryPathFromVersion` (now renamed to `BinaryPathForVersion` based on an early pull request review comment) was not taking into account the `versions-binary-override` flag passed to roachtest when determining the path where the binary for a certain version should live in a node. This commit updates that function to take that into account. This improves the debugging experience for mixedversion tests by letting the user swap the binary of a certain version for a custom one, possibly with more debug code. Epic: CRDB-19321 Release note: None Co-authored-by: Renato Costa <[email protected]>
2 parents 4177598 + 482a84a commit 2045f0b

File tree

4 files changed

+38
-31
lines changed

4 files changed

+38
-31
lines changed

pkg/cmd/roachtest/main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ Use --bench to list benchmarks instead of tests.
237237
238238
Each test has a set of tags. The tags are used to skip tests which don't match
239239
the tag filter. The tag filter is specified by specifying a pattern with the
240-
"tag:" prefix.
240+
"tag:" prefix.
241241
242242
If multiple "tag:" patterns are specified, the test must match at
243243
least one of them.
@@ -404,8 +404,8 @@ runner itself.
404404
cmd.Flags().StringToStringVar(
405405
&versionsBinaryOverride, "versions-binary-override", nil,
406406
"List of <version>=<path to cockroach binary>. If a certain version <ver> "+
407-
"is present in the list,"+"the respective binary will be used when a "+
408-
"multi-version test asks for the respective binary, instead of "+
407+
"is present in the list, the respective binary will be used when a "+
408+
"mixed-version test asks for the respective binary, instead of "+
409409
"`roachprod stage <ver>`. Example: 20.1.4=cockroach-20.1,20.2.0=cockroach-20.2.")
410410
}
411411

pkg/cmd/roachtest/roachtestutil/clusterupgrade/clusterupgrade.go

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -81,33 +81,35 @@ func UploadVersion(
8181
nodes option.NodeListOption,
8282
newVersion string,
8383
) (string, error) {
84-
binaryName := "./cockroach"
85-
if newVersion == MainVersion {
86-
if err := c.PutE(ctx, l, t.Cockroach(), binaryName, nodes); err != nil {
87-
return "", err
88-
}
89-
} else if binary, ok := t.VersionsBinaryOverride()[newVersion]; ok {
90-
// If an override has been specified for newVersion, use that binary.
91-
l.Printf("using binary override for version %s: %s", newVersion, binary)
92-
binaryName = "./cockroach-" + newVersion
93-
if err := c.PutE(ctx, l, binary, binaryName, nodes); err != nil {
84+
dstBinary := BinaryPathForVersion(t, newVersion)
85+
srcBinary := t.Cockroach()
86+
87+
overrideBinary, isOverriden := t.VersionsBinaryOverride()[newVersion]
88+
if isOverriden {
89+
l.Printf("using binary override for version %s: %s", newVersion, overrideBinary)
90+
srcBinary = overrideBinary
91+
}
92+
93+
if newVersion == MainVersion || isOverriden {
94+
if err := c.PutE(ctx, l, srcBinary, dstBinary, nodes); err != nil {
9495
return "", err
9596
}
9697
} else {
9798
v := "v" + newVersion
98-
dir := v
99-
binaryName = filepath.Join(dir, "cockroach")
99+
dir := filepath.Dir(dstBinary)
100+
100101
// Check if the cockroach binary already exists.
101-
if err := c.RunE(ctx, nodes, "test", "-e", binaryName); err != nil {
102-
if err := c.RunE(ctx, nodes, "mkdir", "-p", dir); err != nil {
103-
return "", err
104-
}
105-
if err := c.Stage(ctx, l, "release", v, dir, nodes); err != nil {
106-
return "", err
107-
}
102+
cmd := fmt.Sprintf("test -e %s || mkdir -p %s", dstBinary, dir)
103+
if err := c.RunE(ctx, nodes, cmd); err != nil {
104+
return "", err
105+
}
106+
107+
if err := c.Stage(ctx, l, "release", v, dir, nodes); err != nil {
108+
return "", err
108109
}
109110
}
110-
return BinaryPathFromVersion(newVersion), nil
111+
112+
return dstBinary, nil
111113
}
112114

113115
// InstallFixtures copies the previously created fixtures (in
@@ -157,14 +159,19 @@ func StartWithSettings(
157159
return c.StartE(ctx, l, startOpts, settings, nodes)
158160
}
159161

160-
// BinaryPathFromVersion shows where the binary for the given version
161-
// can be found on roachprod nodes. It's either `./cockroach` or the
162-
// path to which a released binary is staged.
163-
func BinaryPathFromVersion(v string) string {
164-
if v == "" {
162+
// BinaryPathForVersion shows where the binary for the given version
163+
// is expected to be found on roachprod nodes. The file will only
164+
// actually exist if there was a previous call to `UploadVersion` with
165+
// the same version parameter.
166+
func BinaryPathForVersion(t test.Test, v string) string {
167+
if v == MainVersion {
165168
return "./cockroach"
169+
} else if _, ok := t.VersionsBinaryOverride()[v]; ok {
170+
// If an override has been specified for `v`, use that binary.
171+
return "./cockroach-" + v
172+
} else {
173+
return filepath.Join("v"+v, "cockroach")
166174
}
167-
return filepath.Join("v"+v, "cockroach")
168175
}
169176

170177
// RestartNodesWithNewBinary uploads a given cockroach version to the

pkg/cmd/roachtest/tests/mixed_version_backup.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1971,7 +1971,7 @@ func (mvb *mixedVersionBackup) resetCluster(
19711971
return fmt.Errorf("failed to wipe cluster: %w", err)
19721972
}
19731973

1974-
cockroachPath := clusterupgrade.BinaryPathFromVersion(version)
1974+
cockroachPath := clusterupgrade.BinaryPathForVersion(mvb.t, version)
19751975
return clusterupgrade.StartWithSettings(
19761976
ctx, l, mvb.cluster, mvb.roachNodes, option.DefaultStartOptsNoBackups(),
19771977
install.BinaryOption(cockroachPath), install.SecureOption(true),

pkg/cmd/roachtest/tests/versionupgrade.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ func makeVersionFixtureAndFatal(
378378
name := clusterupgrade.CheckpointName(u.binaryVersion(ctx, t, 1).String())
379379
u.c.Stop(ctx, t.L(), option.DefaultStopOpts(), c.All())
380380

381-
binaryPath := clusterupgrade.BinaryPathFromVersion(fixtureVersion)
381+
binaryPath := clusterupgrade.BinaryPathForVersion(t, fixtureVersion)
382382
c.Run(ctx, c.All(), binaryPath, "debug", "pebble", "db", "checkpoint",
383383
"{store-dir}", "{store-dir}/"+name)
384384
// The `cluster-bootstrapped` marker can already be found within

0 commit comments

Comments
 (0)