Skip to content

Commit

Permalink
Fix machine type defaulting and disks test
Browse files Browse the repository at this point in the history
Signed-off-by: Roman Mohr <[email protected]>
  • Loading branch information
rmohr committed Feb 12, 2018
1 parent 82760cd commit e83838f
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 19 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ cluster/local/certs
**.crt
**.csr
_out
vendor/**/*_test.go
6 changes: 3 additions & 3 deletions api/openapi-spec/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -1628,7 +1628,7 @@
"v1.CDRomTarget": {
"properties": {
"bus": {
"description": "Bus indicates the type of disk device to emulate.\nsupported values: virtio, sata, scsi, ide\nsee libvirt schema here:\nhttps://github.com/libvirt/libvirt/blob/v3.7-maint/docs/schemas/domaincommon.rng#L1693",
"description": "Bus indicates the type of disk device to emulate.\nsupported values: virtio, sata, scsi, ide",
"type": "string"
},
"readonly": {
Expand Down Expand Up @@ -1775,7 +1775,7 @@
"v1.DiskTarget": {
"properties": {
"bus": {
"description": "Bus indicates the type of disk device to emulate.\nsupported values: virtio, sata, scsi, ide\nsee libvirt schema here:\nhttps://github.com/libvirt/libvirt/blob/v3.7-maint/docs/schemas/domaincommon.rng#L1693",
"description": "Bus indicates the type of disk device to emulate.\nsupported values: virtio, sata, scsi, ide",
"type": "string"
},
"readonly": {
Expand Down Expand Up @@ -2148,7 +2148,7 @@
"v1.LunTarget": {
"properties": {
"bus": {
"description": "Bus indicates the type of disk device to emulate.\nsupported values: virtio, sata, scsi, ide\nsee libvirt schema here:\nhttps://github.com/libvirt/libvirt/blob/v3.7-maint/docs/schemas/domaincommon.rng#L1693",
"description": "Bus indicates the type of disk device to emulate.\nsupported values: virtio, sata, scsi, ide",
"type": "string"
},
"readonly": {
Expand Down
4 changes: 3 additions & 1 deletion pkg/api/v1/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,9 @@ func SetDefaults_VirtualMachine(obj *VirtualMachine) {
if obj.Spec.Domain.Features == nil {
obj.Spec.Domain.Features = &Features{}
}
obj.Spec.Domain.Machine.Type = "q35"
if obj.Spec.Domain.Machine.Type == "" {
obj.Spec.Domain.Machine.Type = "q35"
}
setDefaults_DiskFromMachineType(obj)
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/api/v1/schema_swagger_generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,14 @@ func (DiskDevice) SwaggerDoc() map[string]string {

func (DiskTarget) SwaggerDoc() map[string]string {
return map[string]string{
"bus": "Bus indicates the type of disk device to emulate.\nsupported values: virtio, sata, scsi, ide\nsee libvirt schema here:\nhttps://github.com/libvirt/libvirt/blob/v3.7-maint/docs/schemas/domaincommon.rng#L1693",
"bus": "Bus indicates the type of disk device to emulate.\nsupported values: virtio, sata, scsi, ide",
"readonly": "ReadOnly\nDefaults to false",
}
}

func (LunTarget) SwaggerDoc() map[string]string {
return map[string]string{
"bus": "Bus indicates the type of disk device to emulate.\nsupported values: virtio, sata, scsi, ide\nsee libvirt schema here:\nhttps://github.com/libvirt/libvirt/blob/v3.7-maint/docs/schemas/domaincommon.rng#L1693",
"bus": "Bus indicates the type of disk device to emulate.\nsupported values: virtio, sata, scsi, ide",
"readonly": "ReadOnly\nDefaults to false",
}
}
Expand All @@ -95,7 +95,7 @@ func (FloppyTarget) SwaggerDoc() map[string]string {

func (CDRomTarget) SwaggerDoc() map[string]string {
return map[string]string{
"bus": "Bus indicates the type of disk device to emulate.\nsupported values: virtio, sata, scsi, ide\nsee libvirt schema here:\nhttps://github.com/libvirt/libvirt/blob/v3.7-maint/docs/schemas/domaincommon.rng#L1693",
"bus": "Bus indicates the type of disk device to emulate.\nsupported values: virtio, sata, scsi, ide",
"readonly": "ReadOnly\nDefaults to true",
"tray": "Tray indicates if the tray of the device is open or closed.\nAllowed values are \"open\" and \"closed\"\nDefaults to closed\n+optional",
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/virt-launcher/virtwrap/util/libvirt_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func SetDomainSpec(virConn cli.Connection, vm *v1.VirtualMachine, wantedSpec api
log.Log.Object(vm).Reason(err).Error("Generating the domain XML failed.")
return nil, err
}
log.Log.Object(vm).V(3).With("xml", xmlStr).Info("Domain XML generated.")
log.Log.Object(vm).V(3).With("xml", string(xmlStr)).Info("Domain XML generated.")
dom, err := virConn.DomainDefineXML(string(xmlStr))
if err != nil {
log.Log.Object(vm).Reason(err).Error("Defining the VM failed.")
Expand Down
20 changes: 20 additions & 0 deletions tests/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,26 @@ func AddEphemeralDisk(vm *v1.VirtualMachine, name string, bus string, image stri
return vm
}

func AddEphemeralFloppy(vm *v1.VirtualMachine, name string, image string) *v1.VirtualMachine {
vm.Spec.Domain.Devices.Disks = append(vm.Spec.Domain.Devices.Disks, v1.Disk{
Name: name,
VolumeName: name,
DiskDevice: v1.DiskDevice{
Floppy: &v1.FloppyTarget{},
},
})
vm.Spec.Volumes = append(vm.Spec.Volumes, v1.Volume{
Name: name,
VolumeSource: v1.VolumeSource{
RegistryDisk: &v1.RegistryDiskSource{
Image: image,
},
},
})

return vm
}

func NewRandomVMWithEphemeralDiskAndUserdata(containerImage string, userData string) *v1.VirtualMachine {
vm := NewRandomVMWithEphemeralDisk(containerImage)

Expand Down
30 changes: 19 additions & 11 deletions tests/vm_configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,17 +152,23 @@ var _ = Describe("Configurations", func() {

BeforeEach(func() {
// ordering:
// virtio - added by NewRandomVMWithEphemeralDisk
// use a small disk for the other ones
containerImage := "kubevirt/cirros-registry-disk-demo:devel"
vm = tests.NewRandomVMWithEphemeralDisk(containerImage)
// virtio - added by NewRandomVMWithEphemeralDisk
vm = tests.NewRandomVMWithEphemeralDiskAndUserdata(containerImage, "echo hi!\n")
// sata
tests.AddEphemeralDisk(vm, "disk1", "sata", containerImage)
tests.AddEphemeralDisk(vm, "disk2", "sata", containerImage)
// ide
tests.AddEphemeralDisk(vm, "disk2", "ide", containerImage)
tests.AddEphemeralDisk(vm, "disk3", "ide", containerImage)
// floppy
tests.AddEphemeralDisk(vm, "disk3", "floppy", containerImage)
tests.AddEphemeralFloppy(vm, "disk4", containerImage)
// NOTE: we have one disk per bus, so we expect vda, sda, hda, fda

// We need ide support for the test, q35 does not support ide
vm.Spec.Domain.Machine.Type = "pc"
})

// FIXME ide and floppy is not recognized by the used image right now
It("should have all the device nodes", func() {
vm, err = virtClient.VM(tests.NamespaceTestDefault).Create(vm)
Expect(err).ToNot(HaveOccurred())
Expand All @@ -172,14 +178,16 @@ var _ = Describe("Configurations", func() {
Expect(err).ToNot(HaveOccurred())
defer expecter.Close()
_, err = expecter.ExpectBatch([]expect.Batcher{
&expect.BExp{R: "Welcome to Alpine"},
&expect.BExp{R: "login as 'cirros' user. default password: 'gocubsgo'. use 'sudo' for root."},
&expect.BSnd{S: "\n"},
&expect.BExp{R: "login"},
&expect.BSnd{S: "root\n"},
&expect.BExp{R: "#"},
&expect.BExp{R: "cirros login:"},
&expect.BSnd{S: "cirros\n"},
&expect.BExp{R: "Password:"},
&expect.BSnd{S: "gocubsgo\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"},
&expect.BSnd{S: "ls /dev/sda /dev/vda /dev/vdb\n"},
&expect.BExp{R: "/dev/sda /dev/vda /dev/vdb"},
}, 150*time.Second)

Expect(err).ToNot(HaveOccurred())
Expand Down

0 comments on commit e83838f

Please sign in to comment.