Skip to content
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
33 changes: 24 additions & 9 deletions test/e2e/internal/network/external_connectivity.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,38 @@ package network
import (
"fmt"
"strings"
"time"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

"github.com/deckhouse/virtualization/test/e2e/internal/framework"
)

const (
HTTPStatusOk = "200"
ExternalHost = "https://flant.ru"
)
var ExternalConnectivityHosts = []string{
"https://flant.ru",
"https://google.com",
"https://ya.ru",
}

func CheckExternalConnectivity(f *framework.Framework, vmName, host, expectedHTTPCode string) {
func CheckExternalConnectivity(f *framework.Framework, vmName string, hosts []string) {
GinkgoHelper()

cmd := fmt.Sprintf("curl -o /dev/null -k -s -w \"%%{http_code}\\n\" %s", host)
httpCode, err := f.SSHCommand(vmName, f.Namespace().Name, cmd)
Expect(err).NotTo(HaveOccurred(), "failed external connectivity check for VM %s", vmName)
Expect(strings.TrimSpace(httpCode)).To(Equal(expectedHTTPCode), "HTTP response code from %s should be %s, got %s", host, expectedHTTPCode, httpCode)
cmd := fmt.Sprintf(`set -e
for host in %s; do
if curl --head -k -sS -o /dev/null --connect-timeout 5 --max-time 15 "$host"; then
echo "$host"
exit 0
fi
done
exit 1`, strings.Join(hosts, " "))

reachableHost, err := f.SSHCommand(
vmName,
f.Namespace().Name,
cmd,
framework.WithSSHTimeout(time.Minute),
)
Expect(err).NotTo(HaveOccurred(), "VM %s should have outbound connectivity via at least one host from %v", vmName, hosts)
Expect(strings.TrimSpace(reachableHost)).NotTo(BeEmpty(), "VM %s should report a reachable external host from %v", vmName, hosts)
}
4 changes: 2 additions & 2 deletions test/e2e/vm/additional_network_interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,10 @@ var _ = Describe("VirtualMachineAdditionalNetworkInterfaces", Label(precheck.NoP
})

By("Check VM can reach external network after migration", func() {
network.CheckExternalConnectivity(f, vmFoo.Name, network.ExternalHost, network.HTTPStatusOk)
network.CheckExternalConnectivity(f, vmFoo.Name, network.ExternalConnectivityHosts)

if tc.vmBarHasMainNetwork {
network.CheckExternalConnectivity(f, vmBar.Name, network.ExternalHost, network.HTTPStatusOk)
network.CheckExternalConnectivity(f, vmBar.Name, network.ExternalConnectivityHosts)
}
})

Expand Down
4 changes: 2 additions & 2 deletions test/e2e/vm/connectivity.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ var _ = Describe("VirtualMachineConnectivity", Label(precheck.NoPrecheck), func(
})

By("Check VMs can reach external network", func() {
network.CheckExternalConnectivity(f, t.VMa.Name, network.ExternalHost, network.HTTPStatusOk)
network.CheckExternalConnectivity(f, t.VMb.Name, network.ExternalHost, network.HTTPStatusOk)
network.CheckExternalConnectivity(f, t.VMa.Name, network.ExternalConnectivityHosts)
network.CheckExternalConnectivity(f, t.VMb.Name, network.ExternalConnectivityHosts)
})

By("Check nginx status on VMs", func() {
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/vm/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,8 @@ var _ = Describe("VirtualMachineMigration", Label(precheck.NoPrecheck), func() {
By("Check VM can reach external network", func() {
util.UntilSSHReady(f, vmBIOS, framework.MiddleTimeout)
util.UntilSSHReady(f, vmUEFI, framework.MiddleTimeout)
network.CheckExternalConnectivity(f, vmBIOS.Name, network.ExternalHost, network.HTTPStatusOk)
network.CheckExternalConnectivity(f, vmUEFI.Name, network.ExternalHost, network.HTTPStatusOk)
network.CheckExternalConnectivity(f, vmBIOS.Name, network.ExternalConnectivityHosts)
network.CheckExternalConnectivity(f, vmUEFI.Name, network.ExternalConnectivityHosts)
})
})
})
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/vm/power_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ var _ = Describe("PowerState", Label(precheck.NoPrecheck), func() {
By("Check VM can reach external network", func() {
err := network.CheckCiliumAgents(context.Background(), f.Kubectl(), t.VM.Name, f.Namespace().Name)
Expect(err).NotTo(HaveOccurred(), "Cilium agents check should succeed for VM %s", t.VM.Name)
network.CheckExternalConnectivity(f, t.VM.Name, network.ExternalHost, network.HTTPStatusOk)
network.CheckExternalConnectivity(f, t.VM.Name, network.ExternalConnectivityHosts)
})
},
Entry(
Expand Down
Loading