Skip to content

Commit

Permalink
Merge pull request kubevirt#1124 from booxter/implicit-interfaces-fun…
Browse files Browse the repository at this point in the history
…ctest

Added integration networking test for implicit pod network definition
  • Loading branch information
vladikr authored Jun 14, 2018
2 parents a4675b5 + 41fc924 commit ff9af14
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 35 deletions.
4 changes: 2 additions & 2 deletions pkg/api/v1/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func SetDefaults_VirtualMachineInstance(obj *VirtualMachineInstance) {
obj.Spec.Domain.Machine.Type = "q35"
}
setDefaults_DiskFromMachineType(obj)
setDefaults_NetworkInterface(obj)
SetDefaults_NetworkInterface(obj)
}

func setDefaults_DiskFromMachineType(obj *VirtualMachineInstance) {
Expand All @@ -152,7 +152,7 @@ func setDefaults_DiskFromMachineType(obj *VirtualMachineInstance) {
}
}

func setDefaults_NetworkInterface(obj *VirtualMachineInstance) {
func SetDefaults_NetworkInterface(obj *VirtualMachineInstance) {
networks := obj.Spec.Networks

//TODO: Currently, we support only one interface associated to a network
Expand Down
100 changes: 67 additions & 33 deletions tests/vmi_networking_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ var _ = Describe("Networking", func() {

var inboundVMI *v1.VirtualMachineInstance
var outboundVMI *v1.VirtualMachineInstance
var inboundVMI_podnet *v1.VirtualMachineInstance
var outboundVMI_podnet *v1.VirtualMachineInstance

const testPort = 1500

Expand Down Expand Up @@ -97,48 +99,73 @@ var _ = Describe("Networking", func() {
tests.BeforeAll(func() {
tests.BeforeTestCleanup()

// Create and start inbound VirtualMachineInstance
inboundVMI = tests.NewRandomVMIWithEphemeralDiskAndUserdata(tests.RegistryDiskFor(tests.RegistryDiskCirros), "#!/bin/bash\necho 'hello'\n")
inboundVMI.Labels = map[string]string{"expose": "me"}
inboundVMI.Spec.Subdomain = "myvmi"
inboundVMI.Spec.Hostname = "my-subdomain"
_, err = virtClient.VirtualMachineInstance(tests.NamespaceTestDefault).Create(inboundVMI)
Expect(err).ToNot(HaveOccurred())
prepareVMIs := func(withPodNetwork bool) (*v1.VirtualMachineInstance, *v1.VirtualMachineInstance) {
// Prepare inbound and outbound VMI definitions
inboundVMI := tests.NewRandomVMIWithEphemeralDiskAndUserdata(tests.RegistryDiskFor(tests.RegistryDiskCirros), "#!/bin/bash\necho 'hello'\n")
inboundVMI.Labels = map[string]string{"expose": "me"}
inboundVMI.Spec.Subdomain = "myvmi"
inboundVMI.Spec.Hostname = "my-subdomain"
outboundVMI := tests.NewRandomVMIWithEphemeralDiskAndUserdata(tests.RegistryDiskFor(tests.RegistryDiskCirros), "#!/bin/bash\necho 'hello'\n")

if withPodNetwork {
v1.SetDefaults_NetworkInterface(inboundVMI)
v1.SetDefaults_NetworkInterface(outboundVMI)
for _, networkVMI := range []*v1.VirtualMachineInstance{inboundVMI, outboundVMI} {
Expect(networkVMI.Spec.Domain.Devices.Interfaces).ToNot(BeZero())
Expect(networkVMI.Spec.Networks).ToNot(BeZero())
}
} else {
for _, networkVMI := range []*v1.VirtualMachineInstance{inboundVMI, outboundVMI} {
Expect(networkVMI.Spec.Domain.Devices.Interfaces).To(BeZero())
Expect(networkVMI.Spec.Networks).To(BeZero())
}
}

// Create and start outbound VirtualMachineInstance
outboundVMI = tests.NewRandomVMIWithEphemeralDiskAndUserdata(tests.RegistryDiskFor(tests.RegistryDiskCirros), "#!/bin/bash\necho 'hello'\n")
_, err = virtClient.VirtualMachineInstance(tests.NamespaceTestDefault).Create(outboundVMI)
Expect(err).ToNot(HaveOccurred())
// Create and start VMIs
_, err = virtClient.VirtualMachineInstance(tests.NamespaceTestDefault).Create(inboundVMI)
Expect(err).ToNot(HaveOccurred())

for _, networkVMI := range []*v1.VirtualMachineInstance{inboundVMI, outboundVMI} {
waitUntilVMIReady(networkVMI, tests.LoggedInCirrosExpecter)
}
_, err = virtClient.VirtualMachineInstance(tests.NamespaceTestDefault).Create(outboundVMI)
Expect(err).ToNot(HaveOccurred())

inboundVMI, err = virtClient.VirtualMachineInstance(tests.NamespaceTestDefault).Get(inboundVMI.Name, &v13.GetOptions{})
Expect(err).ToNot(HaveOccurred())
expecter, _, err := tests.NewConsoleExpecter(virtClient, inboundVMI, 10*time.Second)
Expect(err).ToNot(HaveOccurred())
defer expecter.Close()
resp, err := expecter.ExpectBatch([]expect.Batcher{
&expect.BSnd{S: "\n"},
&expect.BExp{R: "\\$ "},
&expect.BSnd{S: "screen -d -m nc -klp 1500 -e echo -e \"Hello World!\"\n"},
&expect.BExp{R: "\\$ "},
&expect.BSnd{S: "echo $?\n"},
&expect.BExp{R: "0"},
}, 60*time.Second)
log.DefaultLogger().Infof("%v", resp)
Expect(err).ToNot(HaveOccurred())
for _, networkVMI := range []*v1.VirtualMachineInstance{inboundVMI, outboundVMI} {
waitUntilVMIReady(networkVMI, tests.LoggedInCirrosExpecter)
}

outboundVMI, err = virtClient.VirtualMachineInstance(tests.NamespaceTestDefault).Get(outboundVMI.Name, &v13.GetOptions{})
Expect(err).ToNot(HaveOccurred())
})
inboundVMI, err = virtClient.VirtualMachineInstance(tests.NamespaceTestDefault).Get(inboundVMI.Name, &v13.GetOptions{})
Expect(err).ToNot(HaveOccurred())
expecter, _, err := tests.NewConsoleExpecter(virtClient, inboundVMI, 10*time.Second)
Expect(err).ToNot(HaveOccurred())
defer expecter.Close()
resp, err := expecter.ExpectBatch([]expect.Batcher{
&expect.BSnd{S: "\n"},
&expect.BExp{R: "\\$ "},
&expect.BSnd{S: "screen -d -m nc -klp 1500 -e echo -e \"Hello World!\"\n"},
&expect.BExp{R: "\\$ "},
&expect.BSnd{S: "echo $?\n"},
&expect.BExp{R: "0"},
}, 60*time.Second)
log.DefaultLogger().Infof("%v", resp)
Expect(err).ToNot(HaveOccurred())

Context("VirtualMachineInstance attached to the pod network", func() {
outboundVMI, err = virtClient.VirtualMachineInstance(tests.NamespaceTestDefault).Get(outboundVMI.Name, &v13.GetOptions{})
Expect(err).ToNot(HaveOccurred())

return inboundVMI, outboundVMI
}

inboundVMI, outboundVMI = prepareVMIs(false)
// same but with explicit pod network definition
inboundVMI_podnet, outboundVMI_podnet = prepareVMIs(true)
})

declareConnectivityCases := func(inboundVMIRef **v1.VirtualMachineInstance, outboundVMIRef **v1.VirtualMachineInstance) {
table.DescribeTable("should be able to reach", func(destination string) {
var cmdCheck, addrShow, addr string

inboundVMI := *inboundVMIRef
outboundVMI := *outboundVMIRef

// assuming pod network is of standard MTU = 1500 (minus 50 bytes for vxlan overhead)
expectedMtu := 1450
ipHeaderSize := 28 // IPv4 specific
Expand Down Expand Up @@ -331,6 +358,13 @@ var _ = Describe("Networking", func() {
Expect(virtClient.CoreV1().Services(inboundVMI.Namespace).Delete(inboundVMI.Spec.Subdomain, &v13.DeleteOptions{})).To(Succeed())
})
})
}

Context("VirtualMachineInstance attached to implicit pod network", func() {
declareConnectivityCases(&inboundVMI, &outboundVMI)
})
Context("VirtualMachineInstance attached to explicit pod network", func() {
declareConnectivityCases(&inboundVMI_podnet, &outboundVMI_podnet)
})

checkNetworkVendor := func(vmi *v1.VirtualMachineInstance, expectedVendor string, prompt string) {
Expand Down

0 comments on commit ff9af14

Please sign in to comment.