Skip to content

Commit 2b9bc5d

Browse files
dmitshurgopherbot
authored andcommitted
cmd/bootstrapswarm: allow hostname flag to be left empty on GCE
CL 526618 changed the 'on GCE' path of bootstrapswarm to forcibly use its own internal hostname computation rather than the value of the hostname flag, dropping "(required)" from its description. But the flag is still required when not on GCE, and even on GCE bootstrapswarm would exit fatally if os.Getenv("HOSTNAME") happened to be the empty string. Make all of this more precise. Spotted while investigating why the swarming bot wouldn't come up in sid and wanted to eliminate this possibility, even though it turned out to be due to a Python 3.13 incompatibility as described in CL 665016 and not this. Change-Id: Ibf65057290e9d8cb79a2800fdc982d35d7edf68b Reviewed-on: https://go-review.googlesource.com/c/build/+/666375 LUCI-TryBot-Result: Go LUCI <[email protected]> Auto-Submit: Dmitri Shuralyov <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]> Reviewed-by: Michael Pratt <[email protected]>
1 parent b220385 commit 2b9bc5d

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

cmd/bootstrapswarm/bootstrapswarm.go

+6-5
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@
1111
// within the user's home directory.
1212
//
1313
// Requirements:
14-
// - Python3 installed and in the calling user's PATH.
14+
// - Python 3 installed and available in PATH (or equivalent) under the name python3 (or python3.exe on Windows).
1515
//
1616
// Not on GCE: bootstrapswarm will read the token file and retrieve the
1717
// the luci machine token. It will use that token to authenticate and
1818
// download the swarming bot. It will then start the swarming bot in a
1919
// directory within the user's home directory.
2020
//
2121
// Requirements:
22-
// - Python3 installed and in the calling user's PATH.
22+
// - Python 3 installed and available in PATH (or equivalent) under the name python3 (or python3.exe on Windows).
2323
// - luci_machine_tokend running as root in a cron job.
2424
// See https://chromium.googlesource.com/infra/luci/luci-go/+/main/tokenserver.
2525
// Further instructions can be found at https://go.dev/wiki/DashboardBuilders.
@@ -48,7 +48,7 @@ import (
4848
)
4949

5050
var (
51-
hostname = flag.String("hostname", os.Getenv("HOSTNAME"), "Hostname of machine to bootstrap")
51+
hostname = flag.String("hostname", os.Getenv("HOSTNAME"), "Hostname of machine to bootstrap (required when not on GCE)")
5252
swarming = flag.String("swarming", "chromium-swarm.appspot.com", "Swarming server to connect to")
5353
)
5454

@@ -58,7 +58,8 @@ func main() {
5858
flag.PrintDefaults()
5959
}
6060
flag.Parse()
61-
if *hostname == "" {
61+
if *hostname == "" && !metadata.OnGCE() {
62+
fmt.Fprintln(os.Stderr, "Hostname is required when not on GCE.")
6263
flag.Usage()
6364
os.Exit(2)
6465
}
@@ -83,7 +84,7 @@ func bootstrap(ctx context.Context, hostname string) error {
8384

8485
// Override the hostname flag with the GCE hostname. This is a hard
8586
// requirement for LUCI, so there's no point in trying anything else.
86-
fullHost, err := metadata.Hostname()
87+
fullHost, err := metadata.HostnameWithContext(ctx)
8788
if err != nil {
8889
return fmt.Errorf("retrieving hostname: %w", err)
8990
}

0 commit comments

Comments
 (0)