diff --git a/.gitignore b/.gitignore index 4eabc8714c53..c87039d1cb02 100644 --- a/.gitignore +++ b/.gitignore @@ -26,3 +26,4 @@ cluster/local/certs **.crt **.csr _out +vendor/**/*_test.go diff --git a/api/openapi-spec/swagger.json b/api/openapi-spec/swagger.json index 417bdd8440b0..acbb6a4f3472 100644 --- a/api/openapi-spec/swagger.json +++ b/api/openapi-spec/swagger.json @@ -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": { @@ -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": { @@ -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": { diff --git a/pkg/api/v1/defaults.go b/pkg/api/v1/defaults.go index 7c1c8ca93d53..ca81fe3c8938 100644 --- a/pkg/api/v1/defaults.go +++ b/pkg/api/v1/defaults.go @@ -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) } diff --git a/pkg/api/v1/schema_swagger_generated.go b/pkg/api/v1/schema_swagger_generated.go index d775ab90934a..18b60e108a39 100644 --- a/pkg/api/v1/schema_swagger_generated.go +++ b/pkg/api/v1/schema_swagger_generated.go @@ -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", } } @@ -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", } diff --git a/pkg/virt-launcher/virtwrap/util/libvirt_helper.go b/pkg/virt-launcher/virtwrap/util/libvirt_helper.go index a4e1b76a6c84..fb45eabb9f26 100644 --- a/pkg/virt-launcher/virtwrap/util/libvirt_helper.go +++ b/pkg/virt-launcher/virtwrap/util/libvirt_helper.go @@ -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.") diff --git a/tests/utils.go b/tests/utils.go index 34180ae1407d..a761b9c3c446 100644 --- a/tests/utils.go +++ b/tests/utils.go @@ -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) diff --git a/tests/vm_configuration_test.go b/tests/vm_configuration_test.go index 41891b7cfc79..48848046a9e9 100644 --- a/tests/vm_configuration_test.go +++ b/tests/vm_configuration_test.go @@ -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()) @@ -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())