[ARVADOS] updated: 2.1.0-1505-g72b73786d

Git user git at public.arvados.org
Thu Oct 28 01:09:44 UTC 2021


Summary of changes:
 lib/controller/localdb/collection_test.go        |  29 ++--
 lib/controller/localdb/container_request.go      |  39 ++++++
 lib/controller/localdb/container_request_test.go | 168 +++++++++++++++++++++++
 lib/controller/localdb/group.go                  |  39 ++++++
 lib/controller/localdb/group_test.go             | 140 +++++++++++++++++++
 5 files changed, 398 insertions(+), 17 deletions(-)
 create mode 100644 lib/controller/localdb/container_request.go
 create mode 100644 lib/controller/localdb/container_request_test.go
 create mode 100644 lib/controller/localdb/group.go
 create mode 100644 lib/controller/localdb/group_test.go

       via  72b73786d65024b941a99d2c6593c42f0efbaf18 (commit)
      from  eb2ad403584404052875a286edec4a53b57c7192 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.


commit 72b73786d65024b941a99d2c6593c42f0efbaf18
Author: Lucas Di Pentima <lucas.dipentima at curii.com>
Date:   Wed Oct 27 22:08:39 2021 -0300

    17944: Adds group & container_request vocabulary checking.
    
    Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima <lucas.dipentima at curii.com>

diff --git a/lib/controller/localdb/collection_test.go b/lib/controller/localdb/collection_test.go
index 44584fec0..d7395d750 100644
--- a/lib/controller/localdb/collection_test.go
+++ b/lib/controller/localdb/collection_test.go
@@ -6,7 +6,6 @@ package localdb
 
 import (
 	"context"
-	"encoding/json"
 	"regexp"
 	"strconv"
 	"time"
@@ -78,13 +77,13 @@ func (s *CollectionSuite) TestCollectionCreateWithProperties(c *check.C) {
 
 	tests := []struct {
 		name    string
-		props   string
+		props   map[string]interface{}
 		success bool
 	}{
-		{"Invalid prop key", `{"Priority":"IDVALIMPORTANCES1"}`, false},
-		{"Invalid prop value", `{"IDTAGIMPORTANCES": "high"}`, false},
-		{"Valid prop key & value", `{"IDTAGIMPORTANCES": "IDVALIMPORTANCES1"}`, true},
-		{"Empty properties", "{}", true},
+		{"Invalid prop key", map[string]interface{}{"Priority": "IDVALIMPORTANCES1"}, false},
+		{"Invalid prop value", map[string]interface{}{"IDTAGIMPORTANCES": "high"}, false},
+		{"Valid prop key & value", map[string]interface{}{"IDTAGIMPORTANCES": "IDVALIMPORTANCES1"}, true},
+		{"Empty properties", map[string]interface{}{}, true},
 	}
 	for _, tt := range tests {
 		c.Log(c.TestName()+" ", tt.name)
@@ -96,10 +95,8 @@ func (s *CollectionSuite) TestCollectionCreateWithProperties(c *check.C) {
 			}})
 		if tt.success {
 			c.Assert(err, check.IsNil)
-			var wantedProps map[string]interface{}
-			err = json.Unmarshal([]byte(tt.props), &wantedProps)
 			c.Assert(err, check.IsNil)
-			c.Assert(coll.Properties, check.DeepEquals, wantedProps)
+			c.Assert(coll.Properties, check.DeepEquals, tt.props)
 		} else {
 			c.Assert(err, check.NotNil)
 		}
@@ -112,13 +109,13 @@ func (s *CollectionSuite) TestCollectionUpdateWithProperties(c *check.C) {
 
 	tests := []struct {
 		name    string
-		props   string
+		props   map[string]interface{}
 		success bool
 	}{
-		{"Invalid prop key", `{"Priority":"IDVALIMPORTANCES1"}`, false},
-		{"Invalid prop value", `{"IDTAGIMPORTANCES": "high"}`, false},
-		{"Valid prop key & value", `{"IDTAGIMPORTANCES": "IDVALIMPORTANCES1"}`, true},
-		{"Empty properties", "{}", true},
+		{"Invalid prop key", map[string]interface{}{"Priority": "IDVALIMPORTANCES1"}, false},
+		{"Invalid prop value", map[string]interface{}{"IDTAGIMPORTANCES": "high"}, false},
+		{"Valid prop key & value", map[string]interface{}{"IDTAGIMPORTANCES": "IDVALIMPORTANCES1"}, true},
+		{"Empty properties", map[string]interface{}{}, true},
 	}
 	for _, tt := range tests {
 		c.Log(c.TestName()+" ", tt.name)
@@ -132,10 +129,8 @@ func (s *CollectionSuite) TestCollectionUpdateWithProperties(c *check.C) {
 			}})
 		if tt.success {
 			c.Assert(err, check.IsNil)
-			var wantedProps map[string]interface{}
-			err = json.Unmarshal([]byte(tt.props), &wantedProps)
 			c.Assert(err, check.IsNil)
-			c.Assert(coll.Properties, check.DeepEquals, wantedProps)
+			c.Assert(coll.Properties, check.DeepEquals, tt.props)
 		} else {
 			c.Assert(err, check.NotNil)
 		}
diff --git a/lib/controller/localdb/container_request.go b/lib/controller/localdb/container_request.go
new file mode 100644
index 000000000..940c3cf84
--- /dev/null
+++ b/lib/controller/localdb/container_request.go
@@ -0,0 +1,39 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+package localdb
+
+import (
+	"context"
+
+	"git.arvados.org/arvados.git/sdk/go/arvados"
+)
+
+// ContainerCreate defers to railsProxy for everything except
+// vocabulary checking.
+func (conn *Conn) ContainerRequestCreate(ctx context.Context, opts arvados.CreateOptions) (arvados.ContainerRequest, error) {
+	err := conn.checkProperties(opts.Attrs["properties"])
+	if err != nil {
+		return arvados.ContainerRequest{}, err
+	}
+	resp, err := conn.railsProxy.ContainerRequestCreate(ctx, opts)
+	if err != nil {
+		return resp, err
+	}
+	return resp, nil
+}
+
+// ContainerUpdate defers to railsProxy for everything except
+// vocabulary checking.
+func (conn *Conn) ContainerRequestUpdate(ctx context.Context, opts arvados.UpdateOptions) (arvados.ContainerRequest, error) {
+	err := conn.checkProperties(opts.Attrs["properties"])
+	if err != nil {
+		return arvados.ContainerRequest{}, err
+	}
+	resp, err := conn.railsProxy.ContainerRequestUpdate(ctx, opts)
+	if err != nil {
+		return resp, err
+	}
+	return resp, nil
+}
diff --git a/lib/controller/localdb/container_request_test.go b/lib/controller/localdb/container_request_test.go
new file mode 100644
index 000000000..ce55d650b
--- /dev/null
+++ b/lib/controller/localdb/container_request_test.go
@@ -0,0 +1,168 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+package localdb
+
+import (
+	"context"
+
+	"git.arvados.org/arvados.git/lib/config"
+	"git.arvados.org/arvados.git/lib/controller/rpc"
+	"git.arvados.org/arvados.git/sdk/go/arvados"
+	"git.arvados.org/arvados.git/sdk/go/arvadostest"
+	"git.arvados.org/arvados.git/sdk/go/auth"
+	"git.arvados.org/arvados.git/sdk/go/ctxlog"
+	check "gopkg.in/check.v1"
+)
+
+var _ = check.Suite(&ContainerRequestSuite{})
+
+type ContainerRequestSuite struct {
+	cluster  *arvados.Cluster
+	localdb  *Conn
+	railsSpy *arvadostest.Proxy
+}
+
+func (s *ContainerRequestSuite) TearDownSuite(c *check.C) {
+	// Undo any changes/additions to the user database so they
+	// don't affect subsequent tests.
+	arvadostest.ResetEnv()
+	c.Check(arvados.NewClientFromEnv().RequestAndDecode(nil, "POST", "database/reset", nil, nil), check.IsNil)
+}
+
+func (s *ContainerRequestSuite) SetUpTest(c *check.C) {
+	cfg, err := config.NewLoader(nil, ctxlog.TestLogger(c)).Load()
+	c.Assert(err, check.IsNil)
+	s.cluster, err = cfg.GetCluster("")
+	c.Assert(err, check.IsNil)
+	s.localdb = NewConn(s.cluster)
+	s.railsSpy = arvadostest.NewProxy(c, s.cluster.Services.RailsAPI)
+	*s.localdb.railsProxy = *rpc.NewConn(s.cluster.ClusterID, s.railsSpy.URL, true, rpc.PassthroughTokenProvider)
+}
+
+func (s *ContainerRequestSuite) TearDownTest(c *check.C) {
+	s.railsSpy.Close()
+}
+
+func (s *ContainerRequestSuite) setUpVocabulary(c *check.C, testVocabulary string) {
+	if testVocabulary == "" {
+		testVocabulary = `{
+			"strict_tags": false,
+			"tags": {
+				"IDTAGIMPORTANCES": {
+					"strict": true,
+					"labels": [{"label": "Importance"}, {"label": "Priority"}],
+					"values": {
+						"IDVALIMPORTANCES1": { "labels": [{"label": "Critical"}, {"label": "Urgent"}, {"label": "High"}] },
+						"IDVALIMPORTANCES2": { "labels": [{"label": "Normal"}, {"label": "Moderate"}] },
+						"IDVALIMPORTANCES3": { "labels": [{"label": "Low"}] }
+					}
+				}
+			}
+		}`
+	}
+	voc, err := arvados.NewVocabulary([]byte(testVocabulary))
+	c.Assert(err, check.IsNil)
+	c.Assert(voc.Validate(), check.IsNil)
+	s.cluster.API.Vocabulary = voc
+}
+
+func (s *ContainerRequestSuite) TestCRCreateWithProperties(c *check.C) {
+	s.setUpVocabulary(c, "")
+	ctx := auth.NewContext(context.Background(), &auth.Credentials{Tokens: []string{arvadostest.ActiveTokenV2}})
+
+	tests := []struct {
+		name    string
+		props   map[string]interface{}
+		success bool
+	}{
+		{"Invalid prop key", map[string]interface{}{"Priority": "IDVALIMPORTANCES1"}, false},
+		{"Invalid prop value", map[string]interface{}{"IDTAGIMPORTANCES": "high"}, false},
+		{"Valid prop key & value", map[string]interface{}{"IDTAGIMPORTANCES": "IDVALIMPORTANCES1"}, true},
+		{"Empty properties", map[string]interface{}{}, true},
+	}
+	for _, tt := range tests {
+		c.Log(c.TestName()+" ", tt.name)
+
+		cnt, err := s.localdb.ContainerRequestCreate(ctx, arvados.CreateOptions{
+			Select: []string{"uuid", "properties"},
+			Attrs: map[string]interface{}{
+				"command":         []string{"echo", "foo"},
+				"container_image": "arvados/apitestfixture:latest",
+				"cwd":             "/tmp",
+				"environment":     map[string]string{},
+				"mounts": map[string]interface{}{
+					"/out": map[string]interface{}{
+						"kind":     "tmp",
+						"capacity": 1000000,
+					},
+				},
+				"output_path": "/out",
+				"runtime_constraints": map[string]interface{}{
+					"vcpus": 1,
+					"ram":   2,
+				},
+				"properties": tt.props,
+			}})
+		if tt.success {
+			c.Assert(err, check.IsNil)
+			c.Assert(err, check.IsNil)
+			c.Assert(cnt.Properties, check.DeepEquals, tt.props)
+		} else {
+			c.Assert(err, check.NotNil)
+		}
+	}
+}
+
+func (s *ContainerRequestSuite) TestCRUpdateWithProperties(c *check.C) {
+	s.setUpVocabulary(c, "")
+	ctx := auth.NewContext(context.Background(), &auth.Credentials{Tokens: []string{arvadostest.ActiveTokenV2}})
+
+	tests := []struct {
+		name    string
+		props   map[string]interface{}
+		success bool
+	}{
+		{"Invalid prop key", map[string]interface{}{"Priority": "IDVALIMPORTANCES1"}, false},
+		{"Invalid prop value", map[string]interface{}{"IDTAGIMPORTANCES": "high"}, false},
+		{"Valid prop key & value", map[string]interface{}{"IDTAGIMPORTANCES": "IDVALIMPORTANCES1"}, true},
+		{"Empty properties", map[string]interface{}{}, true},
+	}
+	for _, tt := range tests {
+		c.Log(c.TestName()+" ", tt.name)
+		cnt, err := s.localdb.ContainerRequestCreate(ctx, arvados.CreateOptions{
+			Attrs: map[string]interface{}{
+				"command":         []string{"echo", "foo"},
+				"container_image": "arvados/apitestfixture:latest",
+				"cwd":             "/tmp",
+				"environment":     map[string]string{},
+				"mounts": map[string]interface{}{
+					"/out": map[string]interface{}{
+						"kind":     "tmp",
+						"capacity": 1000000,
+					},
+				},
+				"output_path": "/out",
+				"runtime_constraints": map[string]interface{}{
+					"vcpus": 1,
+					"ram":   2,
+				},
+			},
+		})
+		c.Assert(err, check.IsNil)
+		cnt, err = s.localdb.ContainerRequestUpdate(ctx, arvados.UpdateOptions{
+			UUID:   cnt.UUID,
+			Select: []string{"uuid", "properties"},
+			Attrs: map[string]interface{}{
+				"properties": tt.props,
+			}})
+		if tt.success {
+			c.Assert(err, check.IsNil)
+			c.Assert(err, check.IsNil)
+			c.Assert(cnt.Properties, check.DeepEquals, tt.props)
+		} else {
+			c.Assert(err, check.NotNil)
+		}
+	}
+}
diff --git a/lib/controller/localdb/group.go b/lib/controller/localdb/group.go
new file mode 100644
index 000000000..d9617d8bc
--- /dev/null
+++ b/lib/controller/localdb/group.go
@@ -0,0 +1,39 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+package localdb
+
+import (
+	"context"
+
+	"git.arvados.org/arvados.git/sdk/go/arvados"
+)
+
+// GroupCreate defers to railsProxy for everything except vocabulary
+// checking.
+func (conn *Conn) GroupCreate(ctx context.Context, opts arvados.CreateOptions) (arvados.Group, error) {
+	err := conn.checkProperties(opts.Attrs["properties"])
+	if err != nil {
+		return arvados.Group{}, err
+	}
+	resp, err := conn.railsProxy.GroupCreate(ctx, opts)
+	if err != nil {
+		return resp, err
+	}
+	return resp, nil
+}
+
+// GroupUpdate defers to railsProxy for everything except vocabulary
+// checking.
+func (conn *Conn) GroupUpdate(ctx context.Context, opts arvados.UpdateOptions) (arvados.Group, error) {
+	err := conn.checkProperties(opts.Attrs["properties"])
+	if err != nil {
+		return arvados.Group{}, err
+	}
+	resp, err := conn.railsProxy.GroupUpdate(ctx, opts)
+	if err != nil {
+		return resp, err
+	}
+	return resp, nil
+}
diff --git a/lib/controller/localdb/group_test.go b/lib/controller/localdb/group_test.go
new file mode 100644
index 000000000..d6b739c41
--- /dev/null
+++ b/lib/controller/localdb/group_test.go
@@ -0,0 +1,140 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+package localdb
+
+import (
+	"context"
+
+	"git.arvados.org/arvados.git/lib/config"
+	"git.arvados.org/arvados.git/lib/controller/rpc"
+	"git.arvados.org/arvados.git/sdk/go/arvados"
+	"git.arvados.org/arvados.git/sdk/go/arvadostest"
+	"git.arvados.org/arvados.git/sdk/go/auth"
+	"git.arvados.org/arvados.git/sdk/go/ctxlog"
+	check "gopkg.in/check.v1"
+)
+
+var _ = check.Suite(&GroupSuite{})
+
+type GroupSuite struct {
+	cluster  *arvados.Cluster
+	localdb  *Conn
+	railsSpy *arvadostest.Proxy
+}
+
+func (s *GroupSuite) TearDownSuite(c *check.C) {
+	// Undo any changes/additions to the user database so they
+	// don't affect subsequent tests.
+	arvadostest.ResetEnv()
+	c.Check(arvados.NewClientFromEnv().RequestAndDecode(nil, "POST", "database/reset", nil, nil), check.IsNil)
+}
+
+func (s *GroupSuite) SetUpTest(c *check.C) {
+	cfg, err := config.NewLoader(nil, ctxlog.TestLogger(c)).Load()
+	c.Assert(err, check.IsNil)
+	s.cluster, err = cfg.GetCluster("")
+	c.Assert(err, check.IsNil)
+	s.localdb = NewConn(s.cluster)
+	s.railsSpy = arvadostest.NewProxy(c, s.cluster.Services.RailsAPI)
+	*s.localdb.railsProxy = *rpc.NewConn(s.cluster.ClusterID, s.railsSpy.URL, true, rpc.PassthroughTokenProvider)
+}
+
+func (s *GroupSuite) TearDownTest(c *check.C) {
+	s.railsSpy.Close()
+}
+
+func (s *GroupSuite) setUpVocabulary(c *check.C, testVocabulary string) {
+	if testVocabulary == "" {
+		testVocabulary = `{
+			"strict_tags": false,
+			"tags": {
+				"IDTAGIMPORTANCES": {
+					"strict": true,
+					"labels": [{"label": "Importance"}, {"label": "Priority"}],
+					"values": {
+						"IDVALIMPORTANCES1": { "labels": [{"label": "Critical"}, {"label": "Urgent"}, {"label": "High"}] },
+						"IDVALIMPORTANCES2": { "labels": [{"label": "Normal"}, {"label": "Moderate"}] },
+						"IDVALIMPORTANCES3": { "labels": [{"label": "Low"}] }
+					}
+				}
+			}
+		}`
+	}
+	voc, err := arvados.NewVocabulary([]byte(testVocabulary))
+	c.Assert(err, check.IsNil)
+	c.Assert(voc.Validate(), check.IsNil)
+	s.cluster.API.Vocabulary = voc
+}
+
+func (s *GroupSuite) TestGroupCreateWithProperties(c *check.C) {
+	s.setUpVocabulary(c, "")
+	ctx := auth.NewContext(context.Background(), &auth.Credentials{Tokens: []string{arvadostest.ActiveTokenV2}})
+
+	tests := []struct {
+		name    string
+		props   map[string]interface{}
+		success bool
+	}{
+		{"Invalid prop key", map[string]interface{}{"Priority": "IDVALIMPORTANCES1"}, false},
+		{"Invalid prop value", map[string]interface{}{"IDTAGIMPORTANCES": "high"}, false},
+		{"Valid prop key & value", map[string]interface{}{"IDTAGIMPORTANCES": "IDVALIMPORTANCES1"}, true},
+		{"Empty properties", map[string]interface{}{}, true},
+	}
+	for _, tt := range tests {
+		c.Log(c.TestName()+" ", tt.name)
+
+		grp, err := s.localdb.GroupCreate(ctx, arvados.CreateOptions{
+			Select: []string{"uuid", "properties"},
+			Attrs: map[string]interface{}{
+				"group_class": "project",
+				"properties":  tt.props,
+			}})
+		if tt.success {
+			c.Assert(err, check.IsNil)
+			c.Assert(err, check.IsNil)
+			c.Assert(grp.Properties, check.DeepEquals, tt.props)
+		} else {
+			c.Assert(err, check.NotNil)
+		}
+	}
+}
+
+func (s *GroupSuite) TestGroupUpdateWithProperties(c *check.C) {
+	s.setUpVocabulary(c, "")
+	ctx := auth.NewContext(context.Background(), &auth.Credentials{Tokens: []string{arvadostest.ActiveTokenV2}})
+
+	tests := []struct {
+		name    string
+		props   map[string]interface{}
+		success bool
+	}{
+		{"Invalid prop key", map[string]interface{}{"Priority": "IDVALIMPORTANCES1"}, false},
+		{"Invalid prop value", map[string]interface{}{"IDTAGIMPORTANCES": "high"}, false},
+		{"Valid prop key & value", map[string]interface{}{"IDTAGIMPORTANCES": "IDVALIMPORTANCES1"}, true},
+		{"Empty properties", map[string]interface{}{}, true},
+	}
+	for _, tt := range tests {
+		c.Log(c.TestName()+" ", tt.name)
+		grp, err := s.localdb.GroupCreate(ctx, arvados.CreateOptions{
+			Attrs: map[string]interface{}{
+				"group_class": "project",
+			},
+		})
+		c.Assert(err, check.IsNil)
+		grp, err = s.localdb.GroupUpdate(ctx, arvados.UpdateOptions{
+			UUID:   grp.UUID,
+			Select: []string{"uuid", "properties"},
+			Attrs: map[string]interface{}{
+				"properties": tt.props,
+			}})
+		if tt.success {
+			c.Assert(err, check.IsNil)
+			c.Assert(err, check.IsNil)
+			c.Assert(grp.Properties, check.DeepEquals, tt.props)
+		} else {
+			c.Assert(err, check.NotNil)
+		}
+	}
+}

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


hooks/post-receive
-- 




More information about the arvados-commits mailing list