1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
8 "git.curoverse.com/arvados.git/sdk/go/arvados"
9 check "gopkg.in/check.v1"
12 var _ = check.Suite(&NodeSizeSuite{})
14 const GiB = int64(1 << 30)
16 type NodeSizeSuite struct{}
18 func (*NodeSizeSuite) TestChooseNotConfigured(c *check.C) {
19 _, err := ChooseInstanceType(&arvados.Cluster{}, &arvados.Container{
20 RuntimeConstraints: arvados.RuntimeConstraints{
25 c.Check(err, check.Equals, ErrInstanceTypesNotConfigured)
28 func (*NodeSizeSuite) TestChooseUnsatisfiable(c *check.C) {
29 checkUnsatisfiable := func(ctr *arvados.Container) {
30 _, err := ChooseInstanceType(&arvados.Cluster{InstanceTypes: []arvados.InstanceType{
31 {Price: 1.1, RAM: 1000000000, VCPUs: 2, Name: "small1"},
32 {Price: 2.2, RAM: 2000000000, VCPUs: 4, Name: "small2"},
33 {Price: 4.4, RAM: 4000000000, VCPUs: 8, Name: "small4", Scratch: GiB},
35 c.Check(err, check.Equals, ErrConstraintsNotSatisfiable)
38 for _, rc := range []arvados.RuntimeConstraints{
39 {RAM: 9876543210, VCPUs: 2},
40 {RAM: 1234567890, VCPUs: 20},
41 {RAM: 1234567890, VCPUs: 2, KeepCacheRAM: 9876543210},
43 checkUnsatisfiable(&arvados.Container{RuntimeConstraints: rc})
45 checkUnsatisfiable(&arvados.Container{
46 Mounts: map[string]arvados.Mount{"/tmp": {Kind: "tmp", Capacity: 2 * GiB}},
47 RuntimeConstraints: arvados.RuntimeConstraints{RAM: 12345, VCPUs: 1},
51 func (*NodeSizeSuite) TestChoose(c *check.C) {
52 for _, menu := range [][]arvados.InstanceType{
54 {Price: 4.4, RAM: 4000000000, VCPUs: 8, Scratch: 2 * GiB, Name: "costly"},
55 {Price: 2.2, RAM: 2000000000, VCPUs: 4, Scratch: 2 * GiB, Name: "best"},
56 {Price: 1.1, RAM: 1000000000, VCPUs: 2, Scratch: 2 * GiB, Name: "small"},
59 {Price: 4.4, RAM: 4000000000, VCPUs: 8, Scratch: 2 * GiB, Name: "costly"},
60 {Price: 2.2, RAM: 2000000000, VCPUs: 4, Scratch: 2 * GiB, Name: "goodenough"},
61 {Price: 2.2, RAM: 4000000000, VCPUs: 4, Scratch: 2 * GiB, Name: "best"},
62 {Price: 1.1, RAM: 1000000000, VCPUs: 2, Scratch: 2 * GiB, Name: "small"},
65 {Price: 1.1, RAM: 1000000000, VCPUs: 2, Scratch: 2 * GiB, Name: "small"},
66 {Price: 2.2, RAM: 2000000000, VCPUs: 4, Scratch: 2 * GiB, Name: "goodenough"},
67 {Price: 2.2, RAM: 4000000000, VCPUs: 4, Scratch: 2 * GiB, Name: "best"},
68 {Price: 4.4, RAM: 4000000000, VCPUs: 8, Scratch: 2 * GiB, Name: "costly"},
71 {Price: 1.1, RAM: 1000000000, VCPUs: 2, Scratch: GiB, Name: "small"},
72 {Price: 2.2, RAM: 2000000000, VCPUs: 4, Scratch: GiB, Name: "nearly"},
73 {Price: 3.3, RAM: 4000000000, VCPUs: 4, Scratch: 2 * GiB, Name: "best"},
74 {Price: 4.4, RAM: 4000000000, VCPUs: 8, Scratch: 2 * GiB, Name: "costly"},
77 best, err := ChooseInstanceType(&arvados.Cluster{InstanceTypes: menu}, &arvados.Container{
78 Mounts: map[string]arvados.Mount{
79 "/tmp": {Kind: "tmp", Capacity: 2 * GiB},
81 RuntimeConstraints: arvados.RuntimeConstraints{
84 KeepCacheRAM: 123456789,
87 c.Check(err, check.IsNil)
88 c.Check(best.Name, check.Equals, "best")
89 c.Check(best.RAM >= 1234567890, check.Equals, true)
90 c.Check(best.VCPUs >= 2, check.Equals, true)
91 c.Check(best.Scratch >= 2*GiB, check.Equals, true)