X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/c4b2d43234205a0d9b1310e55b1f00dee9c20625..b715e06b9f8ac2ca1037a63dc90b3c235557dbde:/lib/dispatchcloud/node_size_test.go diff --git a/lib/dispatchcloud/node_size_test.go b/lib/dispatchcloud/node_size_test.go index d6b7c6bf9f..eef86f7477 100644 --- a/lib/dispatchcloud/node_size_test.go +++ b/lib/dispatchcloud/node_size_test.go @@ -11,7 +11,7 @@ import ( var _ = check.Suite(&NodeSizeSuite{}) -const GiB = int64(1 << 30) +const GiB = arvados.ByteSize(1 << 30) type NodeSizeSuite struct{} @@ -27,10 +27,10 @@ func (*NodeSizeSuite) TestChooseNotConfigured(c *check.C) { func (*NodeSizeSuite) TestChooseUnsatisfiable(c *check.C) { checkUnsatisfiable := func(ctr *arvados.Container) { - _, err := ChooseInstanceType(&arvados.Cluster{InstanceTypes: []arvados.InstanceType{ - {Price: 1.1, RAM: 1000000000, VCPUs: 2, Name: "small1"}, - {Price: 2.2, RAM: 2000000000, VCPUs: 4, Name: "small2"}, - {Price: 4.4, RAM: 4000000000, VCPUs: 8, Name: "small4", Scratch: GiB}, + _, err := ChooseInstanceType(&arvados.Cluster{InstanceTypes: map[string]arvados.InstanceType{ + "small1": {Price: 1.1, RAM: 1000000000, VCPUs: 2, Name: "small1"}, + "small2": {Price: 2.2, RAM: 2000000000, VCPUs: 4, Name: "small2"}, + "small4": {Price: 4.4, RAM: 4000000000, VCPUs: 8, Name: "small4", Scratch: GiB}, }}, ctr) c.Check(err, check.FitsTypeOf, ConstraintsNotSatisfiableError{}) } @@ -43,40 +43,40 @@ func (*NodeSizeSuite) TestChooseUnsatisfiable(c *check.C) { checkUnsatisfiable(&arvados.Container{RuntimeConstraints: rc}) } checkUnsatisfiable(&arvados.Container{ - Mounts: map[string]arvados.Mount{"/tmp": {Kind: "tmp", Capacity: 2 * GiB}}, + Mounts: map[string]arvados.Mount{"/tmp": {Kind: "tmp", Capacity: int64(2 * GiB)}}, RuntimeConstraints: arvados.RuntimeConstraints{RAM: 12345, VCPUs: 1}, }) } func (*NodeSizeSuite) TestChoose(c *check.C) { - for _, menu := range [][]arvados.InstanceType{ + for _, menu := range []map[string]arvados.InstanceType{ { - {Price: 4.4, RAM: 4000000000, VCPUs: 8, Scratch: 2 * GiB, Name: "costly"}, - {Price: 2.2, RAM: 2000000000, VCPUs: 4, Scratch: 2 * GiB, Name: "best"}, - {Price: 1.1, RAM: 1000000000, VCPUs: 2, Scratch: 2 * GiB, Name: "small"}, + "costly": {Price: 4.4, RAM: 4000000000, VCPUs: 8, Scratch: 2 * GiB, Name: "costly"}, + "best": {Price: 2.2, RAM: 2000000000, VCPUs: 4, Scratch: 2 * GiB, Name: "best"}, + "small": {Price: 1.1, RAM: 1000000000, VCPUs: 2, Scratch: 2 * GiB, Name: "small"}, }, { - {Price: 4.4, RAM: 4000000000, VCPUs: 8, Scratch: 2 * GiB, Name: "costly"}, - {Price: 2.2, RAM: 2000000000, VCPUs: 4, Scratch: 2 * GiB, Name: "goodenough"}, - {Price: 2.2, RAM: 4000000000, VCPUs: 4, Scratch: 2 * GiB, Name: "best"}, - {Price: 1.1, RAM: 1000000000, VCPUs: 2, Scratch: 2 * GiB, Name: "small"}, + "costly": {Price: 4.4, RAM: 4000000000, VCPUs: 8, Scratch: 2 * GiB, Name: "costly"}, + "goodenough": {Price: 2.2, RAM: 2000000000, VCPUs: 4, Scratch: 2 * GiB, Name: "goodenough"}, + "best": {Price: 2.2, RAM: 4000000000, VCPUs: 4, Scratch: 2 * GiB, Name: "best"}, + "small": {Price: 1.1, RAM: 1000000000, VCPUs: 2, Scratch: 2 * GiB, Name: "small"}, }, { - {Price: 1.1, RAM: 1000000000, VCPUs: 2, Scratch: 2 * GiB, Name: "small"}, - {Price: 2.2, RAM: 2000000000, VCPUs: 4, Scratch: 2 * GiB, Name: "goodenough"}, - {Price: 2.2, RAM: 4000000000, VCPUs: 4, Scratch: 2 * GiB, Name: "best"}, - {Price: 4.4, RAM: 4000000000, VCPUs: 8, Scratch: 2 * GiB, Name: "costly"}, + "small": {Price: 1.1, RAM: 1000000000, VCPUs: 2, Scratch: 2 * GiB, Name: "small"}, + "goodenough": {Price: 2.2, RAM: 2000000000, VCPUs: 4, Scratch: 2 * GiB, Name: "goodenough"}, + "best": {Price: 2.2, RAM: 4000000000, VCPUs: 4, Scratch: 2 * GiB, Name: "best"}, + "costly": {Price: 4.4, RAM: 4000000000, VCPUs: 8, Scratch: 2 * GiB, Name: "costly"}, }, { - {Price: 1.1, RAM: 1000000000, VCPUs: 2, Scratch: GiB, Name: "small"}, - {Price: 2.2, RAM: 2000000000, VCPUs: 4, Scratch: GiB, Name: "nearly"}, - {Price: 3.3, RAM: 4000000000, VCPUs: 4, Scratch: 2 * GiB, Name: "best"}, - {Price: 4.4, RAM: 4000000000, VCPUs: 8, Scratch: 2 * GiB, Name: "costly"}, + "small": {Price: 1.1, RAM: 1000000000, VCPUs: 2, Scratch: GiB, Name: "small"}, + "nearly": {Price: 2.2, RAM: 2000000000, VCPUs: 4, Scratch: GiB, Name: "nearly"}, + "best": {Price: 3.3, RAM: 4000000000, VCPUs: 4, Scratch: 2 * GiB, Name: "best"}, + "costly": {Price: 4.4, RAM: 4000000000, VCPUs: 8, Scratch: 2 * GiB, Name: "costly"}, }, } { best, err := ChooseInstanceType(&arvados.Cluster{InstanceTypes: menu}, &arvados.Container{ Mounts: map[string]arvados.Mount{ - "/tmp": {Kind: "tmp", Capacity: 2 * GiB}, + "/tmp": {Kind: "tmp", Capacity: 2 * int64(GiB)}, }, RuntimeConstraints: arvados.RuntimeConstraints{ VCPUs: 2, @@ -93,15 +93,15 @@ func (*NodeSizeSuite) TestChoose(c *check.C) { } func (*NodeSizeSuite) TestChoosePreemptable(c *check.C) { - menu := []arvados.InstanceType{ - {Price: 4.4, RAM: 4000000000, VCPUs: 8, Scratch: 2 * GiB, Preemptable: true, Name: "costly"}, - {Price: 2.2, RAM: 2000000000, VCPUs: 4, Scratch: 2 * GiB, Name: "almost best"}, - {Price: 2.2, RAM: 2000000000, VCPUs: 4, Scratch: 2 * GiB, Preemptable: true, Name: "best"}, - {Price: 1.1, RAM: 1000000000, VCPUs: 2, Scratch: 2 * GiB, Preemptable: true, Name: "small"}, + menu := map[string]arvados.InstanceType{ + "costly": {Price: 4.4, RAM: 4000000000, VCPUs: 8, Scratch: 2 * GiB, Preemptible: true, Name: "costly"}, + "almost best": {Price: 2.2, RAM: 2000000000, VCPUs: 4, Scratch: 2 * GiB, Name: "almost best"}, + "best": {Price: 2.2, RAM: 2000000000, VCPUs: 4, Scratch: 2 * GiB, Preemptible: true, Name: "best"}, + "small": {Price: 1.1, RAM: 1000000000, VCPUs: 2, Scratch: 2 * GiB, Preemptible: true, Name: "small"}, } best, err := ChooseInstanceType(&arvados.Cluster{InstanceTypes: menu}, &arvados.Container{ Mounts: map[string]arvados.Mount{ - "/tmp": {Kind: "tmp", Capacity: 2 * GiB}, + "/tmp": {Kind: "tmp", Capacity: 2 * int64(GiB)}, }, RuntimeConstraints: arvados.RuntimeConstraints{ VCPUs: 2, @@ -109,7 +109,7 @@ func (*NodeSizeSuite) TestChoosePreemptable(c *check.C) { KeepCacheRAM: 123456789, }, SchedulingParameters: arvados.SchedulingParameters{ - Preemptable: true, + Preemptible: true, }, }) c.Check(err, check.IsNil) @@ -117,5 +117,27 @@ func (*NodeSizeSuite) TestChoosePreemptable(c *check.C) { c.Check(best.RAM >= 1234567890, check.Equals, true) c.Check(best.VCPUs >= 2, check.Equals, true) c.Check(best.Scratch >= 2*GiB, check.Equals, true) - c.Check(best.Preemptable, check.Equals, true) + c.Check(best.Preemptible, check.Equals, true) +} + +func (*NodeSizeSuite) TestScratchForDockerImage(c *check.C) { + n := EstimateScratchSpace(&arvados.Container{ + ContainerImage: "d5025c0f29f6eef304a7358afa82a822+342", + }) + // Actual image is 371.1 MiB (according to workbench) + // Estimated size is 384 MiB (402653184 bytes) + // Want to reserve 2x the estimated size, so 805306368 bytes + c.Check(n, check.Equals, int64(805306368)) + + n = EstimateScratchSpace(&arvados.Container{ + ContainerImage: "d5025c0f29f6eef304a7358afa82a822+-342", + }) + // Parse error will return 0 + c.Check(n, check.Equals, int64(0)) + + n = EstimateScratchSpace(&arvados.Container{ + ContainerImage: "d5025c0f29f6eef304a7358afa82a822+34", + }) + // Short manifest will return 0 + c.Check(n, check.Equals, int64(0)) }