blob: b195ecf5c7d89a357fb0e1b2021c4f02c09fdb31 [file] [log] [blame]
Lorenz Brunfc5dbc62020-05-28 12:18:07 +02001// Copyright 2020 The Monogon Project Authors.
2//
3// SPDX-License-Identifier: Apache-2.0
4//
5// Licensed under the Apache License, Version 2.0 (the "License");
6// you may not use this file except in compliance with the License.
7// You may obtain a copy of the License at
8//
9// http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing, software
12// distributed under the License is distributed on an "AS IS" BASIS,
13// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14// See the License for the specific language governing permissions and
15// limitations under the License.
16
17package main
18
19import (
20 "context"
Lorenz Brun52f7f292020-06-24 16:42:02 +020021 "log"
Lorenz Brunfc5dbc62020-05-28 12:18:07 +020022 "os"
Lorenz Brunfc5dbc62020-05-28 12:18:07 +020023
Serge Bazanski075465c2021-11-16 15:38:49 +010024 clicontext "source.monogon.dev/metropolis/cli/pkg/context"
Serge Bazanski0ed2f962021-03-15 16:39:30 +010025 apb "source.monogon.dev/metropolis/proto/api"
Serge Bazanski31370b02021-01-07 16:31:14 +010026 "source.monogon.dev/metropolis/test/launch"
Serge Bazanski66e58952021-10-05 17:06:56 +020027 "source.monogon.dev/metropolis/test/launch/cluster"
Lorenz Brunfc5dbc62020-05-28 12:18:07 +020028)
29
30func main() {
Mateusz Zalega0246f5e2022-04-22 17:29:04 +020031 // Create the launch directory.
32 ld, err := os.MkdirTemp(os.Getenv("TEST_TMPDIR"), "node_state*")
33 if err != nil {
34 log.Fatalf("couldn't create a launch directory: %v", err)
35 }
36 defer os.RemoveAll(ld)
37 // Create the socket directory. Since using TEST_TMPDIR will often result in
38 // paths too long to place UNIX sockets at, we'll use the LSB temporary
39 // directory.
40 sd, err := os.MkdirTemp("/tmp", "node_sock*")
41 if err != nil {
42 log.Fatalf("couldn't create a socket directory: %v", err)
43 }
44 defer os.RemoveAll(sd)
45
Serge Bazanskibe742842022-04-04 13:18:50 +020046 var ports []uint16
47 for _, p := range cluster.NodePorts {
48 ports = append(ports, uint16(p))
49 }
Serge Bazanski075465c2021-11-16 15:38:49 +010050 ctx := clicontext.WithInterrupt(context.Background())
Mateusz Zalega0246f5e2022-04-22 17:29:04 +020051 err = cluster.LaunchNode(ctx, ld, sd, &cluster.NodeOptions{
Serge Bazanskibe742842022-04-04 13:18:50 +020052 Ports: launch.IdentityPortMap(ports),
Serge Bazanski0ed2f962021-03-15 16:39:30 +010053 SerialPort: os.Stdout,
54 NodeParameters: &apb.NodeParameters{
55 Cluster: &apb.NodeParameters_ClusterBootstrap_{
Serge Bazanski66e58952021-10-05 17:06:56 +020056 ClusterBootstrap: cluster.InsecureClusterBootstrap,
Serge Bazanski0ed2f962021-03-15 16:39:30 +010057 },
58 },
Serge Bazanski075465c2021-11-16 15:38:49 +010059 })
60 if err != nil {
61 log.Fatalf("LaunchNode: %v", err)
Lorenz Brunfc5dbc62020-05-28 12:18:07 +020062 }
63}