m/t/launch: multi-node launches, prefixed stdout
This reinstantiates //:launch-test2, with some small fixes for usability
(prefixed stdout and GetNodes retries to handle cluster connectivity
issues as the cluster grows).
We also drive-by port //:launch-test2 and //:launch to use the new and
shiny clicontext package.
Change-Id: I62a1d827b2087f1173abf19e792a2088dc8b80bb
Reviewed-on: https://review.monogon.dev/c/monogon/+/485
Reviewed-by: Lorenz Brun <lorenz@monogon.tech>
diff --git a/metropolis/test/launch/cli/launch-multi2/BUILD.bazel b/metropolis/test/launch/cli/launch-multi2/BUILD.bazel
index 51118cf..932b57b 100644
--- a/metropolis/test/launch/cli/launch-multi2/BUILD.bazel
+++ b/metropolis/test/launch/cli/launch-multi2/BUILD.bazel
@@ -5,7 +5,10 @@
srcs = ["main.go"],
importpath = "source.monogon.dev/metropolis/test/launch/cli/launch-multi2",
visibility = ["//visibility:private"],
- deps = ["//metropolis/pkg/logbuffer:go_default_library"],
+ deps = [
+ "//metropolis/cli/pkg/context:go_default_library",
+ "//metropolis/test/launch/cluster:go_default_library",
+ ],
)
go_binary(
diff --git a/metropolis/test/launch/cli/launch-multi2/main.go b/metropolis/test/launch/cli/launch-multi2/main.go
index d6c5f05..70c3745 100644
--- a/metropolis/test/launch/cli/launch-multi2/main.go
+++ b/metropolis/test/launch/cli/launch-multi2/main.go
@@ -17,35 +17,23 @@
package main
import (
- "fmt"
- "io"
+ "context"
"log"
- "os"
- "source.monogon.dev/metropolis/pkg/logbuffer"
+ clicontext "source.monogon.dev/metropolis/cli/pkg/context"
+ "source.monogon.dev/metropolis/test/launch/cluster"
)
-// prefixedStdout is a os.Stdout proxy that prefixes every line with a constant
-// prefix. This is used to show logs from two Metropolis nodes without getting
-// them confused.
-// TODO(q3k): move to logging API instead of relying on qemu stdout, and remove
-// this function.
-func prefixedStdout(prefix string) io.ReadWriter {
- lb := logbuffer.NewLineBuffer(2048, func(l *logbuffer.Line) {
- fmt.Fprintf(os.Stdout, "%s%s\n", prefix, l.Data)
- })
- // Make a ReaderWriter from LineBuffer (a Reader), by combining into an
- // anonymous struct with a io.MultiReader() (which will always return EOF
- // on every Read if given no underlying readers).
- return struct {
- io.Reader
- io.Writer
- }{
- Reader: io.MultiReader(),
- Writer: lb,
- }
-}
-
func main() {
- log.Fatal("unimplemented")
+ ctx := clicontext.WithInterrupt(context.Background())
+ cl, err := cluster.LaunchCluster(ctx, cluster.ClusterOptions{
+ NumNodes: 2,
+ })
+ if err != nil {
+ log.Fatalf("LaunchCluster: %v", err)
+ }
+ log.Printf("Launch: Cluster running!")
+
+ <-ctx.Done()
+ cl.Close()
}