Skip to content

Commit 91870a8

Browse files
authored
fix(instance): add server-id attribut to detach-volume (#4922)
1 parent 40edd8c commit 91870a8

8 files changed

+2810
-2540
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ EXAMPLES:
1111

1212
ARGS:
1313
volume-id ID of the volume to detach
14+
server-id ID of the server
1415
[zone=fr-par-1] Zone to target. If none is passed will use default zone from the config (fr-par-1 | fr-par-2 | fr-par-3 | nl-ams-1 | nl-ams-2 | nl-ams-3 | pl-waw-1 | pl-waw-2 | pl-waw-3)
1516

1617
FLAGS:

docs/commands/instance.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1910,6 +1910,7 @@ scw instance server detach-volume [arg=value ...]
19101910
| Name | | Description |
19111911
|------|---|-------------|
19121912
| volume-id | Required | ID of the volume to detach |
1913+
| server-id | Required | ID of the server |
19131914
| zone | Default: `fr-par-1`<br />One of: `fr-par-1`, `fr-par-2`, `fr-par-3`, `nl-ams-1`, `nl-ams-2`, `nl-ams-3`, `pl-waw-1`, `pl-waw-2`, `pl-waw-3` | Zone to target. If none is passed will use default zone from the config |
19141915

19151916

internal/namespaces/instance/v1/custom_server.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -606,22 +606,27 @@ func serverDetachVolumeCommand() *core.Command {
606606
Namespace: "instance",
607607
Resource: "server",
608608
Verb: "detach-volume",
609-
ArgsType: reflect.TypeOf(instance.DetachVolumeRequest{}),
609+
ArgsType: reflect.TypeOf(instance.DetachServerVolumeRequest{}),
610610
ArgSpecs: core.ArgSpecs{
611611
{
612612
Name: "volume-id",
613613
Short: `ID of the volume to detach`,
614614
Required: true,
615615
},
616+
{
617+
Name: "server-id",
618+
Short: `ID of the server`,
619+
Required: true,
620+
},
616621
core.ZoneArgSpec((*instance.API)(nil).Zones()...),
617622
},
618623
Run: func(ctx context.Context, argsI any) (i any, err error) {
619-
request := argsI.(*instance.DetachVolumeRequest)
624+
request := argsI.(*instance.DetachServerVolumeRequest)
620625

621626
client := core.ExtractClient(ctx)
622627
api := instance.NewAPI(client)
623628

624-
return api.DetachVolume(request)
629+
return api.DetachServerVolume(request)
625630
},
626631
Examples: []*core.Example{
627632
{

internal/namespaces/instance/v1/custom_server_test.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,18 @@ func Test_ServerVolumeUpdate(t *testing.T) {
9595
"Server",
9696
testServerCommand("stopped=true image=ubuntu-jammy additional-volumes.0=block:10G"),
9797
),
98-
Cmd: `scw instance server detach-volume volume-id={{ (index .Server.Volumes "1").ID }}`,
98+
Cmd: `scw instance server detach-volume volume-id={{ (index .Server.Volumes "1").ID }} server-id={{ .Server.ID }}`,
9999
Check: func(t *testing.T, ctx *core.CheckFuncCtx) {
100100
t.Helper()
101101
require.NoError(t, ctx.Err)
102-
resp := testhelpers.Value[*instanceSDK.DetachVolumeResponse](t, ctx.Result)
102+
resp := testhelpers.Value[*instanceSDK.DetachServerVolumeResponse](t, ctx.Result)
103103
assert.NotZero(t, resp.Server.Volumes["0"])
104104
assert.Nil(t, resp.Server.Volumes["1"])
105-
assert.Len(t, ctx.Result.(*instanceSDK.DetachVolumeResponse).Server.Volumes, 1)
105+
assert.Len(
106+
t,
107+
ctx.Result.(*instanceSDK.DetachServerVolumeResponse).Server.Volumes,
108+
1,
109+
)
106110
},
107111
AfterFunc: core.AfterFuncCombine(
108112
core.ExecAfterCmd(
@@ -117,7 +121,7 @@ func Test_ServerVolumeUpdate(t *testing.T) {
117121
t.Run("invalid volume UUID", core.Test(&core.TestConfig{
118122
Commands: instance.GetCommands(),
119123
BeforeFunc: createServer("Server"),
120-
Cmd: "scw instance server detach-volume volume-id=11111111-1111-1111-1111-111111111111",
124+
Cmd: "scw instance server detach-volume volume-id=11111111-1111-1111-1111-111111111111 server-id={{ .Server.ID }}",
121125
Check: core.TestCheckCombine(
122126
core.TestCheckGolden(),
123127
core.TestCheckExitCode(1),

internal/namespaces/instance/v1/helpers_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ func createNonEmptyLocalVolume(metaKey string, sizeInGB int) core.BeforeFunc {
148148
volume := createServerResponse.Server.Volumes["0"]
149149
ctx.Meta[metaKey] = volume
150150

151-
cmd = "scw instance server detach-volume volume-id=" + volume.ID
151+
cmd = "scw instance server detach-volume volume-id=" + volume.ID + " server-id=" + serverID
152152
_ = ctx.ExecuteCmd(strings.Split(cmd, " "))
153153

154154
cmd = "scw instance server delete " + serverID

internal/namespaces/instance/v1/testdata/test-server-volume-update-detach-invalid-volume-uuid.cassette.yaml

Lines changed: 1363 additions & 1239 deletions
Large diffs are not rendered by default.
Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,24 @@
11
🎲🎲🎲 EXIT CODE: 1 🎲🎲🎲
22
🟥🟥🟥 STDERR️️ 🟥🟥🟥️
3-
Cannot find resource 'volume' with ID '11111111-1111-1111-1111-111111111111'
3+
Invalid arguments 'volume_id'
4+
5+
Details:
6+
- 'volume_id' does not respect constraints
7+
8+
Hint:
9+
Volume 11111111-1111-1111-1111-111111111111 is not attached to this server
410
🟥🟥🟥 JSON STDERR 🟥🟥🟥
511
{
6-
"message": "cannot find resource 'volume' with ID '11111111-1111-1111-1111-111111111111'",
12+
"message": "invalid arguments 'volume_id'",
713
"error": {
8-
"resource": "volume",
9-
"resource_id": "11111111-1111-1111-1111-111111111111"
10-
}
14+
"details": [
15+
{
16+
"argument_name": "volume_id",
17+
"reason": "constraint",
18+
"help_message": "Volume 11111111-1111-1111-1111-111111111111 is not attached to this server"
19+
}
20+
]
21+
},
22+
"details": "- 'volume_id' does not respect constraints",
23+
"hint": "Volume 11111111-1111-1111-1111-111111111111 is not attached to this server"
1124
}

0 commit comments

Comments
 (0)