m/test: implement SOCKS proxy in cluster tests
This uses the new socksproxy package to run a proxy server in the
nanoswitch, and uses it within tests to access the test cluster's nodes.
The cluster test code (and nanoswitch) still forward traffic to the
first node, but this will be gradually removed as SOCKS support is
implemented in metroctl and the debug tool. Forwards from host ports to
different node can then be implemented as part of the dbg tool (instead
of the cluster launch code) to maintain a simple interface during debug
and development.
We also use the opportunity to make the non-cluster launch code not
Metropolis specific (by removing an assumption that all ports on all
nodes are Metropolis ports). In the long term, we will probably remove
non-cluster launches entirely (or further turn this code into just being
a 'launch qemu' wrapper).
Change-Id: I9b321bde95ba74fbfaa695eaaad8f9974aba5372
Reviewed-on: https://review.monogon.dev/c/monogon/+/648
Reviewed-by: Lorenz Brun <lorenz@monogon.tech>
diff --git a/metropolis/test/launch/launch.go b/metropolis/test/launch/launch.go
index 219e787..8f72434 100644
--- a/metropolis/test/launch/launch.go
+++ b/metropolis/test/launch/launch.go
@@ -31,9 +31,7 @@
"syscall"
"golang.org/x/sys/unix"
- "google.golang.org/grpc"
- "source.monogon.dev/metropolis/node"
"source.monogon.dev/metropolis/pkg/freeport"
)
@@ -59,7 +57,7 @@
// PortMap represents where VM ports are mapped to on the host. It maps from the VM
// port number to the host port number.
-type PortMap map[node.Port]uint16
+type PortMap map[uint16]uint16
// ToQemuForwards generates QEMU hostfwd values (https://qemu.weilnetz.de/doc/qemu-
// doc.html#:~:text=hostfwd=) for all mapped ports.
@@ -71,24 +69,10 @@
return hostfwdOptions
}
-// DialGRPC creates a gRPC client for a VM port that's forwarded/mapped to the
-// host. The given port is automatically resolved to the host-mapped port.
-func (p PortMap) DialGRPC(port node.Port, opts ...grpc.DialOption) (*grpc.ClientConn, error) {
- mappedPort, ok := p[port]
- if !ok {
- return nil, fmt.Errorf("cannot dial port: port %d is not mapped/forwarded", port)
- }
- grpcClient, err := grpc.Dial(fmt.Sprintf("localhost:%d", mappedPort), opts...)
- if err != nil {
- return nil, fmt.Errorf("failed to dial port %d: %w", port, err)
- }
- return grpcClient, nil
-}
-
// IdentityPortMap returns a port map where each given port is mapped onto itself
// on the host. This is mainly useful for development against Metropolis. The dbg
// command requires this mapping.
-func IdentityPortMap(ports []node.Port) PortMap {
+func IdentityPortMap(ports []uint16) PortMap {
portMap := make(PortMap)
for _, port := range ports {
portMap[port] = uint16(port)
@@ -101,7 +85,7 @@
// multiple instances of Metropolis nodes might be running. Please call this
// function for each Launch command separately and as close to it as possible since
// it cannot guarantee that the ports will remain free.
-func ConflictFreePortMap(ports []node.Port) (PortMap, error) {
+func ConflictFreePortMap(ports []uint16) (PortMap, error) {
portMap := make(PortMap)
for _, port := range ports {
mappedPort, listenCloser, err := freeport.AllocateTCPPort()