[ARVADOS] created: 1.1.4-526-g11ab2e235

Git user git at public.curoverse.com
Fri Jun 29 12:52:09 EDT 2018


        at  11ab2e23511c7e8962e0110c3aad44b74fea2dbd (commit)


commit 11ab2e23511c7e8962e0110c3aad44b74fea2dbd
Author: Tom Clegg <tclegg at veritasgenetics.com>
Date:   Fri Jun 29 12:50:22 2018 -0400

    13569: Update dispatchcloud to use arvados.ByteSize.
    
    Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tclegg at veritasgenetics.com>

diff --git a/lib/dispatchcloud/node_size.go b/lib/dispatchcloud/node_size.go
index 55e9d1e79..1c36d6cf5 100644
--- a/lib/dispatchcloud/node_size.go
+++ b/lib/dispatchcloud/node_size.go
@@ -51,8 +51,8 @@ func ChooseInstanceType(cc *arvados.Cluster, ctr *arvados.Container) (best arvad
 	for _, it := range cc.InstanceTypes {
 		switch {
 		case ok && it.Price > best.Price:
-		case it.Scratch < needScratch:
-		case it.RAM < needRAM:
+		case int64(it.Scratch) < needScratch:
+		case int64(it.RAM) < needRAM:
 		case it.VCPUs < needVCPUs:
 		case it.Preemptible != ctr.SchedulingParameters.Preemptible:
 		case it.Price == best.Price && (it.RAM < best.RAM || it.VCPUs < best.VCPUs):
diff --git a/lib/dispatchcloud/node_size_test.go b/lib/dispatchcloud/node_size_test.go
index 881c1f523..91c6bb104 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{}
 
@@ -43,7 +43,7 @@ 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},
 	})
 }
@@ -76,7 +76,7 @@ func (*NodeSizeSuite) TestChoose(c *check.C) {
 	} {
 		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,
@@ -101,7 +101,7 @@ func (*NodeSizeSuite) TestChoosePreemptable(c *check.C) {
 	}
 	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,

commit 7d4123813b42d8f6478e239895e62f6f600a1c6f
Author: Tom Clegg <tclegg at veritasgenetics.com>
Date:   Thu Jun 28 17:30:35 2018 -0400

    13569: Accept metric/binary-prefixed units in RAM/scratch configs.
    
    Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tclegg at veritasgenetics.com>

diff --git a/sdk/go/arvados/byte_size.go b/sdk/go/arvados/byte_size.go
new file mode 100644
index 000000000..db26a4cca
--- /dev/null
+++ b/sdk/go/arvados/byte_size.go
@@ -0,0 +1,71 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: Apache-2.0
+
+package arvados
+
+import (
+	"encoding/json"
+	"fmt"
+	"strings"
+)
+
+type ByteSize int64
+
+var prefixValue = map[string]int64{
+	"":   1,
+	"K":  1000,
+	"Ki": 1 << 10,
+	"M":  1000000,
+	"Mi": 1 << 20,
+	"G":  1000000000,
+	"Gi": 1 << 30,
+	"T":  1000000000000,
+	"Ti": 1 << 40,
+	"P":  1000000000000000,
+	"Pi": 1 << 50,
+	"E":  1000000000000000000,
+	"Ei": 1 << 60,
+}
+
+func (n *ByteSize) UnmarshalJSON(data []byte) error {
+	if len(data) == 0 || data[0] != '"' {
+		var i int64
+		err := json.Unmarshal(data, &i)
+		if err != nil {
+			return err
+		}
+		*n = ByteSize(i)
+		return nil
+	}
+	var s string
+	err := json.Unmarshal(data, &s)
+	if err != nil {
+		return err
+	}
+	split := strings.LastIndexAny(s, "0123456789") + 1
+	if split == 0 {
+		return fmt.Errorf("invalid byte size %q", s)
+	}
+	var val int64
+	err = json.Unmarshal([]byte(s[:split]), &val)
+	if err != nil {
+		return err
+	}
+	if split == len(s) {
+		return nil
+	}
+	prefix := strings.Trim(s[split:], " ")
+	if strings.HasSuffix(prefix, "B") {
+		prefix = prefix[:len(prefix)-1]
+	}
+	pval, ok := prefixValue[prefix]
+	if !ok {
+		return fmt.Errorf("invalid unit %q", strings.Trim(s[split:], " "))
+	}
+	if pval > 1 && (val*pval)/pval != val {
+		return fmt.Errorf("size %q overflows int64", s)
+	}
+	*n = ByteSize(val * pval)
+	return nil
+}
diff --git a/sdk/go/arvados/byte_size_test.go b/sdk/go/arvados/byte_size_test.go
new file mode 100644
index 000000000..857ec7b00
--- /dev/null
+++ b/sdk/go/arvados/byte_size_test.go
@@ -0,0 +1,59 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: Apache-2.0
+
+package arvados
+
+import (
+	"github.com/ghodss/yaml"
+	check "gopkg.in/check.v1"
+)
+
+var _ = check.Suite(&ByteSizeSuite{})
+
+type ByteSizeSuite struct{}
+
+func (s *ByteSizeSuite) TestUnmarshal(c *check.C) {
+	for _, testcase := range []struct {
+		in  string
+		out int64
+	}{
+		{"0", 0},
+		{"5", 5},
+		{"5B", 5},
+		{"5 B", 5},
+		{" 4 KiB ", 4096},
+		{"0K", 0},
+		{"0Ki", 0},
+		{"0 KiB", 0},
+		{"4K", 4000},
+		{"4KB", 4000},
+		{"4Ki", 4096},
+		{"4KiB", 4096},
+		{"4MB", 4000000},
+		{"4MiB", 4194304},
+		{"4GB", 4000000000},
+		{"4 GiB", 4294967296},
+		{"4TB", 4000000000000},
+		{"4TiB", 4398046511104},
+		{"4PB", 4000000000000000},
+		{"4PiB", 4503599627370496},
+		{"4EB", 4000000000000000000},
+		{"4EiB", 4611686018427387904},
+	} {
+		var n ByteSize
+		err := yaml.Unmarshal([]byte(testcase.in+"\n"), &n)
+		c.Check(err, check.IsNil)
+		c.Check(int64(n), check.Equals, testcase.out)
+	}
+	for _, testcase := range []string{
+		"B", "K", "KB", "KiB", "4BK", "4iB", "4A", "b", "4b", "4mB", "4m", "4mib", "4KIB", "4K iB", "4Ki B", "BB", "4BB",
+		"400000 EB", // overflows int64
+	} {
+		var n ByteSize
+		err := yaml.Unmarshal([]byte(testcase+"\n"), &n)
+		c.Log(n)
+		c.Log(err)
+		c.Check(err, check.NotNil)
+	}
+}
diff --git a/sdk/go/arvados/config.go b/sdk/go/arvados/config.go
index af09d1af1..353901855 100644
--- a/sdk/go/arvados/config.go
+++ b/sdk/go/arvados/config.go
@@ -62,8 +62,8 @@ type InstanceType struct {
 	Name         string
 	ProviderType string
 	VCPUs        int
-	RAM          int64
-	Scratch      int64
+	RAM          ByteSize
+	Scratch      ByteSize
 	Price        float64
 	Preemptible  bool
 }
diff --git a/sdk/go/arvados/config_test.go b/sdk/go/arvados/config_test.go
index 697b02d7c..59c743268 100644
--- a/sdk/go/arvados/config_test.go
+++ b/sdk/go/arvados/config_test.go
@@ -27,3 +27,11 @@ func (s *ConfigSuite) TestInstanceTypesAsHash(c *check.C) {
 	c.Check(cluster.InstanceTypes["foo"].Name, check.Equals, "foo")
 	c.Check(cluster.InstanceTypes["foo"].ProviderType, check.Equals, "bar")
 }
+
+func (s *ConfigSuite) TestInstanceTypeSize(c *check.C) {
+	var it InstanceType
+	err := yaml.Unmarshal([]byte("Name: foo\nScratch: 4GB\nRAM: 4GiB\n"), &it)
+	c.Check(err, check.IsNil)
+	c.Check(int64(it.Scratch), check.Equals, int64(4000000000))
+	c.Check(int64(it.RAM), check.Equals, int64(4294967296))
+}

commit 596884ea30c551d7c2699b2cf3fdea2cede3101a
Author: Tom Clegg <tclegg at veritasgenetics.com>
Date:   Fri Jun 22 14:16:05 2018 -0400

    13674: Don't build heavy error unless needed.
    
    Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tclegg at veritasgenetics.com>

diff --git a/lib/dispatchcloud/node_size.go b/lib/dispatchcloud/node_size.go
index 5173cc797..55e9d1e79 100644
--- a/lib/dispatchcloud/node_size.go
+++ b/lib/dispatchcloud/node_size.go
@@ -47,20 +47,10 @@ func ChooseInstanceType(cc *arvados.Cluster, ctr *arvados.Container) (best arvad
 	needRAM := ctr.RuntimeConstraints.RAM + ctr.RuntimeConstraints.KeepCacheRAM
 	needRAM = (needRAM * 100) / int64(100-discountConfiguredRAMPercent)
 
-	availableTypes := make([]arvados.InstanceType, 0, len(cc.InstanceTypes))
-	for _, t := range cc.InstanceTypes {
-		availableTypes = append(availableTypes, t)
-	}
-	sort.Slice(availableTypes, func(a, b int) bool {
-		return availableTypes[a].Price < availableTypes[b].Price
-	})
-	err = ConstraintsNotSatisfiableError{
-		errors.New("constraints not satisfiable by any configured instance type"),
-		availableTypes,
-	}
+	ok := false
 	for _, it := range cc.InstanceTypes {
 		switch {
-		case err == nil && it.Price > best.Price:
+		case ok && it.Price > best.Price:
 		case it.Scratch < needScratch:
 		case it.RAM < needRAM:
 		case it.VCPUs < needVCPUs:
@@ -70,8 +60,22 @@ func ChooseInstanceType(cc *arvados.Cluster, ctr *arvados.Container) (best arvad
 		default:
 			// Lower price || (same price && better specs)
 			best = it
-			err = nil
+			ok = true
+		}
+	}
+	if !ok {
+		availableTypes := make([]arvados.InstanceType, 0, len(cc.InstanceTypes))
+		for _, t := range cc.InstanceTypes {
+			availableTypes = append(availableTypes, t)
+		}
+		sort.Slice(availableTypes, func(a, b int) bool {
+			return availableTypes[a].Price < availableTypes[b].Price
+		})
+		err = ConstraintsNotSatisfiableError{
+			errors.New("constraints not satisfiable by any configured instance type"),
+			availableTypes,
 		}
+		return
 	}
 	return
 }

commit bd059862d1dd7e68642dd365f0a536621ff6735f
Author: Tom Clegg <tclegg at veritasgenetics.com>
Date:   Wed Jun 20 15:25:29 2018 -0400

    13674: Change InstanceTypes config from array to hash.
    
    Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tclegg at veritasgenetics.com>

diff --git a/lib/dispatchcloud/node_size.go b/lib/dispatchcloud/node_size.go
index 4329f4f13..5173cc797 100644
--- a/lib/dispatchcloud/node_size.go
+++ b/lib/dispatchcloud/node_size.go
@@ -47,8 +47,10 @@ func ChooseInstanceType(cc *arvados.Cluster, ctr *arvados.Container) (best arvad
 	needRAM := ctr.RuntimeConstraints.RAM + ctr.RuntimeConstraints.KeepCacheRAM
 	needRAM = (needRAM * 100) / int64(100-discountConfiguredRAMPercent)
 
-	availableTypes := make([]arvados.InstanceType, len(cc.InstanceTypes))
-	copy(availableTypes, cc.InstanceTypes)
+	availableTypes := make([]arvados.InstanceType, 0, len(cc.InstanceTypes))
+	for _, t := range cc.InstanceTypes {
+		availableTypes = append(availableTypes, t)
+	}
 	sort.Slice(availableTypes, func(a, b int) bool {
 		return availableTypes[a].Price < availableTypes[b].Price
 	})
diff --git a/lib/dispatchcloud/node_size_test.go b/lib/dispatchcloud/node_size_test.go
index 1484f07a2..881c1f523 100644
--- a/lib/dispatchcloud/node_size_test.go
+++ b/lib/dispatchcloud/node_size_test.go
@@ -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{})
 	}
@@ -49,29 +49,29 @@ func (*NodeSizeSuite) TestChooseUnsatisfiable(c *check.C) {
 }
 
 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{
@@ -92,12 +92,12 @@ func (*NodeSizeSuite) TestChoose(c *check.C) {
 	}
 }
 
-func (*NodeSizeSuite) TestChoosePreemptible(c *check.C) {
-	menu := []arvados.InstanceType{
-		{Price: 4.4, RAM: 4000000000, VCPUs: 8, Scratch: 2 * GiB, Preemptible: 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, Preemptible: true, Name: "best"},
-		{Price: 1.1, RAM: 1000000000, VCPUs: 2, Scratch: 2 * GiB, Preemptible: true, Name: "small"},
+func (*NodeSizeSuite) TestChoosePreemptable(c *check.C) {
+	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{
diff --git a/sdk/go/arvados/config.go b/sdk/go/arvados/config.go
index 182cf8433..af09d1af1 100644
--- a/sdk/go/arvados/config.go
+++ b/sdk/go/arvados/config.go
@@ -5,6 +5,8 @@
 package arvados
 
 import (
+	"encoding/json"
+	"errors"
 	"fmt"
 	"os"
 
@@ -52,7 +54,7 @@ type Cluster struct {
 	ClusterID          string `json:"-"`
 	ManagementToken    string
 	NodeProfiles       map[string]NodeProfile
-	InstanceTypes      []InstanceType
+	InstanceTypes      InstanceTypeMap
 	HTTPRequestTimeout Duration
 }
 
@@ -66,6 +68,46 @@ type InstanceType struct {
 	Preemptible  bool
 }
 
+type InstanceTypeMap map[string]InstanceType
+
+var errDuplicateInstanceTypeName = errors.New("duplicate instance type name")
+
+// UnmarshalJSON handles old config files that provide an array of
+// instance types instead of a hash.
+func (it *InstanceTypeMap) UnmarshalJSON(data []byte) error {
+	if len(data) > 0 && data[0] == '[' {
+		var arr []InstanceType
+		err := json.Unmarshal(data, &arr)
+		if err != nil {
+			return err
+		}
+		if len(arr) == 0 {
+			*it = nil
+			return nil
+		}
+		*it = make(map[string]InstanceType, len(arr))
+		for _, t := range arr {
+			if _, ok := (*it)[t.Name]; ok {
+				return errDuplicateInstanceTypeName
+			}
+			(*it)[t.Name] = t
+		}
+		return nil
+	}
+	var hash map[string]InstanceType
+	err := json.Unmarshal(data, &hash)
+	if err != nil {
+		return err
+	}
+	// Fill in Name field using hash key.
+	*it = InstanceTypeMap(hash)
+	for name, t := range *it {
+		t.Name = name
+		(*it)[name] = t
+	}
+	return nil
+}
+
 // GetNodeProfile returns a NodeProfile for the given hostname. An
 // error is returned if the appropriate configuration can't be
 // determined (e.g., this does not appear to be a system node). If
diff --git a/sdk/go/arvados/config_test.go b/sdk/go/arvados/config_test.go
new file mode 100644
index 000000000..697b02d7c
--- /dev/null
+++ b/sdk/go/arvados/config_test.go
@@ -0,0 +1,29 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: Apache-2.0
+
+package arvados
+
+import (
+	"github.com/ghodss/yaml"
+	check "gopkg.in/check.v1"
+)
+
+var _ = check.Suite(&ConfigSuite{})
+
+type ConfigSuite struct{}
+
+func (s *ConfigSuite) TestInstanceTypesAsArray(c *check.C) {
+	var cluster Cluster
+	yaml.Unmarshal([]byte("InstanceTypes:\n- Name: foo\n"), &cluster)
+	c.Check(len(cluster.InstanceTypes), check.Equals, 1)
+	c.Check(cluster.InstanceTypes["foo"].Name, check.Equals, "foo")
+}
+
+func (s *ConfigSuite) TestInstanceTypesAsHash(c *check.C) {
+	var cluster Cluster
+	yaml.Unmarshal([]byte("InstanceTypes:\n  foo:\n    ProviderType: bar\n"), &cluster)
+	c.Check(len(cluster.InstanceTypes), check.Equals, 1)
+	c.Check(cluster.InstanceTypes["foo"].Name, check.Equals, "foo")
+	c.Check(cluster.InstanceTypes["foo"].ProviderType, check.Equals, "bar")
+}
diff --git a/services/crunch-dispatch-slurm/crunch-dispatch-slurm_test.go b/services/crunch-dispatch-slurm/crunch-dispatch-slurm_test.go
index b4033e78b..23a8a0ca0 100644
--- a/services/crunch-dispatch-slurm/crunch-dispatch-slurm_test.go
+++ b/services/crunch-dispatch-slurm/crunch-dispatch-slurm_test.go
@@ -367,17 +367,17 @@ func (s *StubbedSuite) TestSbatchInstanceTypeConstraint(c *C) {
 	}
 
 	for _, trial := range []struct {
-		types      []arvados.InstanceType
+		types      map[string]arvados.InstanceType
 		sbatchArgs []string
 		err        error
 	}{
 		// Choose node type => use --constraint arg
 		{
-			types: []arvados.InstanceType{
-				{Name: "a1.tiny", Price: 0.02, RAM: 128000000, VCPUs: 1},
-				{Name: "a1.small", Price: 0.04, RAM: 256000000, VCPUs: 2},
-				{Name: "a1.medium", Price: 0.08, RAM: 512000000, VCPUs: 4},
-				{Name: "a1.large", Price: 0.16, RAM: 1024000000, VCPUs: 8},
+			types: map[string]arvados.InstanceType{
+				"a1.tiny":   {Name: "a1.tiny", Price: 0.02, RAM: 128000000, VCPUs: 1},
+				"a1.small":  {Name: "a1.small", Price: 0.04, RAM: 256000000, VCPUs: 2},
+				"a1.medium": {Name: "a1.medium", Price: 0.08, RAM: 512000000, VCPUs: 4},
+				"a1.large":  {Name: "a1.large", Price: 0.16, RAM: 1024000000, VCPUs: 8},
 			},
 			sbatchArgs: []string{"--constraint=instancetype=a1.medium"},
 		},
@@ -388,8 +388,8 @@ func (s *StubbedSuite) TestSbatchInstanceTypeConstraint(c *C) {
 		},
 		// No node type is big enough => error
 		{
-			types: []arvados.InstanceType{
-				{Name: "a1.tiny", Price: 0.02, RAM: 128000000, VCPUs: 1},
+			types: map[string]arvados.InstanceType{
+				"a1.tiny": {Name: "a1.tiny", Price: 0.02, RAM: 128000000, VCPUs: 1},
 			},
 			err: dispatchcloud.ConstraintsNotSatisfiableError{},
 		},

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list