m/t/launch: use undeclared test outputs for node logs

This allows easy access to node logs for failed tests. If
NodeLogsToFiles is set and the environment variable is available, this
is used instead of the test temp dir.

Change-Id: Icf0a99280e4bfabb34f9259ea0e94ac3d6cc4b05
Reviewed-on: https://review.monogon.dev/c/monogon/+/3781
Reviewed-by: Tim Windelschmidt <tim@monogon.tech>
Tested-by: Jenkins CI
diff --git a/metropolis/test/launch/cluster.go b/metropolis/test/launch/cluster.go
index bb9f2f7..882f422 100644
--- a/metropolis/test/launch/cluster.go
+++ b/metropolis/test/launch/cluster.go
@@ -822,8 +822,12 @@
 	}
 
 	if opts.NodeLogsToFiles {
+		nodeLogDir := ld
+		if os.Getenv("TEST_UNDECLARED_OUTPUTS_DIR") != "" {
+			nodeLogDir = os.Getenv("TEST_UNDECLARED_OUTPUTS_DIR")
+		}
 		for i := range opts.NumNodes {
-			path := path.Join(ld, fmt.Sprintf("node-%d.txt", i))
+			path := path.Join(nodeLogDir, fmt.Sprintf("node-%d.txt", i))
 			port, err := NewSerialFileLogger(path)
 			if err != nil {
 				return nil, fmt.Errorf("could not open log file for node %d: %w", i, err)