X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/fb9f29b33a380616211a56973045dac1254977ee..2e370ca1df7e1f99df5a08de40b8826d8cbc6349:/lib/cloud/azure/azure_test.go diff --git a/lib/cloud/azure/azure_test.go b/lib/cloud/azure/azure_test.go index 96bfb4fefb..b6aa9a16b6 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: // @@ -39,14 +39,15 @@ import ( "net" "net/http" "os" + "strings" "testing" "time" - "git.curoverse.com/arvados.git/lib/cloud" - "git.curoverse.com/arvados.git/lib/dispatchcloud/test" - "git.curoverse.com/arvados.git/sdk/go/arvados" - "git.curoverse.com/arvados.git/sdk/go/config" - "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2018-06-01/compute" + "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/2019-07-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" @@ -66,6 +67,8 @@ type AzureInstanceSetSuite struct{} var _ = check.Suite(&AzureInstanceSetSuite{}) +const testNamePrefix = "compute-test123-" + type VirtualMachinesClientStub struct{} func (*VirtualMachinesClientStub) createOrUpdate(ctx context.Context, @@ -124,7 +127,7 @@ var live = flag.String("live-azure-cfg", "", "Test with real azure API, provide func GetInstanceSet() (cloud.InstanceSet, cloud.ImageID, arvados.Cluster, error) { cluster := arvados.Cluster{ InstanceTypes: arvados.InstanceTypeMap(map[string]arvados.InstanceType{ - "tiny": arvados.InstanceType{ + "tiny": { Name: "tiny", ProviderType: "Standard_D1_v2", VCPUs: 1, @@ -133,6 +136,15 @@ func GetInstanceSet() (cloud.InstanceSet, cloud.ImageID, arvados.Cluster, error) Price: .02, Preemptible: false, }, + "tinyp": { + Name: "tiny", + ProviderType: "Standard_D1_v2", + VCPUs: 1, + RAM: 4000000000, + Scratch: 10000000000, + Price: .002, + Preemptible: true, + }, })} if *live != "" { var exampleCfg testConfig @@ -141,7 +153,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{ @@ -149,10 +161,11 @@ 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), + deleteDisk: make(chan compute.Disk), } ap.ctx, ap.stopFunc = context.WithCancel(context.Background()) ap.vmClient = &VirtualMachinesClientStub{} @@ -181,6 +194,17 @@ func (*AzureInstanceSetSuite) TestCreate(c *check.C) { c.Check(tags["TestTagName"], check.Equals, "test tag value") c.Logf("inst.String()=%v Address()=%v Tags()=%v", inst.String(), inst.Address(), tags) + instPreemptable, err := ap.Create(cluster.InstanceTypes["tinyp"], + img, map[string]string{ + "TestTagName": "test tag value", + }, "umask 0600; echo -n test-file-data >/var/run/test-file", pk) + + c.Assert(err, check.IsNil) + + tags = instPreemptable.Tags() + c.Check(tags["TestTagName"], check.Equals, "test tag value") + c.Logf("instPreemptable.String()=%v Address()=%v Tags()=%v", instPreemptable.String(), instPreemptable.Address(), tags) + } func (*AzureInstanceSetSuite) TestListInstances(c *check.C) { @@ -228,7 +252,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) } } @@ -255,7 +279,7 @@ func (*AzureInstanceSetSuite) TestWrapError(c *check.C) { DetailedError: autorest.DetailedError{ Response: &http.Response{ StatusCode: 429, - Header: map[string][]string{"Retry-After": []string{"123"}}, + Header: map[string][]string{"Retry-After": {"123"}}, }, }, ServiceError: &azure.ServiceError{}, @@ -287,17 +311,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() @@ -312,6 +339,7 @@ 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]) @@ -372,3 +400,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 +}