Fix default CPU limit (#163)
This commit is contained in:
parent
94a3563c96
commit
a3002d23bc
|
@ -255,7 +255,9 @@ func (vm *VirtualMachine) Configure(config *HardwareConfig) error {
|
|||
|
||||
var cpuSpec types.ResourceAllocationInfo
|
||||
cpuSpec.Reservation = &config.CPUReservation
|
||||
cpuSpec.Limit = &config.CPULimit
|
||||
if config.CPULimit != 0 {
|
||||
cpuSpec.Limit = &config.CPULimit
|
||||
}
|
||||
confSpec.CpuAllocation = &cpuSpec
|
||||
|
||||
var ramSpec types.ResourceAllocationInfo
|
||||
|
|
|
@ -159,6 +159,40 @@ func checkHardware(t *testing.T) builderT.TestCheckFunc {
|
|||
}
|
||||
}
|
||||
|
||||
func TestISOBuilderAcc_limit(t *testing.T) {
|
||||
builderT.Test(t, builderT.TestCase{
|
||||
Builder: &Builder{},
|
||||
Template: limitConfig(),
|
||||
Check: checkLimit(t),
|
||||
})
|
||||
}
|
||||
|
||||
func limitConfig() string {
|
||||
config := defaultConfig()
|
||||
config["CPUs"] = 1 // hardware is customized, but CPU limit is not specified explicitly
|
||||
|
||||
return commonT.RenderConfig(config)
|
||||
}
|
||||
|
||||
func checkLimit(t *testing.T) builderT.TestCheckFunc {
|
||||
return func(artifacts []packer.Artifact) error {
|
||||
d := commonT.TestConn(t)
|
||||
|
||||
vm := commonT.GetVM(t, d, artifacts)
|
||||
vmInfo, err := vm.Info("config.cpuAllocation")
|
||||
if err != nil {
|
||||
t.Fatalf("Cannot read VM properties: %v", err)
|
||||
}
|
||||
|
||||
limit := *vmInfo.Config.CpuAllocation.Limit
|
||||
if limit != -1 { // must be unlimited
|
||||
t.Errorf("Invalid CPU limit: expected '%v', got '%v'", -1, limit)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func TestISOBuilderAcc_cdrom(t *testing.T) {
|
||||
builderT.Test(t, builderT.TestCase{
|
||||
Builder: &Builder{},
|
||||
|
|
Loading…
Reference in New Issue