X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/9f57bcbab5b244365ca4d0ece8490d7540c72b86..dc021c3b57dcdebe464c148d55f9990a74e8246b:/lib/cloud/azure/azure_test.go diff --git a/lib/cloud/azure/azure_test.go b/lib/cloud/azure/azure_test.go index 850a3fb427..94af0b9a26 100644 --- a/lib/cloud/azure/azure_test.go +++ b/lib/cloud/azure/azure_test.go @@ -5,7 +5,7 @@ // // How to manually run individual tests against the real cloud: // -// $ go test -v git.curoverse.com/arvados.git/lib/cloud/azure -live-azure-cfg azconfig.yml -check.f=TestCreate +// $ go test -v git.arvados.org/arvados.git/lib/cloud/azure -live-azure-cfg azconfig.yml -check.f=TestCreate // // Tests should be run individually and in the order they are listed in the file: // @@ -25,6 +25,7 @@ // StorageAccount: example // BlobContainer: vhds // DeleteDanglingResourcesAfter: 20s +// AdminUsername: crunch package azure @@ -38,19 +39,20 @@ import ( "net" "net/http" "os" + "strings" "testing" "time" - "git.curoverse.com/arvados.git/lib/cloud" - "git.curoverse.com/arvados.git/sdk/go/arvados" - "git.curoverse.com/arvados.git/sdk/go/config" + "git.arvados.org/arvados.git/lib/cloud" + "git.arvados.org/arvados.git/lib/dispatchcloud/test" + "git.arvados.org/arvados.git/sdk/go/arvados" + "git.arvados.org/arvados.git/sdk/go/config" "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2018-06-01/compute" "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2018-06-01/network" "github.com/Azure/azure-sdk-for-go/storage" "github.com/Azure/go-autorest/autorest" "github.com/Azure/go-autorest/autorest/azure" "github.com/Azure/go-autorest/autorest/to" - "github.com/jmcvetta/randutil" "github.com/sirupsen/logrus" "golang.org/x/crypto/ssh" check "gopkg.in/check.v1" @@ -65,9 +67,9 @@ type AzureInstanceSetSuite struct{} var _ = check.Suite(&AzureInstanceSetSuite{}) -type VirtualMachinesClientStub struct{} +const testNamePrefix = "compute-test123-" -var testKey = []byte(`ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDLQS1ExT2+WjA0d/hntEAyAtgeN1W2ik2QX8c2zO6HjlPHWXL92r07W0WMuDib40Pcevpi1BXeBWXA9ZB5KKMJB+ukaAu22KklnQuUmNvk6ZXnPKSkGxuCYvPQb08WhHf3p1VxiKfP3iauedBDM4x9/bkJohlBBQiFXzNUcQ+a6rKiMzmJN2gbL8ncyUzc+XQ5q4JndTwTGtOlzDiGOc9O4z5Dd76wtAVJneOuuNpwfFRVHThpJM6VThpCZOnl8APaceWXKeuwOuCae3COZMz++xQfxOfZ9Z8aIwo+TlQhsRaNfZ4Vjrop6ej8dtfZtgUFKfbXEOYaHrGrWGotFDTD example@example`) +type VirtualMachinesClientStub struct{} func (*VirtualMachinesClientStub) createOrUpdate(ctx context.Context, resourceGroupName string, @@ -105,6 +107,16 @@ func (*InterfacesClientStub) listComplete(ctx context.Context, resourceGroupName return network.InterfaceListResultIterator{}, nil } +type BlobContainerStub struct{} + +func (*BlobContainerStub) GetBlobReference(name string) *storage.Blob { + return nil +} + +func (*BlobContainerStub) ListBlobs(params storage.ListBlobsParameters) (storage.BlobListResponse, error) { + return storage.BlobListResponse{}, nil +} + type testConfig struct { ImageIDForTestSuite string DriverParameters json.RawMessage @@ -132,7 +144,7 @@ func GetInstanceSet() (cloud.InstanceSet, cloud.ImageID, arvados.Cluster, error) return nil, cloud.ImageID(""), cluster, err } - ap, err := newAzureInstanceSet(exampleCfg.DriverParameters, "test123", logrus.StandardLogger()) + ap, err := newAzureInstanceSet(exampleCfg.DriverParameters, "test123", nil, logrus.StandardLogger()) return ap, cloud.ImageID(exampleCfg.ImageIDForTestSuite), cluster, err } ap := azureInstanceSet{ @@ -140,7 +152,7 @@ func GetInstanceSet() (cloud.InstanceSet, cloud.ImageID, arvados.Cluster, error) BlobContainer: "vhds", }, dispatcherID: "test123", - namePrefix: "compute-test123-", + namePrefix: testNamePrefix, logger: logrus.StandardLogger(), deleteNIC: make(chan string), deleteBlob: make(chan storage.Blob), @@ -148,6 +160,7 @@ func GetInstanceSet() (cloud.InstanceSet, cloud.ImageID, arvados.Cluster, error) ap.ctx, ap.stopFunc = context.WithCancel(context.Background()) ap.vmClient = &VirtualMachinesClientStub{} ap.netClient = &InterfacesClientStub{} + ap.blobcont = &BlobContainerStub{} return &ap, cloud.ImageID("blob"), cluster, nil } @@ -157,21 +170,19 @@ func (*AzureInstanceSetSuite) TestCreate(c *check.C) { c.Fatal("Error making provider", err) } - pk, _, _, _, err := ssh.ParseAuthorizedKey(testKey) - c.Assert(err, check.IsNil) - - nodetoken, err := randutil.String(40, "abcdefghijklmnopqrstuvwxyz0123456789") + pk, _ := test.LoadTestKey(c, "../../dispatchcloud/test/sshkey_dispatch") c.Assert(err, check.IsNil) inst, err := ap.Create(cluster.InstanceTypes["tiny"], img, map[string]string{ - "node-token": nodetoken}, - pk) + "TestTagName": "test tag value", + }, "umask 0600; echo -n test-file-data >/var/run/test-file", pk) c.Assert(err, check.IsNil) - tg := inst.Tags() - log.Printf("Result %v %v %v", inst.String(), inst.Address(), tg) + tags := inst.Tags() + c.Check(tags["TestTagName"], check.Equals, "test tag value") + c.Logf("inst.String()=%v Address()=%v Tags()=%v", inst.String(), inst.Address(), tags) } @@ -220,7 +231,7 @@ func (*AzureInstanceSetSuite) TestDestroyInstances(c *check.C) { l, err := ap.Instances(nil) c.Assert(err, check.IsNil) - for _, i := range l { + for _, i := range filterInstances(c, l) { c.Check(i.Destroy(), check.IsNil) } } @@ -279,17 +290,20 @@ func (*AzureInstanceSetSuite) TestSetTags(c *check.C) { if err != nil { c.Fatal("Error making provider", err) } + l, err := ap.Instances(nil) c.Assert(err, check.IsNil) - + l = filterInstances(c, l) if len(l) > 0 { err = l[0].SetTags(map[string]string{"foo": "bar"}) if err != nil { c.Fatal("Error setting tags", err) } } + l, err = ap.Instances(nil) c.Assert(err, check.IsNil) + l = filterInstances(c, l) if len(l) > 0 { tg := l[0].Tags() @@ -304,21 +318,25 @@ func (*AzureInstanceSetSuite) TestSSH(c *check.C) { } l, err := ap.Instances(nil) c.Assert(err, check.IsNil) + l = filterInstances(c, l) if len(l) > 0 { - sshclient, err := SetupSSHClient(c, l[0]) c.Assert(err, check.IsNil) + defer sshclient.Conn.Close() sess, err := sshclient.NewSession() c.Assert(err, check.IsNil) - - out, err := sess.Output("cat /home/crunch/node-token") + defer sess.Close() + _, err = sess.Output("find /var/run/test-file -maxdepth 0 -user root -perm 0600") c.Assert(err, check.IsNil) - log.Printf("%v", string(out)) - - sshclient.Conn.Close() + sess, err = sshclient.NewSession() + c.Assert(err, check.IsNil) + defer sess.Close() + out, err := sess.Output("sudo cat /var/run/test-file") + c.Assert(err, check.IsNil) + c.Check(string(out), check.Equals, "test-file-data") } } @@ -361,3 +379,15 @@ func SetupSSHClient(c *check.C, inst cloud.Instance) (*ssh.Client, error) { return client, nil } + +func filterInstances(c *check.C, instances []cloud.Instance) []cloud.Instance { + var r []cloud.Instance + for _, i := range instances { + if !strings.HasPrefix(i.String(), testNamePrefix) { + c.Logf("ignoring instance %s", i) + continue + } + r = append(r, i) + } + return r +}