mirror of
				https://github.com/juanfont/headscale.git
				synced 2025-10-31 08:01:34 +01:00 
			
		
		
		
	Add get ips command to scenario
Signed-off-by: Kristoffer Dalby <kristoffer@tailscale.com>
This commit is contained in:
		
							parent
							
								
									f109b54e79
								
							
						
					
					
						commit
						25e39d9ff9
					
				| @ -4,6 +4,7 @@ import ( | |||||||
| 	"errors" | 	"errors" | ||||||
| 	"fmt" | 	"fmt" | ||||||
| 	"log" | 	"log" | ||||||
|  | 	"net/netip" | ||||||
| 	"os" | 	"os" | ||||||
| 	"sync" | 	"sync" | ||||||
| 
 | 
 | ||||||
| @ -210,3 +211,20 @@ func (s *Scenario) RunTailscaleUp( | |||||||
| 
 | 
 | ||||||
| 	return fmt.Errorf("failed to up tailscale node: %w", errNoNamespaceAvailable) | 	return fmt.Errorf("failed to up tailscale node: %w", errNoNamespaceAvailable) | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | func (s *Scenario) GetIPs(namespace string) ([]netip.Addr, error) { | ||||||
|  | 	var ips []netip.Addr | ||||||
|  | 	if ns, ok := s.namespaces[namespace]; ok { | ||||||
|  | 		for _, client := range ns.Clients { | ||||||
|  | 			clientIps, err := client.IPs() | ||||||
|  | 			if err != nil { | ||||||
|  | 				return ips, fmt.Errorf("failed to get ips: %w", err) | ||||||
|  | 			} | ||||||
|  | 			ips = append(ips, clientIps...) | ||||||
|  | 		} | ||||||
|  | 
 | ||||||
|  | 		return ips, nil | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	return ips, fmt.Errorf("failed to get ips: %w", errNoNamespaceAvailable) | ||||||
|  | } | ||||||
|  | |||||||
| @ -17,6 +17,7 @@ const tsicHashLength = 6 | |||||||
| const dockerContextPath = "../." | const dockerContextPath = "../." | ||||||
| 
 | 
 | ||||||
| var errTailscalePingFailed = errors.New("ping failed") | var errTailscalePingFailed = errors.New("ping failed") | ||||||
|  | var errTailscaleNotLoggedIn = errors.New("tailscale not logged in") | ||||||
| 
 | 
 | ||||||
| type TailscaleInContainer struct { | type TailscaleInContainer struct { | ||||||
| 	version  string | 	version  string | ||||||
| @ -102,14 +103,17 @@ func (t *TailscaleInContainer) Up( | |||||||
| 
 | 
 | ||||||
| 	log.Println("Join command:", command) | 	log.Println("Join command:", command) | ||||||
| 	log.Printf("Running join command for %s\n", t.Hostname) | 	log.Printf("Running join command for %s\n", t.Hostname) | ||||||
| 	_, _, err := dockertestutil.ExecuteCommand( | 	stdout, stderr, err := dockertestutil.ExecuteCommand( | ||||||
| 		t.container, | 		t.container, | ||||||
| 		command, | 		command, | ||||||
| 		[]string{}, | 		[]string{}, | ||||||
| 	) | 	) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
|  | 		log.Printf("tailscale join stderr: %s\n", stderr) | ||||||
|  | 
 | ||||||
| 		return err | 		return err | ||||||
| 	} | 	} | ||||||
|  | 	log.Printf("tailscale join stdout: %s\n", stdout) | ||||||
| 	log.Printf("%s joined\n", t.Hostname) | 	log.Printf("%s joined\n", t.Hostname) | ||||||
| 
 | 
 | ||||||
| 	return nil | 	return nil | ||||||
| @ -123,12 +127,18 @@ func (t *TailscaleInContainer) IPs() ([]netip.Addr, error) { | |||||||
| 		"ip", | 		"ip", | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	result, _, err := dockertestutil.ExecuteCommand( | 	result, stderr, err := dockertestutil.ExecuteCommand( | ||||||
| 		t.container, | 		t.container, | ||||||
| 		command, | 		command, | ||||||
| 		[]string{}, | 		[]string{}, | ||||||
| 	) | 	) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
|  | 		log.Printf("failed commands stderr: %s\n", stderr) | ||||||
|  | 
 | ||||||
|  | 		if strings.Contains(stderr, "NeedsLogin") { | ||||||
|  | 			return []netip.Addr{}, errTailscaleNotLoggedIn | ||||||
|  | 		} | ||||||
|  | 
 | ||||||
| 		return []netip.Addr{}, err | 		return []netip.Addr{}, err | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| @ -165,7 +175,7 @@ func (t *TailscaleInContainer) Ping(ip netip.Addr) error { | |||||||
| 		return err | 		return err | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	if !strings.Contains(result, "pong") { | 	if !strings.Contains(result, "pong") || !strings.Contains(result, "is local") { | ||||||
| 		return errTailscalePingFailed | 		return errTailscalePingFailed | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user