diff --git a/engine/hatchery/openstack/spawn.go b/engine/hatchery/openstack/spawn.go index 833b1cd1b9..4d12be71f4 100644 --- a/engine/hatchery/openstack/spawn.go +++ b/engine/hatchery/openstack/spawn.go @@ -168,7 +168,11 @@ func (h *HatcheryOpenstack) checkSpawnLimits(ctx context.Context, model sdk.Mode var totalCPUsUsed int if h.Config.MaxCPUs > 0 { for i := range existingServers { - totalCPUsUsed += existingServers[i].Flavor["vcpus"].(int) + flavorName, _ := existingServers[i].Metadata["flavor"] + flavor, err := h.flavor(flavorName) + if err == nil { + totalCPUsUsed += flavor.VCPUs + } } if totalCPUsUsed+flavor.VCPUs > h.Config.MaxCPUs { return sdk.WithStack(fmt.Errorf("MaxCPUs limit (%d) reached", h.Config.MaxCPUs)) diff --git a/engine/hatchery/openstack/spawn_test.go b/engine/hatchery/openstack/spawn_test.go index 41a11d4a27..0c48a995b5 100644 --- a/engine/hatchery/openstack/spawn_test.go +++ b/engine/hatchery/openstack/spawn_test.go @@ -30,17 +30,17 @@ func TestHatcheryOpenstack_checkSpawnLimits_MaxWorker(t *testing.T) { } lservers.list = []servers.Server{ - {Flavor: map[string]interface{}{"vcpus": 8}}, - {Flavor: map[string]interface{}{"vcpus": 16}}, + {Metadata: map[string]string{"flavor": "b2-30"}}, + {Metadata: map[string]string{"flavor": "b2-60"}}, } err := h.checkSpawnLimits(context.TODO(), m) require.NoError(t, err) lservers.list = []servers.Server{ - {Flavor: map[string]interface{}{"vcpus": 8}}, - {Flavor: map[string]interface{}{"vcpus": 16}}, - {Flavor: map[string]interface{}{"vcpus": 32}}, + {Metadata: map[string]string{"flavor": "b2-30"}}, + {Metadata: map[string]string{"flavor": "b2-60"}}, + {Metadata: map[string]string{"flavor": "b2-120"}}, } err = h.checkSpawnLimits(context.TODO(), m) @@ -55,28 +55,28 @@ func TestHatcheryOpenstack_checkSpawnLimits_MaxCPUs(t *testing.T) { h.Config.Provision.MaxWorker = 10 h.Config.MaxCPUs = 6 h.flavors = []flavors.Flavor{ - {Name: "my-flavor", VCPUs: 2}, + {Name: "b2-7", VCPUs: 2}, } m := sdk.Model{ ID: 1, Name: "my-model", Group: &sdk.Group{ID: 1, Name: "my-group"}, - ModelVirtualMachine: sdk.ModelVirtualMachine{Flavor: "my-flavor"}, + ModelVirtualMachine: sdk.ModelVirtualMachine{Flavor: "b2-7"}, } lservers.list = []servers.Server{ - {Flavor: map[string]interface{}{"vcpus": 2}}, - {Flavor: map[string]interface{}{"vcpus": 2}}, + {Metadata: map[string]string{"flavor": "b2-7"}}, + {Metadata: map[string]string{"flavor": "b2-7"}}, } err := h.checkSpawnLimits(context.TODO(), m) require.NoError(t, err) lservers.list = []servers.Server{ - {Flavor: map[string]interface{}{"vcpus": 2}}, - {Flavor: map[string]interface{}{"vcpus": 2}}, - {Flavor: map[string]interface{}{"vcpus": 2}}, + {Metadata: map[string]string{"flavor": "b2-7"}}, + {Metadata: map[string]string{"flavor": "b2-7"}}, + {Metadata: map[string]string{"flavor": "b2-7"}}, } err = h.checkSpawnLimits(context.TODO(), m) @@ -117,15 +117,15 @@ func TestHatcheryOpenstack_checkSpawnLimits_CountSmallerFlavorToKeep(t *testing. } lservers.list = []servers.Server{ - {Flavor: map[string]interface{}{"vcpus": 8}}, + {Metadata: map[string]string{"flavor": "b2-30"}}, } err := h.checkSpawnLimits(context.TODO(), m3) require.NoError(t, err, "22 CPUs left (30-8) should be enough to start 8 CPUs flavor (8+4*2=16)") lservers.list = []servers.Server{ - {Flavor: map[string]interface{}{"vcpus": 8}}, - {Flavor: map[string]interface{}{"vcpus": 8}}, + {Metadata: map[string]string{"flavor": "b2-30"}}, + {Metadata: map[string]string{"flavor": "b2-30"}}, } err = h.checkSpawnLimits(context.TODO(), m3) @@ -136,25 +136,25 @@ func TestHatcheryOpenstack_checkSpawnLimits_CountSmallerFlavorToKeep(t *testing. require.NoError(t, err, "14 CPUs left (30-8*2) should be enough to start 4 CPUs flavor (4+2*2=8)") lservers.list = []servers.Server{ - {Flavor: map[string]interface{}{"vcpus": 8}}, - {Flavor: map[string]interface{}{"vcpus": 8}}, - {Flavor: map[string]interface{}{"vcpus": 4}}, - {Flavor: map[string]interface{}{"vcpus": 4}}, - {Flavor: map[string]interface{}{"vcpus": 2}}, - {Flavor: map[string]interface{}{"vcpus": 2}}, + {Metadata: map[string]string{"flavor": "b2-30"}}, + {Metadata: map[string]string{"flavor": "b2-30"}}, + {Metadata: map[string]string{"flavor": "b2-15"}}, + {Metadata: map[string]string{"flavor": "b2-15"}}, + {Metadata: map[string]string{"flavor": "b2-7"}}, + {Metadata: map[string]string{"flavor": "b2-7"}}, } err = h.checkSpawnLimits(context.TODO(), m1) require.NoError(t, err, "2 CPUs left (30-8*2-4*2-2*2) should be enough to start the smallest flavor with 2 CPUs") lservers.list = []servers.Server{ - {Flavor: map[string]interface{}{"vcpus": 8}}, - {Flavor: map[string]interface{}{"vcpus": 8}}, - {Flavor: map[string]interface{}{"vcpus": 4}}, - {Flavor: map[string]interface{}{"vcpus": 4}}, - {Flavor: map[string]interface{}{"vcpus": 2}}, - {Flavor: map[string]interface{}{"vcpus": 2}}, - {Flavor: map[string]interface{}{"vcpus": 2}}, + {Metadata: map[string]string{"flavor": "b2-30"}}, + {Metadata: map[string]string{"flavor": "b2-30"}}, + {Metadata: map[string]string{"flavor": "b2-15"}}, + {Metadata: map[string]string{"flavor": "b2-15"}}, + {Metadata: map[string]string{"flavor": "b2-7"}}, + {Metadata: map[string]string{"flavor": "b2-7"}}, + {Metadata: map[string]string{"flavor": "b2-7"}}, } err = h.checkSpawnLimits(context.TODO(), m1) diff --git a/engine/vcs/gerrit/client_pull_request.go b/engine/vcs/gerrit/client_pull_request.go index 11e0a151f1..929650ed18 100644 --- a/engine/vcs/gerrit/client_pull_request.go +++ b/engine/vcs/gerrit/client_pull_request.go @@ -36,7 +36,6 @@ func (c *gerritClient) PullRequestComment(ctx context.Context, repo string, prRe } return nil - return nil } // PullRequestCreate create a new pullrequest