Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integration v2: port resolve magicdns #889

Merged
merged 5 commits into from
Oct 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ test_integration_v2_general:
-v $$PWD:$$PWD -w $$PWD/integration \
-v /var/run/docker.sock:/var/run/docker.sock \
golang:1 \
go test ./... -timeout 30m
go test ./... -timeout 60m

coverprofile_func:
go tool cover -func=coverage.out
Expand Down
83 changes: 83 additions & 0 deletions integration/general_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package integration

import (
"fmt"
"strings"
"testing"
"time"

Expand Down Expand Up @@ -255,3 +256,85 @@ func TestTaildrop(t *testing.T) {
t.Errorf("failed to tear down scenario: %s", err)
}
}

func TestResolveMagicDNS(t *testing.T) {
IntegrationSkip(t)

scenario, err := NewScenario()
if err != nil {
t.Errorf("failed to create scenario: %s", err)
}

spec := map[string]int{
// Omit 1.16.2 (-1) because it does not have the FQDN field
"magicdns1": len(TailscaleVersions) - 1,
"magicdns2": len(TailscaleVersions) - 1,
}

err = scenario.CreateHeadscaleEnv(spec)
if err != nil {
t.Errorf("failed to create headscale environment: %s", err)
}

allClients, err := scenario.ListTailscaleClients()
if err != nil {
t.Errorf("failed to get clients: %s", err)
}

err = scenario.WaitForTailscaleSync()
if err != nil {
t.Errorf("failed wait for tailscale clients to be in sync: %s", err)
}

// Poor mans cache
_, err = scenario.ListTailscaleClientsFQDNs()
if err != nil {
t.Errorf("failed to get FQDNs: %s", err)
}

_, err = scenario.ListTailscaleClientsIPs()
if err != nil {
t.Errorf("failed to get IPs: %s", err)
}

for _, client := range allClients {
for _, peer := range allClients {
// It is safe to ignore this error as we handled it when caching it
peerFQDN, _ := peer.FQDN()

command := []string{
"tailscale",
"ip", peerFQDN,
}
result, err := client.Execute(command)
if err != nil {
t.Errorf(
"failed to execute resolve/ip command %s from %s: %s",
peerFQDN,
client.Hostname(),
err,
)
}

ips, err := peer.IPs()
if err != nil {
t.Errorf(
"failed to get ips for %s: %s",
peer.Hostname(),
err,
)
}

for _, ip := range ips {
if !strings.Contains(result, ip.String()) {
t.Errorf("ip %s is not found in \n%s\n", ip.String(), result)
}
}
}
}

err = scenario.Shutdown()
if err != nil {
t.Errorf("failed to tear down scenario: %s", err)
}
}
9 changes: 4 additions & 5 deletions integration/tsic/tsic.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,17 +121,17 @@ func (t *TailscaleInContainer) Execute(
if err != nil {
log.Printf("command stderr: %s\n", stderr)

if stdout != "" {
log.Printf("command stdout: %s\n", stdout)
}

if strings.Contains(stderr, "NeedsLogin") {
return "", errTailscaleNotLoggedIn
}

return "", err
}

if stdout != "" {
log.Printf("command stdout: %s\n", stdout)
}

return stdout, nil
}

Expand All @@ -156,7 +156,6 @@ func (t *TailscaleInContainer) Up(
return nil
}

// TODO(kradalby): Make cached/lazy.
func (t *TailscaleInContainer) IPs() ([]netip.Addr, error) {
if t.ips != nil && len(t.ips) != 0 {
return t.ips, nil
Expand Down