From 0735960a10940f7cf765644571e8583efbff6fa2 Mon Sep 17 00:00:00 2001 From: "Bryan T. Richardson" Date: Fri, 16 Feb 2024 10:44:57 -0700 Subject: [PATCH] fix: avoid tunnel failures from expected errors MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When `cc tunnel` is run in a namespace that has multiple nodes, each node will try to create the tunnel and only one will succeed since the VM being used for the tunnel will only be on one node. The other nodes will report back an error, and this was causing phēnix to assume the tunnel creation had failed. This commit updates the `cc tunnel` command to be prefixed with the node to execute the command on rather than having it sprayed to all nodes. --- src/go/util/mm/minimega.go | 32 ++++++++++++++++++++++++++++---- src/go/util/mm/mmcli/tabular.go | 2 -- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/src/go/util/mm/minimega.go b/src/go/util/mm/minimega.go index eac0a9d1..955e161f 100644 --- a/src/go/util/mm/minimega.go +++ b/src/go/util/mm/minimega.go @@ -155,7 +155,7 @@ func (this Minimega) GetVMInfo(opts ...Option) VMs { State: row["state"], Running: row["state"] == "RUNNING", CCActive: activeC2[row["uuid"]], - CdRom: row["cdrom"], + CdRom: row["cdrom"], } s := row["vlan"] @@ -508,10 +508,21 @@ func (Minimega) DisconnectVMInterface(opts ...Option) error { } func (Minimega) CreateTunnel(opts ...Option) error { + host, err := GetVMHost(opts...) + if err != nil { + return fmt.Errorf("unable to determine what host the VM is scheduled on: %w", err) + } + o := NewOptions(opts...) + var cmdPrefix string + + if !IsHeadnode(host) { + cmdPrefix = fmt.Sprintf("mesh send %s namespace %s", host, o.ns) + } + cmd := mmcli.NewNamespacedCommand(o.ns) - cmd.Command = fmt.Sprintf("cc tunnel %s %d %s %d", o.vm, o.srcPort, o.dstHost, o.dstPort) + cmd.Command = fmt.Sprintf("%s cc tunnel %s %d %s %d", cmdPrefix, o.vm, o.srcPort, o.dstHost, o.dstPort) if err := mmcli.ErrorResponse(mmcli.Run(cmd)); err != nil { return fmt.Errorf("creating tunnel to %s (%d:%s:%d): %w", o.vm, o.srcPort, o.dstHost, o.dstPort, err) @@ -544,12 +555,25 @@ func (Minimega) GetTunnels(opts ...Option) []map[string]string { func (Minimega) CloseTunnel(opts ...Option) error { tunnels := GetTunnels(opts...) + host, err := GetVMHost(opts...) + if err != nil { + return fmt.Errorf("unable to determine what host the VM is scheduled on: %w", err) + } + o := NewOptions(opts...) - var errs error + + var ( + cmdPrefix string + errs error + ) + + if !IsHeadnode(host) { + cmdPrefix = fmt.Sprintf("mesh send %s namespace %s", host, o.ns) + } for _, row := range tunnels { cmd := mmcli.NewNamespacedCommand(o.ns) - cmd.Command = fmt.Sprintf("cc tunnel close %s %s", o.vm, row["id"]) + cmd.Command = fmt.Sprintf("%s cc tunnel close %s %s", cmdPrefix, o.vm, row["id"]) if err := mmcli.ErrorResponse(mmcli.Run(cmd)); err != nil { errs = multierror.Append(errs, fmt.Errorf("closing tunnel to %s (%s:%d): %w", o.vm, o.dstHost, o.dstPort, err)) diff --git a/src/go/util/mm/mmcli/tabular.go b/src/go/util/mm/mmcli/tabular.go index fe7236df..2fe0b995 100644 --- a/src/go/util/mm/mmcli/tabular.go +++ b/src/go/util/mm/mmcli/tabular.go @@ -3,7 +3,6 @@ package mmcli import ( - "fmt" "strings" "github.com/activeshadow/libminimega/minicli" @@ -65,7 +64,6 @@ func RunTabular(cmd *Command) []map[string]string { for resps := range Run(cmd) { for _, resp := range resps.Resp { if resp.Error != "" { - fmt.Println(resp.Error) continue }