mirror of
https://github.com/tailscale/tailscale.git
synced 2024-11-29 04:55:31 +00:00
vnet: don't hard-code bradfitz or maisem in paths
Updates #13038 Change-Id: Ie8c7591fac3800bb3b7f8c35356cce309fd3c164 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
parent
6798f8ea88
commit
082e46b48d
@ -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
|
||||
|
@ -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=
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user