Skip to content

Commit

Permalink
Merge pull request kubevirt#1269 from cynepco3hahue/cpu_model_small_f…
Browse files Browse the repository at this point in the history
…ixes

Set host-model CPU mode when CPU spec defined but model not
  • Loading branch information
Artyom Lukianov authored Jul 4, 2018
2 parents fff9fda + 609d8e2 commit b5b9124
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
4 changes: 3 additions & 1 deletion pkg/virt-launcher/virtwrap/api/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,9 @@ func Convert_v1_VirtualMachine_To_api_Domain(vmi *v1.VirtualMachineInstance, dom
domain.Spec.CPU.Mode = "custom"
domain.Spec.CPU.Model = vmi.Spec.Domain.CPU.Model
}
} else {
}

if vmi.Spec.Domain.CPU == nil || vmi.Spec.Domain.CPU.Model == "" {
domain.Spec.CPU.Mode = "host-model"
}

Expand Down
21 changes: 21 additions & 0 deletions pkg/virt-launcher/virtwrap/api/converter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,27 @@ var _ = Describe("Converter", func() {
Expect(domainSpec.VCPU.CPUs).To(Equal(uint32(3)))
})

Context("when CPU spec defined and model not", func() {
It("should set host-model CPU mode", func() {
v1.SetObjectDefaults_VirtualMachineInstance(vmi)
vmi.Spec.Domain.CPU = &v1.CPU{
Cores: 3,
}
domainSpec := vmiToDomainXMLToDomainSpec(vmi, c)

Expect(domainSpec.CPU.Mode).To(Equal("host-model"))
})
})

Context("when CPU spec not defined", func() {
It("should set host-model CPU mode", func() {
v1.SetObjectDefaults_VirtualMachineInstance(vmi)
domainSpec := vmiToDomainXMLToDomainSpec(vmi, c)

Expect(domainSpec.CPU.Mode).To(Equal("host-model"))
})
})

It("should select explicitly chosen network model", func() {
v1.SetObjectDefaults_VirtualMachineInstance(vmi)
vmi.Spec.Domain.Devices.Interfaces[0].Model = "e1000"
Expand Down
6 changes: 3 additions & 3 deletions tests/vmi_configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,8 @@ var _ = Describe("Configurations", func() {
}
})

Context("when CPU model definied", func() {
It("should report definied CPU model", func() {
Context("when CPU model defined", func() {
It("should report defined CPU model", func() {
vmiModel := "Conroe"
if cpuVendor == "AMD" {
vmiModel = "Opteron_G1"
Expand All @@ -302,7 +302,7 @@ var _ = Describe("Configurations", func() {
})
})

Context("when CPU model not definied", func() {
Context("when CPU model not defined", func() {
It("should report CPU model from libvirt capabilities", func() {
By("Starting a VirtualMachineInstance")
_, err = virtClient.VirtualMachineInstance(tests.NamespaceTestDefault).Create(cpuVmi)
Expand Down

0 comments on commit b5b9124

Please sign in to comment.