Skip to content
This repository has been archived by the owner on Mar 8, 2023. It is now read-only.

Commit

Permalink
Fix default CPU limit (#163)
Browse files Browse the repository at this point in the history
  • Loading branch information
mkuzmin authored Oct 16, 2018
1 parent 94a3563 commit a3002d2
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
4 changes: 3 additions & 1 deletion driver/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
34 changes: 34 additions & 0 deletions iso/builder_acc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{},
Expand Down

0 comments on commit a3002d2

Please sign in to comment.