Skip to content

Commit

Permalink
tests: add test exercising every supported bus type
Browse files Browse the repository at this point in the history
  • Loading branch information
ffromani authored and rmohr committed Feb 12, 2018
1 parent b9fcb92 commit 5141e2b
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 5 deletions.
16 changes: 11 additions & 5 deletions tests/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -522,23 +522,29 @@ func NewRandomVMWithEphemeralDisk(containerImage string) *v1.VirtualMachine {
vm := NewRandomVM()

vm.Spec.Domain.Resources.Requests[k8sv1.ResourceMemory] = resource.MustParse("64M")
AddEphemeralDisk(vm, "disk0", "virtio", containerImage)
return vm
}

func AddEphemeralDisk(vm *v1.VirtualMachine, name string, bus string, image string) *v1.VirtualMachine {
vm.Spec.Domain.Devices.Disks = append(vm.Spec.Domain.Devices.Disks, v1.Disk{
Name: "disk0",
VolumeName: "disk0",
Name: name,
VolumeName: name,
DiskDevice: v1.DiskDevice{
Disk: &v1.DiskTarget{
Bus: "virtio",
Bus: bus,
},
},
})
vm.Spec.Volumes = append(vm.Spec.Volumes, v1.Volume{
Name: "disk0",
Name: name,
VolumeSource: v1.VolumeSource{
RegistryDisk: &v1.RegistryDiskSource{
Image: containerImage,
Image: image,
},
},
})

return vm
}

Expand Down
40 changes: 40 additions & 0 deletions tests/vm_configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,44 @@ var _ = Describe("Configurations", func() {
})
})

Context("New VM with all supported drives", func() {

var vm *v1.VirtualMachine

BeforeEach(func() {
// ordering:
// virtio - added by NewRandomVMWithEphemeralDisk
containerImage := "kubevirt/cirros-registry-disk-demo:devel"
vm = tests.NewRandomVMWithEphemeralDisk(containerImage)
// sata
tests.AddEphemeralDisk(vm, "disk1", "sata", containerImage)
// ide
tests.AddEphemeralDisk(vm, "disk2", "ide", containerImage)
// floppy
tests.AddEphemeralDisk(vm, "disk3", "floppy", containerImage)
// NOTE: we have one disk per bus, so we expect vda, sda, hda, fda
})
It("should have all the device nodes", func() {
vm, err = virtClient.VM(tests.NamespaceTestDefault).Create(vm)
Expect(err).ToNot(HaveOccurred())
tests.WaitForSuccessfulVMStart(vm)

expecter, _, err := tests.NewConsoleExpecter(virtClient, vm, "serial0", 10*time.Second)
Expect(err).ToNot(HaveOccurred())
defer expecter.Close()
_, err = expecter.ExpectBatch([]expect.Batcher{
&expect.BExp{R: "Welcome to Alpine"},
&expect.BSnd{S: "\n"},
&expect.BExp{R: "login"},
&expect.BSnd{S: "root\n"},
&expect.BExp{R: "#"},
// keep the ordering!
&expect.BSnd{S: "ls /dev/fda /dev/hda /dev/sda /dev/vda\n"},
&expect.BExp{R: "/dev/fda /dev/hda /dev/sda /dev/vda"},
}, 150*time.Second)

Expect(err).ToNot(HaveOccurred())
})
})

})

0 comments on commit 5141e2b

Please sign in to comment.