[ARVADOS] created: 2.1.0-2329-g920837d65

Git user git at public.arvados.org
Fri Apr 15 19:27:52 UTC 2022


        at  920837d6511e94cf7e2238bbe9f122fe3f1771a4 (commit)


commit 920837d6511e94cf7e2238bbe9f122fe3f1771a4
Author: Tom Clegg <tom at curii.com>
Date:   Fri Apr 15 15:27:38 2022 -0400

    15370: Stub loopback driver.
    
    Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tom at curii.com>

diff --git a/lib/cloud/loopback/loopback.go b/lib/cloud/loopback/loopback.go
new file mode 100644
index 000000000..e2854832d
--- /dev/null
+++ b/lib/cloud/loopback/loopback.go
@@ -0,0 +1,68 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+package loopback
+
+import (
+	"encoding/json"
+	"errors"
+
+	"git.arvados.org/arvados.git/lib/cloud"
+	"git.arvados.org/arvados.git/sdk/go/arvados"
+	"github.com/sirupsen/logrus"
+	"golang.org/x/crypto/ssh"
+)
+
+// Driver is the loopback implementation of the cloud.Driver interface.
+var Driver = cloud.DriverFunc(newInstanceSet)
+
+var errUnimplemented = errors.New("function not implemented by loopback driver")
+
+type instanceSet struct {
+	instanceSetID cloud.InstanceSetID
+	logger        logrus.FieldLogger
+	config        struct{}
+}
+
+func newInstanceSet(config json.RawMessage, instanceSetID cloud.InstanceSetID, _ cloud.SharedResourceTags, logger logrus.FieldLogger) (cloud.InstanceSet, error) {
+	is := &instanceSet{
+		instanceSetID: instanceSetID,
+		logger:        logger,
+	}
+	err := json.Unmarshal(config, &is.config)
+	if err != nil {
+		return nil, err
+	}
+	return is, nil
+}
+
+func (*instanceSet) Create(arvados.InstanceType, cloud.ImageID, cloud.InstanceTags, cloud.InitCommand, ssh.PublicKey) (cloud.Instance, error) {
+	return nil, errUnimplemented
+}
+
+func (*instanceSet) Instances(cloud.InstanceTags) ([]cloud.Instance, error) {
+	return nil, nil
+}
+
+func (*instanceSet) Stop() {}
+
+type instance struct {
+	adminUser    string
+	sshAddr      string
+	providerType string
+	tags         cloud.InstanceTags
+}
+
+func (i *instance) ID() cloud.InstanceID     { return "localhost" }
+func (i *instance) String() string           { return "localhost" }
+func (i *instance) ProviderType() string     { return i.providerType }
+func (i *instance) Tags() cloud.InstanceTags { return i.tags }
+func (i *instance) SetTags(tags cloud.InstanceTags) error {
+	i.tags = tags
+	return nil
+}
+func (i *instance) Destroy() error                                 { return errUnimplemented }
+func (i *instance) Address() string                                { return i.sshAddr }
+func (i *instance) RemoteUser() string                             { return i.adminUser }
+func (i *instance) VerifyHostKey(ssh.PublicKey, *ssh.Client) error { return nil }
diff --git a/lib/cloud/loopback/loopback_test.go b/lib/cloud/loopback/loopback_test.go
new file mode 100644
index 000000000..13ce2e1cc
--- /dev/null
+++ b/lib/cloud/loopback/loopback_test.go
@@ -0,0 +1,38 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+package loopback
+
+import (
+	"encoding/json"
+	"testing"
+
+	"git.arvados.org/arvados.git/lib/cloud"
+	"git.arvados.org/arvados.git/sdk/go/arvados"
+	"git.arvados.org/arvados.git/sdk/go/ctxlog"
+	"golang.org/x/crypto/ssh"
+	check "gopkg.in/check.v1"
+)
+
+func Test(t *testing.T) {
+	check.TestingT(t)
+}
+
+type suite struct{}
+
+var _ = check.Suite(&suite{})
+
+func (*suite) TestCreateListExecDestroy(c *check.C) {
+	logger := ctxlog.TestLogger(c)
+	is, err := Driver.InstanceSet(json.RawMessage("{}"), "testInstanceSetID", cloud.SharedResourceTags{"sharedTag": "sharedTagValue"}, logger)
+	c.Assert(err, check.IsNil)
+	inst, err := is.Create(arvados.InstanceType{}, "testImageID", cloud.InstanceTags{"instanceTag": "instanceTagValue"}, "testInitCommand", ssh.PublicKey(nil))
+	c.Assert(err, check.IsNil)
+	c.Check(inst.String(), check.Equals, "localhost")
+	list, err := is.Instances(nil)
+	c.Assert(err, check.IsNil)
+	if c.Check(list, check.HasLen, 1) {
+		c.Check(list[0].String(), check.Equals, "localhost")
+	}
+}
diff --git a/lib/config/config.default.yml b/lib/config/config.default.yml
index 651238981..c1d477aa4 100644
--- a/lib/config/config.default.yml
+++ b/lib/config/config.default.yml
@@ -1268,7 +1268,9 @@ Clusters:
         # need to be detected and cleaned up manually.
         TagKeyPrefix: Arvados
 
-        # Cloud driver: "azure" (Microsoft Azure) or "ec2" (Amazon AWS).
+        # Cloud driver: "azure" (Microsoft Azure), "ec2" (Amazon AWS),
+        # or "loopback" (run containers on dispatch host for testing
+        # purposes).
         Driver: ec2
 
         # Cloud-specific driver parameters.
diff --git a/lib/dispatchcloud/driver.go b/lib/dispatchcloud/driver.go
index 5fcc0903f..93515defb 100644
--- a/lib/dispatchcloud/driver.go
+++ b/lib/dispatchcloud/driver.go
@@ -11,6 +11,7 @@ import (
 	"git.arvados.org/arvados.git/lib/cloud"
 	"git.arvados.org/arvados.git/lib/cloud/azure"
 	"git.arvados.org/arvados.git/lib/cloud/ec2"
+	"git.arvados.org/arvados.git/lib/cloud/loopback"
 	"git.arvados.org/arvados.git/sdk/go/arvados"
 	"github.com/prometheus/client_golang/prometheus"
 	"github.com/sirupsen/logrus"
@@ -21,8 +22,9 @@ import (
 // Clusters.*.Containers.CloudVMs.Driver configuration values
 // correspond to keys in this map.
 var Drivers = map[string]cloud.Driver{
-	"azure": azure.Driver,
-	"ec2":   ec2.Driver,
+	"azure":    azure.Driver,
+	"ec2":      ec2.Driver,
+	"loopback": loopback.Driver,
 }
 
 func newInstanceSet(cluster *arvados.Cluster, setID cloud.InstanceSetID, logger logrus.FieldLogger, reg *prometheus.Registry) (cloud.InstanceSet, error) {

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


hooks/post-receive
-- 




More information about the arvados-commits mailing list