1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
12 "git.curoverse.com/arvados.git/lib/cloud"
13 "git.curoverse.com/arvados.git/lib/dispatchcloud/test"
14 "git.curoverse.com/arvados.git/sdk/go/arvados"
15 "git.curoverse.com/arvados.git/sdk/go/ctxlog"
16 "golang.org/x/crypto/ssh"
17 check "gopkg.in/check.v1"
20 // Gocheck boilerplate
21 func Test(t *testing.T) {
25 var _ = check.Suite(&TesterSuite{})
27 type TesterSuite struct {
28 stubDriver *test.StubDriver
29 cluster *arvados.Cluster
34 func (s *TesterSuite) SetUpTest(c *check.C) {
35 pubkey, privkey := test.LoadTestKey(c, "../../dispatchcloud/test/sshkey_dispatch")
36 _, privhostkey := test.LoadTestKey(c, "../../dispatchcloud/test/sshkey_vm")
37 s.stubDriver = &test.StubDriver{
39 AuthorizedKeys: []ssh.PublicKey{pubkey},
40 ErrorRateDestroy: 0.1,
41 MinTimeBetweenCreateCalls: time.Millisecond,
43 tagKeyPrefix := "tagprefix:"
44 s.cluster = &arvados.Cluster{
45 ManagementToken: "test-management-token",
46 Containers: arvados.ContainersConfig{
47 CloudVMs: arvados.CloudVMsConfig{
48 SyncInterval: arvados.Duration(10 * time.Millisecond),
49 TimeoutBooting: arvados.Duration(150 * time.Millisecond),
50 TimeoutProbe: arvados.Duration(15 * time.Millisecond),
51 ProbeInterval: arvados.Duration(5 * time.Millisecond),
52 ResourceTags: map[string]string{"testtag": "test value"},
55 InstanceTypes: arvados.InstanceTypeMap{
56 test.InstanceType(1).Name: test.InstanceType(1),
57 test.InstanceType(2).Name: test.InstanceType(2),
58 test.InstanceType(3).Name: test.InstanceType(3),
62 Logger: ctxlog.New(&s.log, "text", "info"),
63 Tags: cloud.SharedResourceTags{"testtagkey": "testtagvalue"},
64 TagKeyPrefix: tagKeyPrefix,
65 SetID: cloud.InstanceSetID("test-instance-set-id"),
66 ProbeInterval: 5 * time.Millisecond,
67 SyncInterval: 10 * time.Millisecond,
68 TimeoutBooting: 150 * time.Millisecond,
70 DriverParameters: nil,
71 InstanceType: test.InstanceType(2),
72 ImageID: "test-image-id",
74 BootProbeCommand: "crunch-run --list",
79 func (s *TesterSuite) TestSuccess(c *check.C) {
80 s.tester.Logger = ctxlog.TestLogger(c)
82 c.Check(ok, check.Equals, true)
85 func (s *TesterSuite) TestBootFail(c *check.C) {
86 s.tester.BootProbeCommand = "falsey"
88 c.Check(ok, check.Equals, false)
89 c.Check(s.log.String(), check.Matches, `(?ms).*\\"falsey\\": command not found.*`)
92 func (s *TesterSuite) TestShellCommandFail(c *check.C) {
93 s.tester.ShellCommand = "falsey"
95 c.Check(ok, check.Equals, false)
96 c.Check(s.log.String(), check.Matches, `(?ms).*\\"falsey\\": command not found.*`)