13581: Available types reported to the user when CR is not satisfiable.
[arvados.git] / lib / dispatchcloud / node_size_test.go
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 package dispatchcloud
6
7 import (
8         "git.curoverse.com/arvados.git/sdk/go/arvados"
9         check "gopkg.in/check.v1"
10 )
11
12 var _ = check.Suite(&NodeSizeSuite{})
13
14 const GiB = int64(1 << 30)
15
16 type NodeSizeSuite struct{}
17
18 func (*NodeSizeSuite) TestChooseNotConfigured(c *check.C) {
19         _, err := ChooseInstanceType(&arvados.Cluster{}, &arvados.Container{
20                 RuntimeConstraints: arvados.RuntimeConstraints{
21                         RAM:   1234567890,
22                         VCPUs: 2,
23                 },
24         })
25         c.Check(err, check.Equals, ErrInstanceTypesNotConfigured)
26 }
27
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},
34                 }}, ctr)
35                 err, ok := err.(ConstraintsNotSatisfiableError)
36                 c.Check(ok, check.Equals, true)
37         }
38
39         for _, rc := range []arvados.RuntimeConstraints{
40                 {RAM: 9876543210, VCPUs: 2},
41                 {RAM: 1234567890, VCPUs: 20},
42                 {RAM: 1234567890, VCPUs: 2, KeepCacheRAM: 9876543210},
43         } {
44                 checkUnsatisfiable(&arvados.Container{RuntimeConstraints: rc})
45         }
46         checkUnsatisfiable(&arvados.Container{
47                 Mounts:             map[string]arvados.Mount{"/tmp": {Kind: "tmp", Capacity: 2 * GiB}},
48                 RuntimeConstraints: arvados.RuntimeConstraints{RAM: 12345, VCPUs: 1},
49         })
50 }
51
52 func (*NodeSizeSuite) TestChoose(c *check.C) {
53         for _, menu := range [][]arvados.InstanceType{
54                 {
55                         {Price: 4.4, RAM: 4000000000, VCPUs: 8, Scratch: 2 * GiB, Name: "costly"},
56                         {Price: 2.2, RAM: 2000000000, VCPUs: 4, Scratch: 2 * GiB, Name: "best"},
57                         {Price: 1.1, RAM: 1000000000, VCPUs: 2, Scratch: 2 * GiB, Name: "small"},
58                 },
59                 {
60                         {Price: 4.4, RAM: 4000000000, VCPUs: 8, Scratch: 2 * GiB, Name: "costly"},
61                         {Price: 2.2, RAM: 2000000000, VCPUs: 4, Scratch: 2 * GiB, Name: "goodenough"},
62                         {Price: 2.2, RAM: 4000000000, VCPUs: 4, Scratch: 2 * GiB, Name: "best"},
63                         {Price: 1.1, RAM: 1000000000, VCPUs: 2, Scratch: 2 * GiB, Name: "small"},
64                 },
65                 {
66                         {Price: 1.1, RAM: 1000000000, VCPUs: 2, Scratch: 2 * GiB, Name: "small"},
67                         {Price: 2.2, RAM: 2000000000, VCPUs: 4, Scratch: 2 * GiB, Name: "goodenough"},
68                         {Price: 2.2, RAM: 4000000000, VCPUs: 4, Scratch: 2 * GiB, Name: "best"},
69                         {Price: 4.4, RAM: 4000000000, VCPUs: 8, Scratch: 2 * GiB, Name: "costly"},
70                 },
71                 {
72                         {Price: 1.1, RAM: 1000000000, VCPUs: 2, Scratch: GiB, Name: "small"},
73                         {Price: 2.2, RAM: 2000000000, VCPUs: 4, Scratch: GiB, Name: "nearly"},
74                         {Price: 3.3, RAM: 4000000000, VCPUs: 4, Scratch: 2 * GiB, Name: "best"},
75                         {Price: 4.4, RAM: 4000000000, VCPUs: 8, Scratch: 2 * GiB, Name: "costly"},
76                 },
77         } {
78                 best, err := ChooseInstanceType(&arvados.Cluster{InstanceTypes: menu}, &arvados.Container{
79                         Mounts: map[string]arvados.Mount{
80                                 "/tmp": {Kind: "tmp", Capacity: 2 * GiB},
81                         },
82                         RuntimeConstraints: arvados.RuntimeConstraints{
83                                 VCPUs:        2,
84                                 RAM:          987654321,
85                                 KeepCacheRAM: 123456789,
86                         },
87                 })
88                 c.Check(err, check.IsNil)
89                 c.Check(best.Name, check.Equals, "best")
90                 c.Check(best.RAM >= 1234567890, check.Equals, true)
91                 c.Check(best.VCPUs >= 2, check.Equals, true)
92                 c.Check(best.Scratch >= 2*GiB, check.Equals, true)
93         }
94 }