Skip to content

Commit

Permalink
fix(hatchery): count CPUs using flavor list instead of data from serv…
Browse files Browse the repository at this point in the history
…er (#5254)
  • Loading branch information
richardlt authored Jun 16, 2020
1 parent 069cee4 commit 90ac6a7
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 30 deletions.
6 changes: 5 additions & 1 deletion engine/hatchery/openstack/spawn.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
56 changes: 28 additions & 28 deletions engine/hatchery/openstack/spawn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
1 change: 0 additions & 1 deletion engine/vcs/gerrit/client_pull_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ func (c *gerritClient) PullRequestComment(ctx context.Context, repo string, prRe
}

return nil
return nil
}

// PullRequestCreate create a new pullrequest
Expand Down

0 comments on commit 90ac6a7

Please sign in to comment.