Fix default CPU limit (#163)

This commit is contained in:
Michael Kuzmin 2018-10-16 18:59:51 +03:00 committed by GitHub
parent 94a3563c96
commit a3002d23bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 37 additions and 1 deletions

View File

@ -255,7 +255,9 @@ func (vm *VirtualMachine) Configure(config *HardwareConfig) error {
var cpuSpec types.ResourceAllocationInfo
cpuSpec.Reservation = &config.CPUReservation
if config.CPULimit != 0 {
cpuSpec.Limit = &config.CPULimit
}
confSpec.CpuAllocation = &cpuSpec
var ramSpec types.ResourceAllocationInfo

View File

@ -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{},