From 082e46b48da9e865cefe7d6febd24f2843da8f29 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Thu, 8 Aug 2024 08:34:08 -0700 Subject: [PATCH] vnet: don't hard-code bradfitz or maisem in paths Updates #13038 Change-Id: Ie8c7591fac3800bb3b7f8c35356cce309fd3c164 Signed-off-by: Brad Fitzpatrick --- .../tailscale/gokrazy-kernel/go.mod | 2 +- .../tailscale/gokrazy-kernel/go.sum | 2 + tstest/integration/nat/nat_test.go | 44 +++++++++++++++++-- 3 files changed, 44 insertions(+), 4 deletions(-) diff --git a/gokrazy/tsapp/builddir/github.com/tailscale/gokrazy-kernel/go.mod b/gokrazy/tsapp/builddir/github.com/tailscale/gokrazy-kernel/go.mod index 570b3ef4c..ec4d9c64f 100644 --- a/gokrazy/tsapp/builddir/github.com/tailscale/gokrazy-kernel/go.mod +++ b/gokrazy/tsapp/builddir/github.com/tailscale/gokrazy-kernel/go.mod @@ -2,4 +2,4 @@ module gokrazy/build/tsapp go 1.22.2 -require github.com/tailscale/gokrazy-kernel v0.0.0-20240530042707-3f95c886bcf2 // indirect +require github.com/tailscale/gokrazy-kernel v0.0.0-20240728225134-3d23beabda2e // indirect diff --git a/gokrazy/tsapp/builddir/github.com/tailscale/gokrazy-kernel/go.sum b/gokrazy/tsapp/builddir/github.com/tailscale/gokrazy-kernel/go.sum index edb1b5c05..d32d5460b 100644 --- a/gokrazy/tsapp/builddir/github.com/tailscale/gokrazy-kernel/go.sum +++ b/gokrazy/tsapp/builddir/github.com/tailscale/gokrazy-kernel/go.sum @@ -1,2 +1,4 @@ github.com/tailscale/gokrazy-kernel v0.0.0-20240530042707-3f95c886bcf2 h1:xzf+cMvBJBcA/Av7OTWBa0Tjrbfcy00TeatJeJt6zrY= github.com/tailscale/gokrazy-kernel v0.0.0-20240530042707-3f95c886bcf2/go.mod h1:7Mth+m9bq2IHusSsexMNyupHWPL8RxwOuSvBlSGtgDY= +github.com/tailscale/gokrazy-kernel v0.0.0-20240728225134-3d23beabda2e h1:tyUUgeRPGHjCZWycRnhdx8Lx9DRkjl3WsVUxYMrVBOw= +github.com/tailscale/gokrazy-kernel v0.0.0-20240728225134-3d23beabda2e/go.mod h1:7Mth+m9bq2IHusSsexMNyupHWPL8RxwOuSvBlSGtgDY= diff --git a/tstest/integration/nat/nat_test.go b/tstest/integration/nat/nat_test.go index 4d4d75bcd..79bcb6eec 100644 --- a/tstest/integration/nat/nat_test.go +++ b/tstest/integration/nat/nat_test.go @@ -14,15 +14,18 @@ "os" "os/exec" "path/filepath" + "strings" "sync" "testing" "time" + "golang.org/x/mod/modfile" "golang.org/x/sync/errgroup" "tailscale.com/client/tailscale" "tailscale.com/ipn/ipnstate" "tailscale.com/tailcfg" "tailscale.com/tstest/natlab/vnet" + "tailscale.com/types/logger" ) type natTest struct { @@ -30,13 +33,27 @@ type natTest struct { base string // base image tempDir string // for qcow2 images vnet *vnet.Server + kernel string // linux kernel path } func newNatTest(tb testing.TB) *natTest { + root, err := os.Getwd() + if err != nil { + tb.Fatal(err) + } + modRoot := filepath.Join(root, "../../..") + + linuxKernel, err := findKernelPath(filepath.Join(modRoot, "gokrazy/tsapp/builddir/github.com/tailscale/gokrazy-kernel/go.mod")) + if err != nil { + tb.Fatalf("findKernelPath: %v", err) + } + tb.Logf("found kernel: %v", linuxKernel) + nt := &natTest{ tb: tb, tempDir: tb.TempDir(), - base: "/Users/maisem/dev/tailscale.com/gokrazy/tsapp.qcow2", + base: filepath.Join(modRoot, "gokrazy/tsapp.qcow2"), + kernel: linuxKernel, } if _, err := os.Stat(nt.base); err != nil { @@ -45,6 +62,27 @@ func newNatTest(tb testing.TB) *natTest { return nt } +func findKernelPath(goMod string) (string, error) { + b, err := os.ReadFile(goMod) + if err != nil { + return "", err + } + mf, err := modfile.Parse("go.mod", b, nil) + if err != nil { + return "", err + } + goModB, err := exec.Command("go", "env", "GOMODCACHE").CombinedOutput() + if err != nil { + return "", err + } + for _, r := range mf.Require { + if r.Mod.Path == "github.com/tailscale/gokrazy-kernel" { + return strings.TrimSpace(string(goModB)) + "/" + r.Mod.String() + "/vmlinuz", nil + } + } + return "", fmt.Errorf("failed to find kernel in %v", goMod) +} + type addNodeFunc func(c *vnet.Config) *vnet.Node func easy(c *vnet.Config) *vnet.Node { @@ -123,7 +161,7 @@ func (nt *natTest) runTest(node1, node2 addNodeFunc) { "-M", "microvm,isa-serial=off", "-m", "1G", "-nodefaults", "-no-user-config", "-nographic", - "-kernel", "/Users/maisem/dev/github.com/tailscale/gokrazy-kernel/vmlinuz", + "-kernel", nt.kernel, "-append", "console=hvc0 root=PARTUUID=60c24cc1-f3f9-427a-8199-dd02023b0001/PARTNROFF=1 ro init=/gokrazy/init panic=10 oops=panic pci=off nousb tsc=unstable clocksource=hpet tailscale-tta=1", "-drive", "id=blk0,file="+disk+",format=qcow2", "-device", "virtio-blk-device,drive=blk0", @@ -185,7 +223,7 @@ func (nt *natTest) runTest(node1, node2 addNodeFunc) { } route, err := ping(ctx, lc1, sts[1].Self.TailscaleIPs[0]) - t.Logf("ping route: %v, %v", route, err) + t.Logf("ping route: %v, %v", logger.AsJSON(route), err) } func ping(ctx context.Context, c *vnet.NodeAgentClient, target netip.Addr) (*ipnstate.PingResult, error) {