Skip to content

Commit

Permalink
bumping upcloud && setting longer default timeout (#1496)
Browse files Browse the repository at this point in the history
  • Loading branch information
eyberg authored Jul 18, 2023
1 parent 78c78b6 commit a3de0c5
Show file tree
Hide file tree
Showing 12 changed files with 459 additions and 274 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ require (
github.com/Azure/go-autorest/autorest/adal v0.9.18
github.com/Azure/go-autorest/autorest/azure/auth v0.5.3
github.com/Azure/go-autorest/autorest/to v0.4.0
github.com/UpCloudLtd/upcloud-go-api v0.0.0-20210127073406-2964ed7e5972
github.com/aws/aws-sdk-go v1.35.20
github.com/bramvdbogaerde/go-scp v1.0.0
github.com/digitalocean/godo v1.57.0
Expand Down Expand Up @@ -44,6 +43,7 @@ require (
google.golang.org/genproto v0.0.0-20221207170731-23e4bf6bdc37
google.golang.org/grpc v1.51.0
google.golang.org/protobuf v1.28.1
gopkg.in/yaml.v2 v2.4.0
gotest.tools v2.2.0+incompatible
k8s.io/client-go v0.23.1
)
Expand All @@ -62,6 +62,7 @@ require (
github.com/Azure/go-autorest/logger v0.2.1 // indirect
github.com/Azure/go-autorest/tracing v0.6.0 // indirect
github.com/Microsoft/go-winio v0.5.2 // indirect
github.com/UpCloudLtd/upcloud-go-api/v6 v6.5.0 // indirect
github.com/blang/semver v3.5.1+incompatible // indirect
github.com/blang/semver/v4 v4.0.0 // indirect
github.com/containerd/containerd v1.6.12 // indirect
Expand Down Expand Up @@ -112,7 +113,6 @@ require (
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
google.golang.org/appengine v1.6.7 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/api v0.23.1 // indirect
k8s.io/apimachinery v0.23.1 // indirect
Expand Down
143 changes: 114 additions & 29 deletions go.sum

Large diffs are not rendered by default.

374 changes: 232 additions & 142 deletions provider/upcloud/mocks/upcloud.go

Large diffs are not rendered by default.

24 changes: 11 additions & 13 deletions provider/upcloud/upcloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
package upcloud

import (
"context"
"errors"
"os"
"time"

"github.com/UpCloudLtd/upcloud-go-api/upcloud"
"github.com/UpCloudLtd/upcloud-go-api/upcloud/client"
"github.com/UpCloudLtd/upcloud-go-api/upcloud/request"
"github.com/UpCloudLtd/upcloud-go-api/upcloud/service"
"github.com/UpCloudLtd/upcloud-go-api/v6/upcloud"
"github.com/UpCloudLtd/upcloud-go-api/v6/upcloud/client"
"github.com/UpCloudLtd/upcloud-go-api/v6/upcloud/request"
"github.com/UpCloudLtd/upcloud-go-api/v6/upcloud/service"
"github.com/nanovms/ops/types"
)

Expand Down Expand Up @@ -64,18 +65,15 @@ func (p *Provider) Initialize(c *types.ProviderConfig) error {
}

if p.upcloud == nil {
c := client.New(user, password)

c.SetTimeout(time.Second * 30)

c := client.New(user, password, client.WithTimeout(time.Second*600))
p.upcloud = service.New(c)
}

_, err := p.upcloud.GetAccount()
_, err := p.upcloud.GetAccount(context.Background())

if err != nil {
if serviceError, ok := err.(*upcloud.Error); ok {
return errors.New(serviceError.ErrorMessage)
if serviceError, ok := err.(*upcloud.Problem); ok {
return errors.New(serviceError.Title)
}
return errors.New("Invalid credentials")
}
Expand All @@ -84,7 +82,7 @@ func (p *Provider) Initialize(c *types.ProviderConfig) error {
}

func (p *Provider) findOrCreateTag(tag upcloud.Tag) (upcloudTag *upcloud.Tag, err error) {
tagsResponse, err := p.upcloud.GetTags()
tagsResponse, err := p.upcloud.GetTags(context.Background())
if err != nil {
return
}
Expand All @@ -98,7 +96,7 @@ func (p *Provider) findOrCreateTag(tag upcloud.Tag) (upcloudTag *upcloud.Tag, er

createTagReq := &request.CreateTagRequest{Tag: tag}

upcloudTag, err = p.upcloud.CreateTag(createTagReq)
upcloudTag, err = p.upcloud.CreateTag(context.Background(), createTagReq)
if err != nil {
return
}
Expand Down
10 changes: 6 additions & 4 deletions provider/upcloud/upcloud_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
package upcloud

import (
"context"
"errors"
"math"
"os"

"github.com/UpCloudLtd/upcloud-go-api/upcloud"
"github.com/UpCloudLtd/upcloud-go-api/upcloud/request"
"github.com/nanovms/ops/lepton"
"github.com/nanovms/ops/types"

"github.com/UpCloudLtd/upcloud-go-api/v6/upcloud"
"github.com/UpCloudLtd/upcloud-go-api/v6/upcloud/request"
"github.com/olekukonko/tablewriter"
)

Expand Down Expand Up @@ -50,7 +52,7 @@ func (p *Provider) CreateImage(ctx *lepton.Context, imagePath string) error {
Title: ctx.Config().CloudConfig.ImageName,
}

templateDetails, err := p.upcloud.TemplatizeStorage(templatizeReq)
templateDetails, err := p.upcloud.TemplatizeStorage(context.Background(), templatizeReq)
if err != nil {
return err
}
Expand Down Expand Up @@ -108,7 +110,7 @@ func (p *Provider) GetImages(ctx *lepton.Context) (images []lepton.CloudImage, e
Access: "private",
}

templates, err := p.upcloud.GetStorages(listTemplatesReq)
templates, err := p.upcloud.GetStorages(context.Background(), listTemplatesReq)
if err != nil {
return
}
Expand Down
24 changes: 13 additions & 11 deletions provider/upcloud/upcloud_image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
package upcloud_test

import (
"context"
"os"
"testing"
"time"

"github.com/UpCloudLtd/upcloud-go-api/upcloud"
"github.com/UpCloudLtd/upcloud-go-api/upcloud/request"
"github.com/nanovms/ops/lepton"

"github.com/UpCloudLtd/upcloud-go-api/v6/upcloud"
"github.com/UpCloudLtd/upcloud-go-api/v6/upcloud/request"
"github.com/stretchr/testify/assert"
)

Expand All @@ -22,24 +24,24 @@ func TestCreateImage(t *testing.T) {
storageUUID := "1"

s.EXPECT().
CreateStorage(&request.CreateStorageRequest{Size: 10}).
CreateStorage(context.Background(), &request.CreateStorageRequest{Size: 1}).
Return(&upcloud.StorageDetails{Storage: upcloud.Storage{UUID: storageUUID}}, nil)

s.EXPECT().
CreateStorageImport(&request.CreateStorageImportRequest{StorageUUID: storageUUID, Source: "direct_upload", SourceLocation: file.Name()}).
CreateStorageImport(context.Background(), &request.CreateStorageImportRequest{StorageUUID: storageUUID, Source: "direct_upload", SourceLocation: file.Name()}).
Return(&upcloud.StorageImportDetails{}, nil)

s.EXPECT().
WaitForStorageState(&request.WaitForStorageStateRequest{UUID: storageUUID, DesiredState: "online", Timeout: 10 * time.Minute}).
WaitForStorageState(context.Background(), &request.WaitForStorageStateRequest{UUID: storageUUID, DesiredState: "online", Timeout: 10 * time.Minute}).
Return(nil, nil).
Times(2)

s.EXPECT().
TemplatizeStorage(&request.TemplatizeStorageRequest{UUID: storageUUID}).
TemplatizeStorage(context.Background(), &request.TemplatizeStorageRequest{UUID: storageUUID}).
Return(nil, nil)

s.EXPECT().
DeleteStorage(&request.DeleteStorageRequest{UUID: storageUUID}).
DeleteStorage(context.Background(), &request.DeleteStorageRequest{UUID: storageUUID}).
Return(nil)

ctx := lepton.NewContext(lepton.NewConfig())
Expand All @@ -52,7 +54,7 @@ func TestListImages(t *testing.T) {
p, s := NewProvider(t)

s.EXPECT().
GetStorages(&request.GetStoragesRequest{Access: "private", Type: "template"}).
GetStorages(context.Background(), &request.GetStoragesRequest{Access: "private", Type: "template"}).
Return(&upcloud.Storages{}, nil)

ctx := lepton.NewContext(lepton.NewConfig())
Expand All @@ -65,7 +67,7 @@ func TestGetImages(t *testing.T) {
p, s := NewProvider(t)

s.EXPECT().
GetStorages(&request.GetStoragesRequest{Access: "private", Type: "template"}).
GetStorages(context.Background(), &request.GetStoragesRequest{Access: "private", Type: "template"}).
Return(&upcloud.Storages{}, nil)

ctx := lepton.NewContext(lepton.NewConfig())
Expand All @@ -87,11 +89,11 @@ func TestDeleteImage(t *testing.T) {
storages.Storages = []upcloud.Storage{{UUID: storageUUID, Title: storageTitle}}

s.EXPECT().
GetStorages(&request.GetStoragesRequest{Access: "private", Type: "template"}).
GetStorages(context.Background(), &request.GetStoragesRequest{Access: "private", Type: "template"}).
Return(&storages, nil)

s.EXPECT().
DeleteStorage(&request.DeleteStorageRequest{UUID: storageUUID}).
DeleteStorage(context.Background(), &request.DeleteStorageRequest{UUID: storageUUID}).
Return(nil)

ctx := lepton.NewContext(lepton.NewConfig())
Expand Down
24 changes: 13 additions & 11 deletions provider/upcloud/upcloud_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
package upcloud

import (
"context"
"errors"
"os"
"strings"
"time"

"github.com/UpCloudLtd/upcloud-go-api/upcloud"
"github.com/UpCloudLtd/upcloud-go-api/upcloud/request"
"github.com/nanovms/ops/lepton"

"github.com/UpCloudLtd/upcloud-go-api/v6/upcloud"
"github.com/UpCloudLtd/upcloud-go-api/v6/upcloud/request"
"github.com/olekukonko/tablewriter"
)

Expand Down Expand Up @@ -48,7 +50,7 @@ func (p *Provider) CreateInstance(ctx *lepton.Context) error {

ctx.Logger().Info("creating server")

serverDetails, err := p.upcloud.CreateServer(createInstanceReq)
serverDetails, err := p.upcloud.CreateServer(context.Background(), createInstanceReq)
if err != nil {
return err
}
Expand Down Expand Up @@ -78,7 +80,7 @@ func (p *Provider) CreateInstance(ctx *lepton.Context) error {
Tags: []string{opsTag.Name, imageTag.Name},
}

_, err = p.upcloud.TagServer(assignOpsTagsRequest)
_, err = p.upcloud.TagServer(context.Background(), assignOpsTagsRequest)
if err != nil {
ctx.Logger().Warn("failed assigning ops tags: %s", err)
return nil
Expand Down Expand Up @@ -134,7 +136,7 @@ func (p *Provider) GetInstances(ctx *lepton.Context) (instances []lepton.CloudIn
ctx.Logger().Warn("failed creating tags: %s", err)

var servers *upcloud.Servers
servers, err = p.upcloud.GetServers()
servers, err = p.upcloud.GetServers(context.Background())
if err != nil {
return
}
Expand Down Expand Up @@ -203,7 +205,7 @@ func (p *Provider) DeleteInstance(ctx *lepton.Context, instancename string) (err
}

ctx.Logger().Debug(`deleting server with uuid "%s"`, instance.ID)
err = p.upcloud.DeleteServer(deleteServerReq)
err = p.upcloud.DeleteServer(context.Background(), deleteServerReq)

return
}
Expand All @@ -226,7 +228,7 @@ func (p *Provider) stopServer(uuid string) (err error) {
UUID: uuid,
}

_, err = p.upcloud.StopServer(stopServerReq)
_, err = p.upcloud.StopServer(context.Background(), stopServerReq)

return
}
Expand All @@ -250,7 +252,7 @@ func (p *Provider) startServer(uuid string) (err error) {
UUID: uuid,
}

_, err = p.upcloud.StartServer(startServerReq)
_, err = p.upcloud.StartServer(context.Background(), startServerReq)

return
}
Expand All @@ -269,7 +271,7 @@ func (p *Provider) GetInstanceByName(ctx *lepton.Context, name string) (instance
}

func (p *Provider) getServerByName(ctx *lepton.Context, name string) (server *upcloud.Server, err error) {
servers, err := p.upcloud.GetServers()
servers, err := p.upcloud.GetServers(context.Background())
if err != nil {
return
}
Expand All @@ -293,7 +295,7 @@ func (p *Provider) GetInstanceByID(ctx *lepton.Context, id string) (instance *le

serverDetailsReq := &request.GetServerDetailsRequest{UUID: id}

serverDetails, err = p.upcloud.GetServerDetails(serverDetailsReq)
serverDetails, err = p.upcloud.GetServerDetails(context.Background(), serverDetailsReq)
if err != nil {
return
}
Expand Down Expand Up @@ -349,7 +351,7 @@ func (p *Provider) waitForServerState(uuid, state string) (err error) {
Timeout: 1 * time.Minute,
}

_, err = p.upcloud.WaitForServerState(waitReq)
_, err = p.upcloud.WaitForServerState(context.Background(), waitReq)

return
}
Loading

0 comments on commit a3de0c5

Please sign in to comment.