1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
6 // How to manually run individual tests against the real cloud:
8 // $ go test -v git.curoverse.com/arvados.git/lib/cloud/ec2 -live-ec2-cfg ec2config.yml -check.f=TestCreate
10 // Tests should be run individually and in the order they are listed in the file:
12 // Example azconfig.yml:
14 // ImageIDForTestSuite: ami-xxxxxxxxxxxxxxxxx
16 // AccessKeyID: XXXXXXXXXXXXXX
17 // SecretAccessKey: xxxxxxxxxxxxxxxxxxxx
19 // SecurityGroupId: sg-xxxxxxxx
20 // SubnetId: subnet-xxxxxxxx
21 // AdminUsername: crunch
31 "git.curoverse.com/arvados.git/lib/cloud"
32 "git.curoverse.com/arvados.git/sdk/go/arvados"
33 "git.curoverse.com/arvados.git/sdk/go/config"
34 "github.com/sirupsen/logrus"
35 "golang.org/x/crypto/ssh"
36 check "gopkg.in/check.v1"
39 var live = flag.String("live-ec2-cfg", "", "Test with real EC2 API, provide config file")
41 // Gocheck boilerplate
42 func Test(t *testing.T) {
46 type EC2InstanceSetSuite struct{}
48 var _ = check.Suite(&EC2InstanceSetSuite{})
50 type testConfig struct {
51 ImageIDForTestSuite string
52 DriverParameters json.RawMessage
55 func GetInstanceSet() (cloud.InstanceSet, cloud.ImageID, arvados.Cluster, error) {
56 cluster := arvados.Cluster{
57 InstanceTypes: arvados.InstanceTypeMap(map[string]arvados.InstanceType{
58 "tiny": arvados.InstanceType{
60 ProviderType: "m1.small",
69 var exampleCfg testConfig
70 err := config.LoadFile(&exampleCfg, *live)
72 return nil, cloud.ImageID(""), cluster, err
75 ap, err := newEC2InstanceSet(exampleCfg.DriverParameters, "test123", logrus.StandardLogger())
76 return ap, cloud.ImageID(exampleCfg.ImageIDForTestSuite), cluster, err
79 ec2config: ec2InstanceSetConfig{},
80 dispatcherID: "test123",
81 logger: logrus.StandardLogger(),
83 return &ap, cloud.ImageID("blob"), cluster, nil
86 var testKey = []byte(`ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDLQS1ExT2+WjA0d/hntEAyAtgeN1W2ik2QX8c2zO6HjlPHWXL92r07W0WMuDib40Pcevpi1BXeBWXA9ZB5KKMJB+ukaAu22KklnQuUmNvk6ZXnPKSkGxuCYvPQb08WhHf3p1VxiKfP3iauedBDM4x9/bkJohlBBQiFXzNUcQ+a6rKiMzmJN2gbL8ncyUzc+XQ5q4JndTwTGtOlzDiGOc9O4z5Dd76wtAVJneOuuNpwfFRVHThpJM6VThpCZOnl8APaceWXKeuwOuCae3COZMz++xQfxOfZ9Z8aIwo+TlQhsRaNfZ4Vjrop6ej8dtfZtgUFKfbXEOYaHrGrWGotFDTD example@example`)
88 func (*EC2InstanceSetSuite) TestCreate(c *check.C) {
89 ap, img, cluster, err := GetInstanceSet()
91 c.Fatal("Error making provider", err)
94 pk, _, _, _, err := ssh.ParseAuthorizedKey(testKey)
95 c.Assert(err, check.IsNil)
97 inst, err := ap.Create(cluster.InstanceTypes["tiny"],
98 img, map[string]string{
99 "TestTagName": "test tag value",
100 }, "umask 0600; echo -n test-file-data >/var/run/test-file", pk)
102 c.Assert(err, check.IsNil)
105 c.Check(tags["TestTagName"], check.Equals, "test tag value")
106 c.Logf("inst.String()=%v Address()=%v Tags()=%v", inst.String(), inst.Address(), tags)
110 func (*EC2InstanceSetSuite) TestListInstances(c *check.C) {
111 ap, _, _, err := GetInstanceSet()
113 c.Fatal("Error making provider", err)
116 l, err := ap.Instances(nil)
118 c.Assert(err, check.IsNil)
120 for _, i := range l {
122 log.Printf("%v %v %v", i.String(), i.Address(), tg)
126 func (*EC2InstanceSetSuite) TestDestroyInstances(c *check.C) {
127 ap, _, _, err := GetInstanceSet()
129 c.Fatal("Error making provider", err)
132 l, err := ap.Instances(nil)
133 c.Assert(err, check.IsNil)
135 for _, i := range l {
136 c.Check(i.Destroy(), check.IsNil)