14745: Makes the azure driver its own package
authorEric Biagiotti <ebiagiotti@veritasgenetcs.com>
Mon, 11 Feb 2019 14:13:11 +0000 (09:13 -0500)
committerEric Biagiotti <ebiagiotti@veritasgenetcs.com>
Mon, 11 Feb 2019 14:13:11 +0000 (09:13 -0500)
Arvados-DCO-1.1-Signed-off-by: Eric Biagiotti <eric.biagiotti@gmail.com>

build/run-tests.sh
lib/cloud/azure/azure.go [moved from lib/cloud/azure.go with 97% similarity]
lib/cloud/azure/azure_test.go [moved from lib/cloud/azure_test.go with 95% similarity]
lib/dispatchcloud/driver.go

index 96e6aea72ca10615c56d9734090dc7b716e024ec..9919c3e1751766892b72bcc806170b61f43e5999 100755 (executable)
@@ -77,6 +77,7 @@ lib/cmd
 lib/controller
 lib/crunchstat
 lib/cloud
+lib/cloud/azure
 lib/dispatchcloud
 lib/dispatchcloud/container
 lib/dispatchcloud/scheduler
@@ -932,6 +933,7 @@ gostuff=(
     lib/controller
     lib/crunchstat
     lib/cloud
+    lib/cloud/azure
     lib/dispatchcloud
     lib/dispatchcloud/container
     lib/dispatchcloud/scheduler
similarity index 97%
rename from lib/cloud/azure.go
rename to lib/cloud/azure/azure.go
index a194b33180b231cfb74964b11253d5aa6f8d0667..5bc7ccfd44f16de94575841a5783558f7fa85224 100644 (file)
@@ -2,7 +2,7 @@
 //
 // SPDX-License-Identifier: AGPL-3.0
 
-package cloud
+package azure
 
 import (
        "context"
@@ -15,6 +15,7 @@ import (
        "sync"
        "time"
 
+       "git.curoverse.com/arvados.git/lib/cloud"
        "git.curoverse.com/arvados.git/sdk/go/arvados"
        "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"
@@ -202,7 +203,7 @@ type AzureInstanceSet struct {
        logger            logrus.FieldLogger
 }
 
-func NewAzureInstanceSet(config map[string]interface{}, dispatcherID InstanceSetID, logger logrus.FieldLogger) (prv InstanceSet, err error) {
+func NewAzureInstanceSet(config map[string]interface{}, dispatcherID cloud.InstanceSetID, logger logrus.FieldLogger) (prv cloud.InstanceSet, err error) {
        azcfg := AzureInstanceSetConfig{}
        if err = mapstructure.Decode(config, &azcfg); err != nil {
                return nil, err
@@ -304,9 +305,9 @@ func (az *AzureInstanceSet) setup(azcfg AzureInstanceSetConfig, dispatcherID str
 
 func (az *AzureInstanceSet) Create(
        instanceType arvados.InstanceType,
-       imageId ImageID,
-       newTags InstanceTags,
-       publicKey ssh.PublicKey) (Instance, error) {
+       imageId cloud.ImageID,
+       newTags cloud.InstanceTags,
+       publicKey ssh.PublicKey) (cloud.Instance, error) {
 
        az.stopWg.Add(1)
        defer az.stopWg.Done()
@@ -430,7 +431,7 @@ echo '%s-%s' > /home/crunch/node-token`, name, newTags["node-token"])))
        }, nil
 }
 
-func (az *AzureInstanceSet) Instances(InstanceTags) ([]Instance, error) {
+func (az *AzureInstanceSet) Instances(cloud.InstanceTags) ([]cloud.Instance, error) {
        az.stopWg.Add(1)
        defer az.stopWg.Done()
 
@@ -444,7 +445,7 @@ func (az *AzureInstanceSet) Instances(InstanceTags) ([]Instance, error) {
                return nil, WrapAzureError(err)
        }
 
-       instances := make([]Instance, 0)
+       instances := make([]cloud.Instance, 0)
 
        for ; result.NotDone(); err = result.Next() {
                if err != nil {
@@ -564,8 +565,8 @@ type AzureInstance struct {
        vm       compute.VirtualMachine
 }
 
-func (ai *AzureInstance) ID() InstanceID {
-       return InstanceID(*ai.vm.ID)
+func (ai *AzureInstance) ID() cloud.InstanceID {
+       return cloud.InstanceID(*ai.vm.ID)
 }
 
 func (ai *AzureInstance) String() string {
@@ -576,7 +577,7 @@ func (ai *AzureInstance) ProviderType() string {
        return string(ai.vm.VirtualMachineProperties.HardwareProfile.VMSize)
 }
 
-func (ai *AzureInstance) SetTags(newTags InstanceTags) error {
+func (ai *AzureInstance) SetTags(newTags cloud.InstanceTags) error {
        ai.provider.stopWg.Add(1)
        defer ai.provider.stopWg.Done()
 
@@ -605,7 +606,7 @@ func (ai *AzureInstance) SetTags(newTags InstanceTags) error {
        return nil
 }
 
-func (ai *AzureInstance) Tags() InstanceTags {
+func (ai *AzureInstance) Tags() cloud.InstanceTags {
        tags := make(map[string]string)
 
        for k, v := range ai.vm.Tags {
similarity index 95%
rename from lib/cloud/azure_test.go
rename to lib/cloud/azure/azure_test.go
index f74688bb180c98cb867eba92ce619a6f0f21b30e..b496d3b3fb732d50885271411d12e16696b78c58 100644 (file)
@@ -24,7 +24,7 @@
 // delete_dangling_resources_after: 20
 // authorized_key: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDLQS1ExT2+WjA0d/hntEAyAtgeN1W2ik2QX8c2zO6HjlPHWXL92r07W0WMuDib40Pcevpi1BXeBWXA9ZB5KKMJB+ukaAu22KklnQuUmNvk6ZXnPKSkGxuCYvPQb08WhHf3p1VxiKfP3iauedBDM4x9/bkJohlBBQiFXzNUcQ+a6rKiMzmJN2gbL8ncyUzc+XQ5q4JndTwTGtOlzDiGOc9O4z5Dd76wtAVJneOuuNpwfFRVHThpJM6VThpCZOnl8APaceWXKeuwOuCae3COZMz++xQfxOfZ9Z8aIwo+TlQhsRaNfZ4Vjrop6ej8dtfZtgUFKfbXEOYaHrGrWGotFDTD example@example"
 
-package cloud
+package azure
 
 import (
        "context"
@@ -37,6 +37,7 @@ import (
        "os"
        "time"
 
+       "git.curoverse.com/arvados.git/lib/cloud"
        "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"
@@ -97,7 +98,7 @@ func (*InterfacesClientStub) ListComplete(ctx context.Context, resourceGroupName
 
 var live = flag.String("live-azure-cfg", "", "Test with real azure API, provide config file")
 
-func GetInstanceSet() (InstanceSet, ImageID, arvados.Cluster, error) {
+func GetInstanceSet() (cloud.InstanceSet, cloud.ImageID, arvados.Cluster, error) {
        cluster := arvados.Cluster{
                InstanceTypes: arvados.InstanceTypeMap(map[string]arvados.InstanceType{
                        "tiny": arvados.InstanceType{
@@ -114,10 +115,10 @@ func GetInstanceSet() (InstanceSet, ImageID, arvados.Cluster, error) {
                cfg := make(map[string]interface{})
                err := config.LoadFile(&cfg, *live)
                if err != nil {
-                       return nil, ImageID(""), cluster, err
+                       return nil, cloud.ImageID(""), cluster, err
                }
                ap, err := NewAzureInstanceSet(cfg, "test123", logrus.StandardLogger())
-               return ap, ImageID(cfg["image"].(string)), cluster, err
+               return ap, cloud.ImageID(cfg["image"].(string)), cluster, err
        } else {
                ap := AzureInstanceSet{
                        azconfig: AzureInstanceSetConfig{
@@ -132,7 +133,7 @@ func GetInstanceSet() (InstanceSet, ImageID, arvados.Cluster, error) {
                ap.ctx, ap.stopFunc = context.WithCancel(context.Background())
                ap.vmClient = &VirtualMachinesClientStub{}
                ap.netClient = &InterfacesClientStub{}
-               return &ap, ImageID("blob"), cluster, nil
+               return &ap, cloud.ImageID("blob"), cluster, nil
        }
 }
 
@@ -239,7 +240,7 @@ func (*AzureInstanceSetSuite) TestWrapError(c *check.C) {
                },
        }
        wrapped := WrapAzureError(retryError)
-       _, ok := wrapped.(RateLimitError)
+       _, ok := wrapped.(cloud.RateLimitError)
        c.Check(ok, check.Equals, true)
 
        quotaError := autorest.DetailedError{
@@ -255,7 +256,7 @@ func (*AzureInstanceSetSuite) TestWrapError(c *check.C) {
                },
        }
        wrapped = WrapAzureError(quotaError)
-       _, ok = wrapped.(QuotaError)
+       _, ok = wrapped.(cloud.QuotaError)
        c.Check(ok, check.Equals, true)
 }
 
@@ -307,7 +308,7 @@ func (*AzureInstanceSetSuite) TestSSH(c *check.C) {
        }
 }
 
-func SetupSSHClient(c *check.C, inst Instance) (*ssh.Client, error) {
+func SetupSSHClient(c *check.C, inst cloud.Instance) (*ssh.Client, error) {
        addr := inst.Address() + ":2222"
        if addr == "" {
                return nil, errors.New("instance has no address")
index a6e62e05bb1a4cb611d6698812ddc459585f24fe..83dca83cd9bfecd38dbb60f730ea1ec5c4d5e907 100644 (file)
@@ -8,12 +8,13 @@ import (
        "fmt"
 
        "git.curoverse.com/arvados.git/lib/cloud"
+       "git.curoverse.com/arvados.git/lib/cloud/azure"
        "git.curoverse.com/arvados.git/sdk/go/arvados"
        "github.com/sirupsen/logrus"
 )
 
 var drivers = map[string]cloud.Driver{
-       "azure": cloud.DriverFunc(cloud.NewAzureInstanceSet),
+       "azure": cloud.DriverFunc(azure.NewAzureInstanceSet),
 }
 
 func newInstanceSet(cluster *arvados.Cluster, setID cloud.InstanceSetID, logger logrus.FieldLogger) (cloud.InstanceSet, error) {