From ada2074194397b05fae12b30543a43dbaf489001 Mon Sep 17 00:00:00 2001 From: Olivier CANO Date: Wed, 8 Apr 2020 19:06:09 +0200 Subject: [PATCH 1/7] try to add tests --- .../namespaces/instance/v1/custom_image.go | 4 ++++ .../instance/v1/custom_image_test.go | 21 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/internal/namespaces/instance/v1/custom_image.go b/internal/namespaces/instance/v1/custom_image.go index 73e1602176..fa06b8a75c 100644 --- a/internal/namespaces/instance/v1/custom_image.go +++ b/internal/namespaces/instance/v1/custom_image.go @@ -135,6 +135,10 @@ func imageListBuilder(c *core.Command) *core.Command { } getServerResponse, err := api.GetServer(&serverReq) if err != nil { + //if _, ok := err.(*scw.ResourceNotFoundError); ok { + // newCustomImage.ServerName = "-" + // continue + //} return nil, err } newCustomImage.ServerID = getServerResponse.Server.ID diff --git a/internal/namespaces/instance/v1/custom_image_test.go b/internal/namespaces/instance/v1/custom_image_test.go index 9d490e4667..afc7c23d56 100644 --- a/internal/namespaces/instance/v1/custom_image_test.go +++ b/internal/namespaces/instance/v1/custom_image_test.go @@ -24,4 +24,25 @@ func Test_ImageCreate(t *testing.T) { deleteSnapshot("Snapshot"), ), })) + + t.Run("List images", core.Test(&core.TestConfig{ + BeforeFunc: core.BeforeFuncCombine( + createServer("Server"), + core.ExecStoreBeforeCmd("Snapshot", `scw instance snapshot create volume-id={{ (index .Server.Volumes "0").ID }}`), + core.ExecStoreBeforeCmd("DeletedServer", `scw instance server delete {{ .Server.ID }} with-ip=true with-volumes=all`), + ), + Commands: GetCommands(), + Cmd: "scw instance image create snapshot-id={{ .Snapshot.Snapshot.ID }} arch=x86_64", + Check: core.TestCheckCombine( + core.TestCheckGolden(), + core.TestCheckExitCode(0), + ), + AfterFunc: core.AfterFuncCombine( + func(ctx *core.AfterFuncCtx) error { + ctx.ExecuteCmd("scw instance image delete " + ctx.CmdResult.(*instance.CreateImageResponse).Image.ID) + return nil + }, + deleteSnapshot("Snapshot"), + ), + })) } From 570b7f47d39fc193f5209e91e131f47c59bb51ef Mon Sep 17 00:00:00 2001 From: Olivier CANO Date: Wed, 8 Apr 2020 19:06:23 +0200 Subject: [PATCH 2/7] remove tests --- .../namespaces/instance/v1/custom_image.go | 8 +- .../instance/v1/custom_image_test.go | 21 --- ...est-image-create-list-images.cassette.yaml | 128 ++++++++++++++++++ ...est-image-create-list-images.stdout.golden | 3 + 4 files changed, 135 insertions(+), 25 deletions(-) create mode 100644 internal/namespaces/instance/v1/testdata/test-image-create-list-images.cassette.yaml create mode 100644 internal/namespaces/instance/v1/testdata/test-image-create-list-images.stdout.golden diff --git a/internal/namespaces/instance/v1/custom_image.go b/internal/namespaces/instance/v1/custom_image.go index fa06b8a75c..92dd725224 100644 --- a/internal/namespaces/instance/v1/custom_image.go +++ b/internal/namespaces/instance/v1/custom_image.go @@ -135,10 +135,10 @@ func imageListBuilder(c *core.Command) *core.Command { } getServerResponse, err := api.GetServer(&serverReq) if err != nil { - //if _, ok := err.(*scw.ResourceNotFoundError); ok { - // newCustomImage.ServerName = "-" - // continue - //} + if _, ok := err.(*scw.ResourceNotFoundError); ok { + newCustomImage.ServerName = "-" + continue + } return nil, err } newCustomImage.ServerID = getServerResponse.Server.ID diff --git a/internal/namespaces/instance/v1/custom_image_test.go b/internal/namespaces/instance/v1/custom_image_test.go index afc7c23d56..9d490e4667 100644 --- a/internal/namespaces/instance/v1/custom_image_test.go +++ b/internal/namespaces/instance/v1/custom_image_test.go @@ -24,25 +24,4 @@ func Test_ImageCreate(t *testing.T) { deleteSnapshot("Snapshot"), ), })) - - t.Run("List images", core.Test(&core.TestConfig{ - BeforeFunc: core.BeforeFuncCombine( - createServer("Server"), - core.ExecStoreBeforeCmd("Snapshot", `scw instance snapshot create volume-id={{ (index .Server.Volumes "0").ID }}`), - core.ExecStoreBeforeCmd("DeletedServer", `scw instance server delete {{ .Server.ID }} with-ip=true with-volumes=all`), - ), - Commands: GetCommands(), - Cmd: "scw instance image create snapshot-id={{ .Snapshot.Snapshot.ID }} arch=x86_64", - Check: core.TestCheckCombine( - core.TestCheckGolden(), - core.TestCheckExitCode(0), - ), - AfterFunc: core.AfterFuncCombine( - func(ctx *core.AfterFuncCtx) error { - ctx.ExecuteCmd("scw instance image delete " + ctx.CmdResult.(*instance.CreateImageResponse).Image.ID) - return nil - }, - deleteSnapshot("Snapshot"), - ), - })) } diff --git a/internal/namespaces/instance/v1/testdata/test-image-create-list-images.cassette.yaml b/internal/namespaces/instance/v1/testdata/test-image-create-list-images.cassette.yaml new file mode 100644 index 0000000000..61a7e240db --- /dev/null +++ b/internal/namespaces/instance/v1/testdata/test-image-create-list-images.cassette.yaml @@ -0,0 +1,128 @@ +--- +version: 1 +interactions: +- request: + body: "" + form: {} + headers: + User-Agent: + - scaleway-sdk-go/v1.0.0-beta.6+dev (go1.13.7; darwin; amd64) cli-e2e-test + url: https://api.scaleway.com/instance/v1/zones/fr-par-1/images?page=1&public=false + method: GET + response: + body: '{"images": [{"id": "c5371903-0ace-40de-8c76-c26479264baa", "name": "test-cli", + "organization": "b2593aa3-d0e8-4366-89c3-6e666abe1f6f", "root_volume": {"id": + "85d26247-8b27-4cb2-8853-df8dc7da256e", "name": "test-cli_snap_0", "volume_type": + "l_ssd", "size": 20000000000}, "extra_volumes": {}, "public": false, "arch": + "x86_64", "creation_date": "2020-04-08T16:09:17.791308+00:00", "modification_date": + "2020-04-08T16:09:17.791308+00:00", "default_bootscript": {"id": "15fbd2f7-a0f9-412b-8502-6a44da8d98b8", + "public": false, "title": "x86_64 mainline 4.9.93 rev1", "architecture": "x86_64", + "organization": "11111111-1111-4111-8111-111111111111", "kernel": "http://169.254.42.24/kernel/x86_64-mainline-lts-4.9-4.9.93-rev1/vmlinuz-4.9.93", + "dtb": "", "initrd": "http://169.254.42.24/initrd/initrd-Linux-x86_64-v3.14.6.gz", + "bootcmdargs": "LINUX_COMMON scaleway boot=local nbd.max_part=16", "default": + false, "zone": "fr-par-1"}, "from_server": "748baef5-e858-45c4-b090-f01c4db8b8dc", + "state": "available", "zone": "fr-par-1"}, {"id": "99344168-3dff-4b5c-9d81-6730c1e04d30", + "name": "cli-img-laughing-noyce", "organization": "b2593aa3-d0e8-4366-89c3-6e666abe1f6f", + "root_volume": {"id": "5f90cf0d-c36a-46ad-b947-f4e2d9eb87c5", "name": "cli-snp-festive-hertz", + "volume_type": "l_ssd", "size": 20000000000}, "extra_volumes": {}, "public": + false, "arch": "x86_64", "creation_date": "2020-04-08T15:54:25.954633+00:00", + "modification_date": "2020-04-08T15:54:25.954633+00:00", "default_bootscript": + null, "from_server": null, "state": "available", "zone": "fr-par-1"}]}' + headers: + Cache-Control: + - no-cache + Content-Length: + - "1559" + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Wed, 08 Apr 2020 17:04:44 GMT + Link: + - ; rel="last" + Server: + - scaleway_api + Strict-Transport-Security: + - max-age=63072000 + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + X-Request-Id: + - 2ab5e661-a6e5-415c-b3e9-7203ddd2fc15 + X-Total-Count: + - "2" + status: 200 OK + code: 200 + duration: "" +- request: + body: "" + form: {} + headers: + User-Agent: + - scaleway-sdk-go/v1.0.0-beta.6+dev (go1.13.7; darwin; amd64) cli-e2e-test + url: https://api.scaleway.com/instance/v1/zones/fr-par-1/servers/748baef5-e858-45c4-b090-f01c4db8b8dc + method: GET + response: + body: '{"server": {"id": "748baef5-e858-45c4-b090-f01c4db8b8dc", "name": "scw-objective-snyder", + "arch": "x86_64", "commercial_type": "DEV1-S", "boot_type": "local", "organization": + "b2593aa3-d0e8-4366-89c3-6e666abe1f6f", "hostname": "scw-objective-snyder", + "image": {"id": "f974feac-abae-4365-b988-8ec7d1cec10d", "name": "Ubuntu Bionic + Beaver", "organization": "51b656e3-4865-41e8-adbc-0c45bdd780db", "root_volume": + {"id": "dd5f5c10-23b1-4c9c-8445-eb6740957c84", "name": "snapshot-de728daa-0bf6-4c64-abf5-a9477e791c83-2019-03-05_10:13", + "volume_type": "l_ssd", "size": 10000000000}, "extra_volumes": {}, "public": + true, "arch": "x86_64", "creation_date": "2019-03-05T10:13:15.974944+00:00", + "modification_date": "2019-03-05T13:32:29.274319+00:00", "default_bootscript": + {"id": "15fbd2f7-a0f9-412b-8502-6a44da8d98b8", "public": false, "title": "x86_64 + mainline 4.9.93 rev1", "architecture": "x86_64", "organization": "11111111-1111-4111-8111-111111111111", + "kernel": "http://169.254.42.24/kernel/x86_64-mainline-lts-4.9-4.9.93-rev1/vmlinuz-4.9.93", + "dtb": "", "initrd": "http://169.254.42.24/initrd/initrd-Linux-x86_64-v3.14.6.gz", + "bootcmdargs": "LINUX_COMMON scaleway boot=local nbd.max_part=16", "default": + false, "zone": "fr-par-1"}, "from_server": null, "state": "available", "zone": + "fr-par-1"}, "volumes": {"0": {"id": "963ad6a2-975d-40f7-8b21-9ae524c83889", + "name": "snapshot-de728daa-0bf6-4c64-abf5-a9477e791c83-2019-03-05_10:13", "volume_type": + "l_ssd", "export_uri": null, "organization": "b2593aa3-d0e8-4366-89c3-6e666abe1f6f", + "server": {"id": "748baef5-e858-45c4-b090-f01c4db8b8dc", "name": "scw-objective-snyder"}, + "size": 20000000000, "state": "available", "creation_date": "2020-02-06T20:29:56.860210+00:00", + "modification_date": "2020-04-08T16:22:40.291254+00:00", "zone": "fr-par-1"}}, + "tags": ["reddit-tracker", "prod"], "state": "running", "protected": true, "state_detail": + "booting kernel", "public_ip": {"id": "2c453330-0286-4986-ab36-a7f9aee549fd", + "address": "51.158.72.139", "dynamic": false}, "ipv6": {"address": "2001:bc8:604:b20::1", + "gateway": "2001:bc8:604:b20::", "netmask": "64"}, "extra_networks": [], "dynamic_ip_required": + false, "enable_ipv6": true, "private_ip": "10.68.102.65", "creation_date": "2020-02-06T20:29:56.860210+00:00", + "modification_date": "2020-02-10T15:02:11.628299+00:00", "bootscript": {"id": + "15fbd2f7-a0f9-412b-8502-6a44da8d98b8", "public": false, "title": "x86_64 mainline + 4.9.93 rev1", "architecture": "x86_64", "organization": "11111111-1111-4111-8111-111111111111", + "kernel": "http://169.254.42.24/kernel/x86_64-mainline-lts-4.9-4.9.93-rev1/vmlinuz-4.9.93", + "dtb": "", "initrd": "http://169.254.42.24/initrd/initrd-Linux-x86_64-v3.14.6.gz", + "bootcmdargs": "LINUX_COMMON scaleway boot=local nbd.max_part=16", "default": + false, "zone": "fr-par-1"}, "security_group": {"id": "980142a3-a959-4aee-8325-91a6ba787439", + "name": "Default security group"}, "location": {"zone_id": "par1", "platform_id": + "14", "cluster_id": "36", "hypervisor_id": "602", "node_id": "33"}, "maintenances": + [], "allowed_actions": ["backup"], "placement_group": null, "compute_cluster": + null, "private_nics": [], "zone": "fr-par-1"}}' + headers: + Cache-Control: + - no-cache + Content-Length: + - "3158" + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Wed, 08 Apr 2020 17:04:45 GMT + Server: + - scaleway_api + Strict-Transport-Security: + - max-age=63072000 + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + X-Request-Id: + - 12d28031-5d65-4a85-ae8c-284640193459 + status: 200 OK + code: 200 + duration: "" diff --git a/internal/namespaces/instance/v1/testdata/test-image-create-list-images.stdout.golden b/internal/namespaces/instance/v1/testdata/test-image-create-list-images.stdout.golden new file mode 100644 index 0000000000..77502a12ca --- /dev/null +++ b/internal/namespaces/instance/v1/testdata/test-image-create-list-images.stdout.golden @@ -0,0 +1,3 @@ +ID NAME ARCH CREATION DATE MODIFICATION DATE DEFAULT BOOTSCRIPT EXTRA VOLUMES ORGANIZATION PUBLIC ROOT VOLUME STATE SERVER ID SERVER NAME ZONE +c5371903-0ace-40de-8c76-c26479264baa test-cli x86_64 few seconds ago few seconds ago x86_64 mainline 4.9.93 rev1 0 b2593aa3-d0e8-4366-89c3-6e666abe1f6f false 85d26247-8b27-4cb2-8853-df8dc7da256e available 748baef5-e858-45c4-b090-f01c4db8b8dc scw-objective-snyder fr-par-1 +99344168-3dff-4b5c-9d81-6730c1e04d30 cli-img-laughing-noyce x86_64 few seconds ago few seconds ago 0 b2593aa3-d0e8-4366-89c3-6e666abe1f6f false 5f90cf0d-c36a-46ad-b947-f4e2d9eb87c5 available - - fr-par-1 From 84a97f36c8ff7c4dbb49b1cab9c4464310a4335e Mon Sep 17 00:00:00 2001 From: Olivier CANO Date: Wed, 8 Apr 2020 19:08:20 +0200 Subject: [PATCH 3/7] fix images --- ...est-image-create-list-images.cassette.yaml | 128 ------------------ ...est-image-create-list-images.stdout.golden | 3 - 2 files changed, 131 deletions(-) delete mode 100644 internal/namespaces/instance/v1/testdata/test-image-create-list-images.cassette.yaml delete mode 100644 internal/namespaces/instance/v1/testdata/test-image-create-list-images.stdout.golden diff --git a/internal/namespaces/instance/v1/testdata/test-image-create-list-images.cassette.yaml b/internal/namespaces/instance/v1/testdata/test-image-create-list-images.cassette.yaml deleted file mode 100644 index 61a7e240db..0000000000 --- a/internal/namespaces/instance/v1/testdata/test-image-create-list-images.cassette.yaml +++ /dev/null @@ -1,128 +0,0 @@ ---- -version: 1 -interactions: -- request: - body: "" - form: {} - headers: - User-Agent: - - scaleway-sdk-go/v1.0.0-beta.6+dev (go1.13.7; darwin; amd64) cli-e2e-test - url: https://api.scaleway.com/instance/v1/zones/fr-par-1/images?page=1&public=false - method: GET - response: - body: '{"images": [{"id": "c5371903-0ace-40de-8c76-c26479264baa", "name": "test-cli", - "organization": "b2593aa3-d0e8-4366-89c3-6e666abe1f6f", "root_volume": {"id": - "85d26247-8b27-4cb2-8853-df8dc7da256e", "name": "test-cli_snap_0", "volume_type": - "l_ssd", "size": 20000000000}, "extra_volumes": {}, "public": false, "arch": - "x86_64", "creation_date": "2020-04-08T16:09:17.791308+00:00", "modification_date": - "2020-04-08T16:09:17.791308+00:00", "default_bootscript": {"id": "15fbd2f7-a0f9-412b-8502-6a44da8d98b8", - "public": false, "title": "x86_64 mainline 4.9.93 rev1", "architecture": "x86_64", - "organization": "11111111-1111-4111-8111-111111111111", "kernel": "http://169.254.42.24/kernel/x86_64-mainline-lts-4.9-4.9.93-rev1/vmlinuz-4.9.93", - "dtb": "", "initrd": "http://169.254.42.24/initrd/initrd-Linux-x86_64-v3.14.6.gz", - "bootcmdargs": "LINUX_COMMON scaleway boot=local nbd.max_part=16", "default": - false, "zone": "fr-par-1"}, "from_server": "748baef5-e858-45c4-b090-f01c4db8b8dc", - "state": "available", "zone": "fr-par-1"}, {"id": "99344168-3dff-4b5c-9d81-6730c1e04d30", - "name": "cli-img-laughing-noyce", "organization": "b2593aa3-d0e8-4366-89c3-6e666abe1f6f", - "root_volume": {"id": "5f90cf0d-c36a-46ad-b947-f4e2d9eb87c5", "name": "cli-snp-festive-hertz", - "volume_type": "l_ssd", "size": 20000000000}, "extra_volumes": {}, "public": - false, "arch": "x86_64", "creation_date": "2020-04-08T15:54:25.954633+00:00", - "modification_date": "2020-04-08T15:54:25.954633+00:00", "default_bootscript": - null, "from_server": null, "state": "available", "zone": "fr-par-1"}]}' - headers: - Cache-Control: - - no-cache - Content-Length: - - "1559" - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - application/json - Date: - - Wed, 08 Apr 2020 17:04:44 GMT - Link: - - ; rel="last" - Server: - - scaleway_api - Strict-Transport-Security: - - max-age=63072000 - X-Content-Type-Options: - - nosniff - X-Frame-Options: - - DENY - X-Request-Id: - - 2ab5e661-a6e5-415c-b3e9-7203ddd2fc15 - X-Total-Count: - - "2" - status: 200 OK - code: 200 - duration: "" -- request: - body: "" - form: {} - headers: - User-Agent: - - scaleway-sdk-go/v1.0.0-beta.6+dev (go1.13.7; darwin; amd64) cli-e2e-test - url: https://api.scaleway.com/instance/v1/zones/fr-par-1/servers/748baef5-e858-45c4-b090-f01c4db8b8dc - method: GET - response: - body: '{"server": {"id": "748baef5-e858-45c4-b090-f01c4db8b8dc", "name": "scw-objective-snyder", - "arch": "x86_64", "commercial_type": "DEV1-S", "boot_type": "local", "organization": - "b2593aa3-d0e8-4366-89c3-6e666abe1f6f", "hostname": "scw-objective-snyder", - "image": {"id": "f974feac-abae-4365-b988-8ec7d1cec10d", "name": "Ubuntu Bionic - Beaver", "organization": "51b656e3-4865-41e8-adbc-0c45bdd780db", "root_volume": - {"id": "dd5f5c10-23b1-4c9c-8445-eb6740957c84", "name": "snapshot-de728daa-0bf6-4c64-abf5-a9477e791c83-2019-03-05_10:13", - "volume_type": "l_ssd", "size": 10000000000}, "extra_volumes": {}, "public": - true, "arch": "x86_64", "creation_date": "2019-03-05T10:13:15.974944+00:00", - "modification_date": "2019-03-05T13:32:29.274319+00:00", "default_bootscript": - {"id": "15fbd2f7-a0f9-412b-8502-6a44da8d98b8", "public": false, "title": "x86_64 - mainline 4.9.93 rev1", "architecture": "x86_64", "organization": "11111111-1111-4111-8111-111111111111", - "kernel": "http://169.254.42.24/kernel/x86_64-mainline-lts-4.9-4.9.93-rev1/vmlinuz-4.9.93", - "dtb": "", "initrd": "http://169.254.42.24/initrd/initrd-Linux-x86_64-v3.14.6.gz", - "bootcmdargs": "LINUX_COMMON scaleway boot=local nbd.max_part=16", "default": - false, "zone": "fr-par-1"}, "from_server": null, "state": "available", "zone": - "fr-par-1"}, "volumes": {"0": {"id": "963ad6a2-975d-40f7-8b21-9ae524c83889", - "name": "snapshot-de728daa-0bf6-4c64-abf5-a9477e791c83-2019-03-05_10:13", "volume_type": - "l_ssd", "export_uri": null, "organization": "b2593aa3-d0e8-4366-89c3-6e666abe1f6f", - "server": {"id": "748baef5-e858-45c4-b090-f01c4db8b8dc", "name": "scw-objective-snyder"}, - "size": 20000000000, "state": "available", "creation_date": "2020-02-06T20:29:56.860210+00:00", - "modification_date": "2020-04-08T16:22:40.291254+00:00", "zone": "fr-par-1"}}, - "tags": ["reddit-tracker", "prod"], "state": "running", "protected": true, "state_detail": - "booting kernel", "public_ip": {"id": "2c453330-0286-4986-ab36-a7f9aee549fd", - "address": "51.158.72.139", "dynamic": false}, "ipv6": {"address": "2001:bc8:604:b20::1", - "gateway": "2001:bc8:604:b20::", "netmask": "64"}, "extra_networks": [], "dynamic_ip_required": - false, "enable_ipv6": true, "private_ip": "10.68.102.65", "creation_date": "2020-02-06T20:29:56.860210+00:00", - "modification_date": "2020-02-10T15:02:11.628299+00:00", "bootscript": {"id": - "15fbd2f7-a0f9-412b-8502-6a44da8d98b8", "public": false, "title": "x86_64 mainline - 4.9.93 rev1", "architecture": "x86_64", "organization": "11111111-1111-4111-8111-111111111111", - "kernel": "http://169.254.42.24/kernel/x86_64-mainline-lts-4.9-4.9.93-rev1/vmlinuz-4.9.93", - "dtb": "", "initrd": "http://169.254.42.24/initrd/initrd-Linux-x86_64-v3.14.6.gz", - "bootcmdargs": "LINUX_COMMON scaleway boot=local nbd.max_part=16", "default": - false, "zone": "fr-par-1"}, "security_group": {"id": "980142a3-a959-4aee-8325-91a6ba787439", - "name": "Default security group"}, "location": {"zone_id": "par1", "platform_id": - "14", "cluster_id": "36", "hypervisor_id": "602", "node_id": "33"}, "maintenances": - [], "allowed_actions": ["backup"], "placement_group": null, "compute_cluster": - null, "private_nics": [], "zone": "fr-par-1"}}' - headers: - Cache-Control: - - no-cache - Content-Length: - - "3158" - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - application/json - Date: - - Wed, 08 Apr 2020 17:04:45 GMT - Server: - - scaleway_api - Strict-Transport-Security: - - max-age=63072000 - X-Content-Type-Options: - - nosniff - X-Frame-Options: - - DENY - X-Request-Id: - - 12d28031-5d65-4a85-ae8c-284640193459 - status: 200 OK - code: 200 - duration: "" diff --git a/internal/namespaces/instance/v1/testdata/test-image-create-list-images.stdout.golden b/internal/namespaces/instance/v1/testdata/test-image-create-list-images.stdout.golden deleted file mode 100644 index 77502a12ca..0000000000 --- a/internal/namespaces/instance/v1/testdata/test-image-create-list-images.stdout.golden +++ /dev/null @@ -1,3 +0,0 @@ -ID NAME ARCH CREATION DATE MODIFICATION DATE DEFAULT BOOTSCRIPT EXTRA VOLUMES ORGANIZATION PUBLIC ROOT VOLUME STATE SERVER ID SERVER NAME ZONE -c5371903-0ace-40de-8c76-c26479264baa test-cli x86_64 few seconds ago few seconds ago x86_64 mainline 4.9.93 rev1 0 b2593aa3-d0e8-4366-89c3-6e666abe1f6f false 85d26247-8b27-4cb2-8853-df8dc7da256e available 748baef5-e858-45c4-b090-f01c4db8b8dc scw-objective-snyder fr-par-1 -99344168-3dff-4b5c-9d81-6730c1e04d30 cli-img-laughing-noyce x86_64 few seconds ago few seconds ago 0 b2593aa3-d0e8-4366-89c3-6e666abe1f6f false 5f90cf0d-c36a-46ad-b947-f4e2d9eb87c5 available - - fr-par-1 From bb8ec9368feb51f3c63ad26e835cdae6b395c572 Mon Sep 17 00:00:00 2001 From: Olivier CANO Date: Tue, 14 Apr 2020 18:35:09 +0200 Subject: [PATCH 4/7] wip --- .../namespaces/instance/v1/custom_image.go | 32 ++++++++++--------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/internal/namespaces/instance/v1/custom_image.go b/internal/namespaces/instance/v1/custom_image.go index 92dd725224..0029f1e57f 100644 --- a/internal/namespaces/instance/v1/custom_image.go +++ b/internal/namespaces/instance/v1/custom_image.go @@ -127,24 +127,26 @@ func imageListBuilder(c *core.Command) *core.Command { State: image.State, Zone: image.Zone, } + customImages = append(customImages, newCustomImage) - if image.FromServer != "" { - serverReq := instance.GetServerRequest{ - Zone: req.Zone, - ServerID: image.FromServer, - } - getServerResponse, err := api.GetServer(&serverReq) - if err != nil { - if _, ok := err.(*scw.ResourceNotFoundError); ok { - newCustomImage.ServerName = "-" - continue - } - return nil, err + if image.FromServer == "" { + continue + } + + serverReq := instance.GetServerRequest{ + Zone: req.Zone, + ServerID: image.FromServer, + } + getServerResponse, err := api.GetServer(&serverReq) + if err != nil { + if _, ok := err.(*scw.ResourceNotFoundError); ok { + newCustomImage.ServerName = "-" + continue } - newCustomImage.ServerID = getServerResponse.Server.ID - newCustomImage.ServerName = getServerResponse.Server.Name + return nil, err } - customImages = append(customImages, newCustomImage) + newCustomImage.ServerID = getServerResponse.Server.ID + newCustomImage.ServerName = getServerResponse.Server.Name } return customImages, nil From 2a10e638668bc82bb670c7eb93f4621f5854b1db Mon Sep 17 00:00:00 2001 From: Olivier CANO Date: Fri, 17 Apr 2020 11:15:14 +0200 Subject: [PATCH 5/7] update sdk --- go.mod | 2 +- go.sum | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index f3209fc9bd..949c63a386 100644 --- a/go.mod +++ b/go.mod @@ -20,7 +20,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.20200409105057-297e3dbdccb5 + github.com/scaleway/scaleway-sdk-go v1.0.0-beta.6.0.20200414183251-a6244a393e63 github.com/sergi/go-diff v1.0.0 // indirect github.com/spf13/cobra v0.0.5 github.com/spf13/pflag v1.0.5 // indirect diff --git a/go.sum b/go.sum index 920eddea66..86c8d9fe07 100644 --- a/go.sum +++ b/go.sum @@ -67,6 +67,8 @@ github.com/scaleway/scaleway-sdk-go v1.0.0-beta.6.0.20200403173805-25a10631420d github.com/scaleway/scaleway-sdk-go v1.0.0-beta.6.0.20200403173805-25a10631420d/go.mod h1:CJJ5VAbozOl0yEw7nHB9+7BXTJbIn6h7W+f6Gau5IP8= github.com/scaleway/scaleway-sdk-go v1.0.0-beta.6.0.20200409105057-297e3dbdccb5 h1:QmrgbtSAIDKRTnzAjdpop3yFAqHFO4MEc8W+/0Epu88= github.com/scaleway/scaleway-sdk-go v1.0.0-beta.6.0.20200409105057-297e3dbdccb5/go.mod h1:CJJ5VAbozOl0yEw7nHB9+7BXTJbIn6h7W+f6Gau5IP8= +github.com/scaleway/scaleway-sdk-go v1.0.0-beta.6.0.20200414183251-a6244a393e63 h1:8tRzNwnY+PK6TD21bvKU0p334p+kApiKdHRO3xsZgpg= +github.com/scaleway/scaleway-sdk-go v1.0.0-beta.6.0.20200414183251-a6244a393e63/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= From 2f0a91968745e4fbd2f6e2dbd48ec430cea5f0cd Mon Sep 17 00:00:00 2001 From: Olivier CANO Date: Fri, 17 Apr 2020 11:18:51 +0200 Subject: [PATCH 6/7] refacto --- internal/namespaces/instance/v1/custom_image.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/internal/namespaces/instance/v1/custom_image.go b/internal/namespaces/instance/v1/custom_image.go index 0029f1e57f..70a533ec05 100644 --- a/internal/namespaces/instance/v1/custom_image.go +++ b/internal/namespaces/instance/v1/custom_image.go @@ -138,11 +138,11 @@ func imageListBuilder(c *core.Command) *core.Command { ServerID: image.FromServer, } getServerResponse, err := api.GetServer(&serverReq) + if _, ok := err.(*scw.ResourceNotFoundError); ok { + newCustomImage.ServerName = "-" + continue + } if err != nil { - if _, ok := err.(*scw.ResourceNotFoundError); ok { - newCustomImage.ServerName = "-" - continue - } return nil, err } newCustomImage.ServerID = getServerResponse.Server.ID From 3749322dbf475d19875ce0c575b8dd6c8d473072 Mon Sep 17 00:00:00 2001 From: Olivier CANO Date: Fri, 17 Apr 2020 11:24:49 +0200 Subject: [PATCH 7/7] update goldens --- ...reate-server-errors-error-invalid-image-uuid.stderr.golden | 4 ++-- ...ement-group-id=valid,-but-non-existing-pg-id.stderr.golden | 2 +- ...ver-volume-update-attach-invalid-volume-uuid.stderr.golden | 2 +- ...ver-volume-update-detach-invalid-volume-uuid.stderr.golden | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/internal/namespaces/instance/v1/testdata/test-create-server-errors-error-invalid-image-uuid.stderr.golden b/internal/namespaces/instance/v1/testdata/test-create-server-errors-error-invalid-image-uuid.stderr.golden index 0498fbd4fc..91cf81d344 100644 --- a/internal/namespaces/instance/v1/testdata/test-create-server-errors-error-invalid-image-uuid.stderr.golden +++ b/internal/namespaces/instance/v1/testdata/test-create-server-errors-error-invalid-image-uuid.stderr.golden @@ -1,3 +1,3 @@ -WARNING: 2019/12/09 16:04:07 cannot get image 7a892c1a-bbdc-491f-9974-4008e3708664: scaleway-sdk-go: http error 404 Not Found: "7a892c1a-bbdc-491f-9974-4008e3708664" not found +WARNING: 2019/12/09 16:04:07 cannot get image 7a892c1a-bbdc-491f-9974-4008e3708664: scaleway-sdk-go: resource with ID 7a892c1a-bbdc-491f-9974-4008e3708664 is not found WARNING: 2019/12/09 16:04:07 skipping image server-type compatibility validation -Cannot create the server: scaleway-sdk-go: http error 404 Not Found: "7a892c1a-bbdc-491f-9974-4008e3708664" not found +Cannot create the server: scaleway-sdk-go: resource with ID 7a892c1a-bbdc-491f-9974-4008e3708664 is not found diff --git a/internal/namespaces/instance/v1/testdata/test-server-update-no-initial-placement-group&-placement-group-id=valid,-but-non-existing-pg-id.stderr.golden b/internal/namespaces/instance/v1/testdata/test-server-update-no-initial-placement-group&-placement-group-id=valid,-but-non-existing-pg-id.stderr.golden index 503f45c26c..71e5bb0e4d 100644 --- a/internal/namespaces/instance/v1/testdata/test-server-update-no-initial-placement-group&-placement-group-id=valid,-but-non-existing-pg-id.stderr.golden +++ b/internal/namespaces/instance/v1/testdata/test-server-update-no-initial-placement-group&-placement-group-id=valid,-but-non-existing-pg-id.stderr.golden @@ -1 +1 @@ -"11111111-1111-1111-1111-111111111111" not found +Cannot find resource '' with ID '11111111-1111-1111-1111-111111111111' diff --git a/internal/namespaces/instance/v1/testdata/test-server-volume-update-attach-invalid-volume-uuid.stderr.golden b/internal/namespaces/instance/v1/testdata/test-server-volume-update-attach-invalid-volume-uuid.stderr.golden index 503f45c26c..71e5bb0e4d 100644 --- a/internal/namespaces/instance/v1/testdata/test-server-volume-update-attach-invalid-volume-uuid.stderr.golden +++ b/internal/namespaces/instance/v1/testdata/test-server-volume-update-attach-invalid-volume-uuid.stderr.golden @@ -1 +1 @@ -"11111111-1111-1111-1111-111111111111" not found +Cannot find resource '' with ID '11111111-1111-1111-1111-111111111111' diff --git a/internal/namespaces/instance/v1/testdata/test-server-volume-update-detach-invalid-volume-uuid.stderr.golden b/internal/namespaces/instance/v1/testdata/test-server-volume-update-detach-invalid-volume-uuid.stderr.golden index 503f45c26c..71e5bb0e4d 100644 --- a/internal/namespaces/instance/v1/testdata/test-server-volume-update-detach-invalid-volume-uuid.stderr.golden +++ b/internal/namespaces/instance/v1/testdata/test-server-volume-update-detach-invalid-volume-uuid.stderr.golden @@ -1 +1 @@ -"11111111-1111-1111-1111-111111111111" not found +Cannot find resource '' with ID '11111111-1111-1111-1111-111111111111'