Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ require (
github.com/mattn/go-colorable v0.1.4
github.com/mattn/go-isatty v0.0.11
github.com/pkg/errors v0.9.1 // indirect
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.6.0.20200601141019-df9902c66d0d
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.6.0.20200603093029-edb933d7c8d4
github.com/sergi/go-diff v1.0.0 // indirect
github.com/spf13/cobra v0.0.5
github.com/spf13/pflag v1.0.5
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g=
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.6.0.20200601141019-df9902c66d0d h1:5643F4Bm9aFFz482Zju0EW/oP+XA7j+pRWWL6kVcjkQ=
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.6.0.20200601141019-df9902c66d0d/go.mod h1:CJJ5VAbozOl0yEw7nHB9+7BXTJbIn6h7W+f6Gau5IP8=
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.6.0.20200603093029-edb933d7c8d4 h1:zJe5/C/RVqDc2GYekjEhFI0e6mrBqotu85LyjBHWhhA=
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.6.0.20200603093029-edb933d7c8d4/go.mod h1:CJJ5VAbozOl0yEw7nHB9+7BXTJbIn6h7W+f6Gau5IP8=
github.com/sergi/go-diff v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ=
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ=
Expand Down
10 changes: 10 additions & 0 deletions internal/core/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,11 @@ func createTestClient(t *testing.T, testConfig *TestConfig, httpClient *http.Cli
return client
}

// DefaultRetryInterval is used across all wait functions in the CLI
// In particular it is very handy to define this RetryInterval at 0 second while running cassette in testing
// because they will be executed without waiting.
var DefaultRetryInterval *time.Duration

// Run a CLI integration test. See TestConfig for configuration option
func Test(config *TestConfig) func(t *testing.T) {
return func(t *testing.T) {
Expand All @@ -248,6 +253,11 @@ func Test(config *TestConfig) func(t *testing.T) {
return "few seconds ago", nil
})

if !UpdateCassettes {
tmp := 0 * time.Second
DefaultRetryInterval = &tmp
}

ctx := config.Ctx
if ctx == nil {
ctx = context.Background()
Expand Down
7 changes: 0 additions & 7 deletions internal/namespaces/baremetal/v1/baremetal_cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,11 @@ package baremetal

import (
"testing"
"time"

"github.com/scaleway/scaleway-cli/internal/core"
"github.com/scaleway/scaleway-sdk-go/scw"
)

func init() {
if !core.UpdateCassettes {
defaultRetryInterval = 1 * time.Millisecond
}
}

//
// Server
//
Expand Down
35 changes: 20 additions & 15 deletions internal/namespaces/baremetal/v1/custom_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,10 @@ func serverWaitCommand() *core.Command {
api := baremetal.NewAPI(core.ExtractClient(ctx))
logger.Debugf("starting to wait for server to reach a stable delivery status")
server, err := api.WaitForServer(&baremetal.WaitForServerRequest{
ServerID: argsI.(*serverWaitRequest).ServerID,
Zone: argsI.(*serverWaitRequest).Zone,
Timeout: serverActionTimeout,
ServerID: argsI.(*serverWaitRequest).ServerID,
Zone: argsI.(*serverWaitRequest).Zone,
Timeout: scw.TimeDurationPtr(serverActionTimeout),
RetryInterval: core.DefaultRetryInterval,
})
if err != nil {
return nil, err
Expand All @@ -58,9 +59,10 @@ func serverWaitCommand() *core.Command {
}
logger.Debugf("server reached a stable delivery status. Will now starting to wait for server to reach a stable installation status")
server, err = api.WaitForServerInstall(&baremetal.WaitForServerInstallRequest{
ServerID: argsI.(*serverWaitRequest).ServerID,
Zone: argsI.(*serverWaitRequest).Zone,
Timeout: serverActionTimeout,
ServerID: argsI.(*serverWaitRequest).ServerID,
Zone: argsI.(*serverWaitRequest).Zone,
Timeout: scw.TimeDurationPtr(serverActionTimeout),
RetryInterval: core.DefaultRetryInterval,
})
if err != nil {
return nil, err
Expand Down Expand Up @@ -97,9 +99,10 @@ func serverStartBuilder(c *core.Command) *core.Command {
c.WaitFunc = func(ctx context.Context, argsI, respI interface{}) (interface{}, error) {
api := baremetal.NewAPI(core.ExtractClient(ctx))
return api.WaitForServer(&baremetal.WaitForServerRequest{
Zone: argsI.(*baremetal.StartServerRequest).Zone,
ServerID: respI.(*baremetal.Server).ID,
Timeout: serverActionTimeout,
Zone: argsI.(*baremetal.StartServerRequest).Zone,
ServerID: respI.(*baremetal.Server).ID,
Timeout: scw.TimeDurationPtr(serverActionTimeout),
RetryInterval: core.DefaultRetryInterval,
})
}

Expand All @@ -111,9 +114,10 @@ func serverStopBuilder(c *core.Command) *core.Command {
c.WaitFunc = func(ctx context.Context, argsI, respI interface{}) (interface{}, error) {
api := baremetal.NewAPI(core.ExtractClient(ctx))
return api.WaitForServer(&baremetal.WaitForServerRequest{
Zone: argsI.(*baremetal.StopServerRequest).Zone,
ServerID: respI.(*baremetal.Server).ID,
Timeout: serverActionTimeout,
Zone: argsI.(*baremetal.StopServerRequest).Zone,
ServerID: respI.(*baremetal.Server).ID,
Timeout: scw.TimeDurationPtr(serverActionTimeout),
RetryInterval: core.DefaultRetryInterval,
})
}

Expand All @@ -127,9 +131,10 @@ func serverRebootBuilder(c *core.Command) *core.Command {
c.WaitFunc = func(ctx context.Context, argsI, respI interface{}) (interface{}, error) {
api := baremetal.NewAPI(core.ExtractClient(ctx))
return api.WaitForServer(&baremetal.WaitForServerRequest{
Zone: argsI.(*baremetal.RebootServerRequest).Zone,
ServerID: respI.(*baremetal.Server).ID,
Timeout: serverActionTimeout,
Zone: argsI.(*baremetal.RebootServerRequest).Zone,
ServerID: respI.(*baremetal.Server).ID,
Timeout: scw.TimeDurationPtr(serverActionTimeout),
RetryInterval: core.DefaultRetryInterval,
})
}

Expand Down
4 changes: 2 additions & 2 deletions internal/namespaces/baremetal/v1/custom_server_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ func serverCreateBuilder(c *core.Command) *core.Command {
return api.WaitForServer(&baremetal.WaitForServerRequest{
Zone: argsI.(*baremetalCreateServerRequestCustom).Zone,
ServerID: respI.(*baremetal.Server).ID,
Timeout: serverActionTimeout,
RetryInterval: defaultRetryInterval,
Timeout: scw.TimeDurationPtr(serverActionTimeout),
RetryInterval: core.DefaultRetryInterval,
})
}

Expand Down
4 changes: 2 additions & 2 deletions internal/namespaces/baremetal/v1/custom_server_install.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ func serverInstallBuilder(c *core.Command) *core.Command {
return api.WaitForServerInstall(&baremetal.WaitForServerInstallRequest{
Zone: argsI.(*baremetalInstallServerRequestCustom).Zone,
ServerID: respI.(*baremetal.Server).ID,
Timeout: serverActionTimeout,
RetryInterval: defaultRetryInterval,
Timeout: scw.TimeDurationPtr(serverActionTimeout),
RetryInterval: core.DefaultRetryInterval,
})
}

Expand Down
12 changes: 6 additions & 6 deletions internal/namespaces/baremetal/v1/custom_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ func Test_StartServerErrors(t *testing.T) {
server, err := api.WaitForServer(&baremetal.WaitForServerRequest{
ServerID: server.ID,
Zone: server.Zone,
Timeout: serverActionTimeout,
RetryInterval: defaultRetryInterval,
Timeout: scw.TimeDurationPtr(serverActionTimeout),
RetryInterval: core.DefaultRetryInterval,
})
return err
},
Expand All @@ -51,8 +51,8 @@ func Test_StopServerErrors(t *testing.T) {
server, err := api.WaitForServer(&baremetal.WaitForServerRequest{
ServerID: server.ID,
Zone: server.Zone,
Timeout: serverActionTimeout,
RetryInterval: defaultRetryInterval,
Timeout: scw.TimeDurationPtr(serverActionTimeout),
RetryInterval: core.DefaultRetryInterval,
})
return err
},
Expand All @@ -78,8 +78,8 @@ func Test_RebootServerErrors(t *testing.T) {
server, err := api.WaitForServer(&baremetal.WaitForServerRequest{
ServerID: server.ID,
Zone: server.Zone,
Timeout: serverActionTimeout,
RetryInterval: defaultRetryInterval,
Timeout: scw.TimeDurationPtr(serverActionTimeout),
RetryInterval: core.DefaultRetryInterval,
})
return err
},
Expand Down
13 changes: 7 additions & 6 deletions internal/namespaces/instance/v1/custom_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,17 +232,18 @@ func imageWaitCommand() *core.Command {
Run: func(ctx context.Context, argsI interface{}) (i interface{}, err error) {
api := instance.NewAPI(core.ExtractClient(ctx))
return api.WaitForImage(&instance.WaitForImageRequest{
Zone: argsI.(*instance.WaitForImageRequest).Zone,
ImageID: argsI.(*instance.WaitForImageRequest).ImageID,
Timeout: imageActionTimeout,
Zone: argsI.(*instance.WaitForImageRequest).Zone,
ImageID: argsI.(*instance.WaitForImageRequest).ImageID,
Timeout: scw.TimeDurationPtr(imageActionTimeout),
RetryInterval: core.DefaultRetryInterval,
})

},
ArgSpecs: core.ArgSpecs{
{
Name: "image-id",
Short: `ID of the image.`,
Required: true,
Name: "image-id",
Short: `ID of the image.`,
Required: true,
Positional: true,
},
core.ZoneArgSpec(),
Expand Down
27 changes: 17 additions & 10 deletions internal/namespaces/instance/v1/custom_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -572,8 +572,10 @@ Once your image is ready you will be able to create a new server based on this i
resp := respI.(*instance.GetImageResponse)
api := instance.NewAPI(core.ExtractClient(ctx))
return api.WaitForImage(&instance.WaitForImageRequest{
ImageID: resp.Image.ID,
Zone: resp.Image.Zone,
ImageID: resp.Image.ID,
Zone: resp.Image.Zone,
Timeout: scw.TimeDurationPtr(serverActionTimeout),
RetryInterval: core.DefaultRetryInterval,
})
},
ArgSpecs: core.ArgSpecs{
Expand Down Expand Up @@ -623,9 +625,10 @@ func serverWaitCommand() *core.Command {
func waitForServerFunc() core.WaitFunc {
return func(ctx context.Context, argsI, _ interface{}) (interface{}, error) {
return instance.NewAPI(core.ExtractClient(ctx)).WaitForServer(&instance.WaitForServerRequest{
Zone: argsI.(*instanceActionRequest).Zone,
ServerID: argsI.(*instanceActionRequest).ServerID,
Timeout: serverActionTimeout,
Zone: argsI.(*instanceActionRequest).Zone,
ServerID: argsI.(*instanceActionRequest).ServerID,
Timeout: scw.TimeDurationPtr(serverActionTimeout),
RetryInterval: core.DefaultRetryInterval,
})
}
}
Expand Down Expand Up @@ -736,18 +739,22 @@ func serverDeleteCommand() *core.Command {

if deleteServerArgs.ForceShutdown {
finalStateServer, err := api.WaitForServer(&instance.WaitForServerRequest{
Zone: deleteServerArgs.Zone,
ServerID: deleteServerArgs.ServerID,
Zone: deleteServerArgs.Zone,
ServerID: deleteServerArgs.ServerID,
Timeout: scw.TimeDurationPtr(serverActionTimeout),
RetryInterval: core.DefaultRetryInterval,
})
if err != nil {
return nil, err
}

if finalStateServer.State != instance.ServerStateStopped {
err = api.ServerActionAndWait(&instance.ServerActionAndWaitRequest{
Zone: deleteServerArgs.Zone,
ServerID: deleteServerArgs.ServerID,
Action: instance.ServerActionPoweroff,
Zone: deleteServerArgs.Zone,
ServerID: deleteServerArgs.ServerID,
Action: instance.ServerActionPoweroff,
Timeout: scw.TimeDurationPtr(serverActionTimeout),
RetryInterval: core.DefaultRetryInterval,
})
if err != nil {
return nil, err
Expand Down
7 changes: 4 additions & 3 deletions internal/namespaces/instance/v1/custom_server_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,10 @@ scw instance server create image=ubuntu_focal ip=$ip`,
func instanceWaitServerCreateRun() core.WaitFunc {
return func(ctx context.Context, argsI, respI interface{}) (interface{}, error) {
return instance.NewAPI(core.ExtractClient(ctx)).WaitForServer(&instance.WaitForServerRequest{
Zone: argsI.(*instanceCreateServerRequest).Zone,
ServerID: respI.(*instance.Server).ID,
Timeout: serverActionTimeout,
Zone: argsI.(*instanceCreateServerRequest).Zone,
ServerID: respI.(*instance.Server).ID,
Timeout: scw.TimeDurationPtr(serverActionTimeout),
RetryInterval: core.DefaultRetryInterval,
})
}
}
Expand Down
21 changes: 12 additions & 9 deletions internal/namespaces/instance/v1/custom_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/scaleway/scaleway-cli/internal/core"
"github.com/scaleway/scaleway-sdk-go/api/instance/v1"
"github.com/scaleway/scaleway-sdk-go/scw"
)

const (
Expand Down Expand Up @@ -41,9 +42,10 @@ func snapshotCreateBuilder(c *core.Command) *core.Command {
c.WaitFunc = func(ctx context.Context, argsI, respI interface{}) (interface{}, error) {
api := instance.NewAPI(core.ExtractClient(ctx))
return api.WaitForSnapshot(&instance.WaitForSnapshotRequest{
SnapshotID: respI.(*instance.CreateSnapshotResponse).Snapshot.ID,
Zone: argsI.(*customCreateSnapshotRequest).Zone,
Timeout: serverActionTimeout,
SnapshotID: respI.(*instance.CreateSnapshotResponse).Snapshot.ID,
Zone: argsI.(*customCreateSnapshotRequest).Zone,
Timeout: scw.TimeDurationPtr(serverActionTimeout),
RetryInterval: core.DefaultRetryInterval,
})
}

Expand Down Expand Up @@ -86,17 +88,18 @@ func snapshotWaitCommand() *core.Command {
Run: func(ctx context.Context, argsI interface{}) (i interface{}, err error) {
api := instance.NewAPI(core.ExtractClient(ctx))
return api.WaitForSnapshot(&instance.WaitForSnapshotRequest{
Zone: argsI.(*instance.WaitForSnapshotRequest).Zone,
SnapshotID: argsI.(*instance.WaitForSnapshotRequest).SnapshotID,
Timeout: snapshotActionTimeout,
Zone: argsI.(*instance.WaitForSnapshotRequest).Zone,
SnapshotID: argsI.(*instance.WaitForSnapshotRequest).SnapshotID,
Timeout: scw.TimeDurationPtr(snapshotActionTimeout),
RetryInterval: core.DefaultRetryInterval,
})

},
ArgSpecs: core.ArgSpecs{
{
Name: "snapshot-id",
Short: `ID of the snapshot.`,
Required: true,
Name: "snapshot-id",
Short: `ID of the snapshot.`,
Required: true,
Positional: true,
},
core.ZoneArgSpec(),
Expand Down
6 changes: 0 additions & 6 deletions internal/namespaces/instance/v1/instance_cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@ import (
"github.com/stretchr/testify/require"
)

func init() {
if !core.UpdateCassettes {
instance.RetryInterval = 0
}
}

//
// Server
//
Expand Down
14 changes: 8 additions & 6 deletions internal/namespaces/k8s/v1/custom_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,10 @@ func clusterUpdateBuilder(c *core.Command) *core.Command {
func waitForClusterFunc(action int) core.WaitFunc {
return func(ctx context.Context, _, respI interface{}) (interface{}, error) {
cluster, err := k8s.NewAPI(core.ExtractClient(ctx)).WaitForCluster(&k8s.WaitForClusterRequest{
Region: respI.(*k8s.Cluster).Region,
ClusterID: respI.(*k8s.Cluster).ID,
Timeout: scw.TimeDurationPtr(clusterActionTimeout),
Region: respI.(*k8s.Cluster).Region,
ClusterID: respI.(*k8s.Cluster).ID,
Timeout: scw.TimeDurationPtr(clusterActionTimeout),
RetryInterval: core.DefaultRetryInterval,
})
switch action {
case clusterActionCreate:
Expand Down Expand Up @@ -114,9 +115,10 @@ func k8sClusterWaitCommand() *core.Command {
Run: func(ctx context.Context, argsI interface{}) (i interface{}, err error) {
api := k8s.NewAPI(core.ExtractClient(ctx))
return api.WaitForCluster(&k8s.WaitForClusterRequest{
Region: argsI.(*k8s.WaitForClusterRequest).Region,
ClusterID: argsI.(*k8s.WaitForClusterRequest).ClusterID,
Timeout: scw.TimeDurationPtr(clusterActionTimeout),
Region: argsI.(*k8s.WaitForClusterRequest).Region,
ClusterID: argsI.(*k8s.WaitForClusterRequest).ClusterID,
Timeout: scw.TimeDurationPtr(clusterActionTimeout),
RetryInterval: core.DefaultRetryInterval,
})
},
ArgSpecs: core.ArgSpecs{
Expand Down
14 changes: 8 additions & 6 deletions internal/namespaces/k8s/v1/custom_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@ func nodeRebootBuilder(c *core.Command) *core.Command {
func waitForNodeFunc(action int) core.WaitFunc {
return func(ctx context.Context, _, respI interface{}) (interface{}, error) {
node, err := k8s.NewAPI(core.ExtractClient(ctx)).WaitForNode(&k8s.WaitForNodeRequest{
Region: respI.(*k8s.Node).Region,
NodeID: respI.(*k8s.Node).ID,
Timeout: scw.TimeDurationPtr(nodeActionTimeout),
Region: respI.(*k8s.Node).Region,
NodeID: respI.(*k8s.Node).ID,
Timeout: scw.TimeDurationPtr(nodeActionTimeout),
RetryInterval: core.DefaultRetryInterval,
})
switch action {
case nodeActionReboot:
Expand All @@ -63,9 +64,10 @@ func k8sNodeWaitCommand() *core.Command {
Run: func(ctx context.Context, argsI interface{}) (i interface{}, err error) {
api := k8s.NewAPI(core.ExtractClient(ctx))
return api.WaitForNode(&k8s.WaitForNodeRequest{
Region: argsI.(*k8s.WaitForNodeRequest).Region,
NodeID: argsI.(*k8s.WaitForNodeRequest).NodeID,
Timeout: scw.TimeDurationPtr(nodeActionTimeout),
Region: argsI.(*k8s.WaitForNodeRequest).Region,
NodeID: argsI.(*k8s.WaitForNodeRequest).NodeID,
Timeout: scw.TimeDurationPtr(nodeActionTimeout),
RetryInterval: core.DefaultRetryInterval,
})
},
ArgSpecs: core.ArgSpecs{
Expand Down
Loading