@ -126,7 +126,7 @@ func TestDownloadImages(t *testing.T) {
t . Parallel ( )
fetchDistro ( t , distro , bins )
( Harness { bins : bins } ) . fetchDistro ( t , distro )
} )
}
}
@ -242,7 +242,7 @@ func fetchFromS3(t *testing.T, fout *os.File, d Distro) bool {
// fetchDistro fetches a distribution from the internet if it doesn't already exist locally. It
// also validates the sha256 sum from a known good hash.
func fetchDistro ( t * testing . T , resultDistro Distro , bins * integration . Binaries ) string {
func ( h Harness ) fetchDistro ( t * testing . T , resultDistro Distro ) string {
t . Helper ( )
cdir , err := os . UserCacheDir ( )
@ -252,7 +252,11 @@ func fetchDistro(t *testing.T, resultDistro Distro, bins *integration.Binaries)
cdir = filepath . Join ( cdir , "tailscale" , "vm-test" )
if strings . HasPrefix ( resultDistro . name , "nixos" ) {
return makeNixOSImage ( t , resultDistro , cdir , bins )
var imagePath string
t . Run ( "nix-build" , func ( t * testing . T ) {
imagePath = h . makeNixOSImage ( t , resultDistro , cdir )
} )
return imagePath
}
qcowPath := filepath . Join ( cdir , "qcow2" , resultDistro . sha256sum )
@ -448,7 +452,7 @@ func mkSeed(t *testing.T, d Distro, sshKey, hostURL, tdir string, port int) {
// mkVM makes a KVM-accelerated virtual machine and prepares it for introduction
// to the testcontrol server. The function it returns is for killing the virtual
// machine when it is time for it to die.
func mkVM ( t * testing . T , n int , d Distro , sshKey , hostURL , tdir string , bins * integration . Binaries ) {
func ( h Harness ) mkVM ( t * testing . T , n int , d Distro , sshKey , hostURL , tdir string ) {
t . Helper ( )
cdir , err := os . UserCacheDir ( )
@ -463,7 +467,7 @@ func mkVM(t *testing.T, n int, d Distro, sshKey, hostURL, tdir string, bins *int
t . Fatal ( err )
}
mkLayeredQcow ( t , tdir , d , fetchDistro ( t , d , bins ) )
mkLayeredQcow ( t , tdir , d , h . fetchDistro ( t , d ) )
mkSeed ( t , d , sshKey , hostURL , tdir , port )
driveArg := fmt . Sprintf ( "file=%s,if=virtio" , filepath . Join ( tdir , d . name + ".qcow2" ) )
@ -600,6 +604,7 @@ func TestVMIntegrationEndToEnd(t *testing.T) {
mux := http . NewServeMux ( )
mux . Handle ( "/" , cs )
mux . Handle ( "/c/" , & integration . LogCatcher { } )
// This handler will let the virtual machines tell the host information about that VM.
// This is used to maintain a list of port->IP address mappings that are known to be
@ -677,7 +682,7 @@ func TestVMIntegrationEndToEnd(t *testing.T) {
}
defer ramsem . Release ( int64 ( distro . mem ) )
mkVM ( t , n , distro , string ( pubkey ) , loginServer , dir , bins )
h . mkVM ( t , n , distro , string ( pubkey ) , loginServer , dir )
var ipm ipMapping
t . Run ( "wait-for-start" , func ( t * testing . T ) {
@ -703,7 +708,6 @@ func TestVMIntegrationEndToEnd(t *testing.T) {
func ( h Harness ) testDistro ( t * testing . T , d Distro , ipm ipMapping ) {
signer := h . signer
bins := h . bins
loginServer := h . loginServerURL
t . Helper ( )
@ -741,7 +745,7 @@ func (h Harness) testDistro(t *testing.T, d Distro, ipm ipMapping) {
if err != nil {
t . Fatal ( err )
}
copyBinaries ( t , d , cli , bins )
h . copyBinaries ( t , d , cli )
timeout := 30 * time . Second
@ -887,7 +891,8 @@ func runTestCommands(t *testing.T, timeout time.Duration, cli *ssh.Client, batch
}
}
func copyBinaries ( t * testing . T , d Distro , conn * ssh . Client , bins * integration . Binaries ) {
func ( h Harness ) copyBinaries ( t * testing . T , d Distro , conn * ssh . Client ) {
bins := h . bins
if strings . HasPrefix ( d . name , "nixos" ) {
return
}
@ -917,6 +922,12 @@ func copyBinaries(t *testing.T, d Distro, conn *ssh.Client, bins *integration.Bi
copyFile ( t , cli , "../../../cmd/tailscaled/tailscaled.service" , "/etc/systemd/system/tailscaled.service" )
}
fout , err := cli . OpenFile ( "/etc/default/tailscaled" , os . O_WRONLY | os . O_APPEND )
if err != nil {
t . Fatalf ( "can't append to defaults for tailscaled: %v" , err )
}
fmt . Fprintf ( fout , "\n\nTS_LOG_TARGET=%s\n" , h . loginServerURL )
t . Log ( "tailscale installed!" )
}
@ -1027,7 +1038,11 @@ func (h *Harness) makeTestNode(t *testing.T, bins *integration.Binaries, control
fmt . Sprintf ( "--socks5-server=localhost:%d" , port ) ,
)
cmd . Env = append ( os . Environ ( ) , "NOTIFY_SOCKET=" + filepath . Join ( dir , "notify_socket" ) )
cmd . Env = append (
os . Environ ( ) ,
"NOTIFY_SOCKET=" + filepath . Join ( dir , "notify_socket" ) ,
"TS_LOG_TARGET=" + h . loginServerURL ,
)
err = cmd . Start ( )
if err != nil {