Skip to content

Commit

Permalink
fix: avoid tunnel failures from expected errors
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
activeshadow committed Feb 16, 2024
1 parent 198ba5a commit 0735960
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
32 changes: 28 additions & 4 deletions src/go/util/mm/minimega.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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))
Expand Down
2 changes: 0 additions & 2 deletions src/go/util/mm/mmcli/tabular.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
package mmcli

import (
"fmt"
"strings"

"github.com/activeshadow/libminimega/minicli"
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit 0735960

Please sign in to comment.