@@ -19,23 +19,38 @@ package network
1919import (
2020 "fmt"
2121 "strings"
22+ "time"
2223
2324 . "github.com/onsi/ginkgo/v2"
2425 . "github.com/onsi/gomega"
2526
2627 "github.com/deckhouse/virtualization/test/e2e/internal/framework"
2728)
2829
29- const (
30- HTTPStatusOk = "200"
31- ExternalHost = "https://flant.ru"
32- )
30+ var ExternalConnectivityHosts = []string {
31+ "https://flant.ru" ,
32+ "https://google.com" ,
33+ "https://ya.ru" ,
34+ }
3335
34- func CheckExternalConnectivity (f * framework.Framework , vmName , host , expectedHTTPCode string ) {
36+ func CheckExternalConnectivity (f * framework.Framework , vmName string , hosts [] string ) {
3537 GinkgoHelper ()
3638
37- cmd := fmt .Sprintf ("curl -o /dev/null -k -s -w \" %%{http_code}\\ n\" %s" , host )
38- httpCode , err := f .SSHCommand (vmName , f .Namespace ().Name , cmd )
39- Expect (err ).NotTo (HaveOccurred (), "failed external connectivity check for VM %s" , vmName )
40- Expect (strings .TrimSpace (httpCode )).To (Equal (expectedHTTPCode ), "HTTP response code from %s should be %s, got %s" , host , expectedHTTPCode , httpCode )
39+ cmd := fmt .Sprintf (`set -e
40+ for host in %s; do
41+ if curl --head -k -sS -o /dev/null --connect-timeout 5 --max-time 15 "$host"; then
42+ echo "$host"
43+ exit 0
44+ fi
45+ done
46+ exit 1` , strings .Join (hosts , " " ))
47+
48+ reachableHost , err := f .SSHCommand (
49+ vmName ,
50+ f .Namespace ().Name ,
51+ cmd ,
52+ framework .WithSSHTimeout (time .Minute ),
53+ )
54+ Expect (err ).NotTo (HaveOccurred (), "VM %s should have outbound connectivity via at least one host from %v" , vmName , hosts )
55+ Expect (strings .TrimSpace (reachableHost )).NotTo (BeEmpty (), "VM %s should report a reachable external host from %v" , vmName , hosts )
4156}
0 commit comments