1
0
mirror of https://github.com/juanfont/headscale.git synced 2025-07-18 13:46:45 +02:00

make traceroute func

Signed-off-by: Kristoffer Dalby <kristoffer@tailscale.com>
This commit is contained in:
Kristoffer Dalby 2025-03-14 15:54:45 +01:00
parent 911da48fd5
commit ca9d37ed9a
No known key found for this signature in database
3 changed files with 23 additions and 4 deletions

View File

@ -1036,6 +1036,10 @@ func assertNodeRouteCount(t *testing.T, node *v1.Node, announced, approved, subn
assert.Len(t, node.GetSubnetRoutes(), subnet)
}
// TestSubnetRouterMultiNetwork is an evolution of the subnet router test.
// This test will set up multiple docker networks and use two isolated tailscale
// clients and a service available in one of the networks to validate that a
// subnet router is working as expected.
func TestSubnetRouterMultiNetwork(t *testing.T) {
IntegrationSkip(t)
t.Parallel()
@ -1130,8 +1134,7 @@ func TestSubnetRouterMultiNetwork(t *testing.T) {
assert.Len(t, nodes, 2)
assertNodeRouteCount(t, nodes[0], 1, 1, 1)
// Verify that no routes has been sent to the client,
// they are not yet enabled.
// Verify that the routes have been sent to the client.
status, err = user2c.Status()
require.NoError(t, err)
@ -1159,8 +1162,8 @@ func TestSubnetRouterMultiNetwork(t *testing.T) {
require.NoError(t, err)
assert.Len(t, result, 13)
stdout, stderr, err := user2c.Execute([]string{"traceroute", webip.String()})
assert.Contains(t, stdout+stderr, user1c.MustIPv4().String())
tr, err := user2c.Traceroute(webip)
assert.Contains(t, tr, user1c.MustIPv4().String())
}
// requirePeerSubnetRoutes asserts that the peer has the expected subnet routes.

View File

@ -41,6 +41,7 @@ type TailscaleClient interface {
WaitForPeers(expected int) error
Ping(hostnameOrIP string, opts ...tsic.PingOption) error
Curl(url string, opts ...tsic.CurlOption) (string, error)
Traceroute(netip.Addr) (string, error)
ID() string
ReadFile(path string) ([]byte, error)

View File

@ -1130,6 +1130,21 @@ func (t *TailscaleInContainer) Curl(url string, opts ...CurlOption) (string, err
return result, nil
}
func (t *TailscaleInContainer) Traceroute(ip netip.Addr) (string, error) {
command := []string{
"traceroute",
ip.String(),
}
var result string
result, _, err := t.Execute(command)
if err != nil {
return result, err
}
return result, nil
}
// WriteFile save file inside the Tailscale container.
func (t *TailscaleInContainer) WriteFile(path string, data []byte) error {
return integrationutil.WriteFileToContainer(t.pool, t.container, path, data)