Skip to content

Commit 3488baf

Browse files
authored
fix(instance): delete with-volumes none worked like all (#3025)
1 parent fbffde8 commit 3488baf

File tree

6 files changed

+2188
-8
lines changed

6 files changed

+2188
-8
lines changed

cmd/scw/testdata/test-all-usage-instance-server-delete-usage.golden

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ EXAMPLES:
1313
scw instance server delete 11111111-1111-1111-1111-111111111111 zone=fr-par-1
1414

1515
ARGS:
16-
server-id
17-
[with-volumes=none] Delete the volumes attached to the server (none | local | block | root | all)
18-
[with-ip] Delete the IP attached to the server
19-
[force-shutdown] Force shutdown of the instance server before deleting it
20-
[zone=fr-par-1] Zone to target. If none is passed will use default zone from the config
16+
server-id
17+
[with-volumes=all] Delete the volumes attached to the server (none | local | block | root | all)
18+
[with-ip] Delete the IP attached to the server
19+
[force-shutdown] Force shutdown of the instance server before deleting it
20+
[zone=fr-par-1] Zone to target. If none is passed will use default zone from the config
2121

2222
FLAGS:
2323
-h, --help help for delete

docs/commands/instance.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1756,7 +1756,7 @@ scw instance server delete <server-id ...> [arg=value ...]
17561756
| Name | | Description |
17571757
|------|---|-------------|
17581758
| server-id | Required | |
1759-
| with-volumes | Default: `none`<br />One of: `none`, `local`, `block`, `root`, `all` | Delete the volumes attached to the server |
1759+
| with-volumes | Default: `all`<br />One of: `none`, `local`, `block`, `root`, `all` | Delete the volumes attached to the server |
17601760
| with-ip | | Delete the IP attached to the server |
17611761
| force-shutdown | | Force shutdown of the instance server before deleting it |
17621762
| zone | Default: `fr-par-1` | Zone to target. If none is passed will use default zone from the config |

internal/namespaces/instance/v1/custom_server.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -915,7 +915,7 @@ func serverDeleteCommand() *core.Command {
915915
{
916916
Name: "with-volumes",
917917
Short: "Delete the volumes attached to the server",
918-
Default: core.DefaultValueSetter("none"),
918+
Default: core.DefaultValueSetter("all"),
919919
EnumValues: []string{
920920
string(withVolumesNone),
921921
string(withVolumesLocal),
@@ -1013,10 +1013,11 @@ func serverDeleteCommand() *core.Command {
10131013
}
10141014

10151015
deletedVolumeMessages := [][2]string(nil)
1016+
volumeDelete:
10161017
for index, volume := range server.Server.Volumes {
10171018
switch {
10181019
case deleteServerArgs.WithVolumes == withVolumesNone:
1019-
break
1020+
break volumeDelete
10201021
case deleteServerArgs.WithVolumes == withVolumesRoot && index != "0":
10211022
continue
10221023
case deleteServerArgs.WithVolumes == withVolumesLocal && volume.VolumeType != instance.VolumeServerVolumeTypeLSSD:

internal/namespaces/instance/v1/custom_server_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,26 @@ func Test_ServerDelete(t *testing.T) {
274274
DisableParallel: true,
275275
}))
276276

277+
t.Run("with none volumes", core.Test(&core.TestConfig{
278+
Commands: GetCommands(),
279+
BeforeFunc: core.ExecStoreBeforeCmd("Server", "scw instance server create stopped=true image=ubuntu-bionic additional-volumes.0=block:10G"),
280+
Cmd: `scw instance server delete {{ .Server.ID }} with-ip=true with-volumes=none`,
281+
Check: core.TestCheckCombine(
282+
core.TestCheckGolden(),
283+
core.TestCheckExitCode(0),
284+
func(t *testing.T, ctx *core.CheckFuncCtx) {
285+
api := instance.NewAPI(ctx.Client)
286+
server := ctx.Meta["Server"].(*instance.Server)
287+
_, err := api.GetVolume(&instance.GetVolumeRequest{
288+
VolumeID: server.Volumes["0"].ID,
289+
})
290+
assert.NoError(t, err)
291+
},
292+
),
293+
AfterFunc: core.ExecAfterCmd(`scw instance volume delete {{ (index .Server.Volumes "0").ID }}`),
294+
DisableParallel: true,
295+
}))
296+
277297
interactive.IsInteractive = false
278298
}
279299

0 commit comments

Comments
 (0)