diff --git a/scaleway/scaleway/instance/v1/tests/cassettes/server.cassette.yaml b/scaleway/scaleway/instance/v1/tests/cassettes/server.cassette.yaml new file mode 100644 index 000000000..20eeefb7b --- /dev/null +++ b/scaleway/scaleway/instance/v1/tests/cassettes/server.cassette.yaml @@ -0,0 +1,124 @@ +interactions: +- request: + body: '{"project": "11111111-1111-1111-1111-111111111111", "commercial_type": + "DEV1-S", "name": "test-sdk-python-fixture", "dynamic_ip_required": false, "image": + "c00ae53c-1e29-4087-a384-47f3c5c1cd84", "protected": false, "boot_type": "local"}' + headers: + Content-Length: + - '236' + user-agent: + - scaleway-sdk-python/2.0.0 + method: POST + uri: https://api.scaleway.com/instance/v1/zones/fr-par-1/servers + response: + body: + string: '{"server": {"id": "66a3b25b-4518-43c3-9e61-33b82873d617", "name": "test-sdk-python-fixture", + "arch": "x86_64", "commercial_type": "DEV1-S", "boot_type": "local", "organization": + "11111111-1111-1111-1111-111111111111", "project": "11111111-1111-1111-1111-111111111111", + "hostname": "test-sdk-python-fixture", "image": {"id": "c00ae53c-1e29-4087-a384-47f3c5c1cd84", + "name": "Ubuntu 20.04 Focal Fossa", "organization": "11111111-1111-1111-1111-111111111111", + "project": "11111111-1111-1111-1111-111111111111", "root_volume": {"id": "6644dfd6-0731-45cc-a581-62f561eff7bf", + "name": "Ubuntu 20.04 Focal Fossa", "volume_type": "l_ssd", "size": 10000000000}, + "extra_volumes": {}, "public": true, "arch": "x86_64", "creation_date": "2025-02-03T13:36:50.774356+00:00", + "modification_date": "2025-02-03T13:36:50.774356+00:00", "default_bootscript": + null, "from_server": "", "state": "available", "tags": [], "zone": "fr-par-1"}, + "volumes": {"0": {"boot": false, "id": "bda6aff6-7ca2-41de-a3fb-47be986c5c0a", + "name": "Ubuntu 20.04 Focal Fossa", "volume_type": "l_ssd", "export_uri": + null, "organization": "11111111-1111-1111-1111-111111111111", "project": "11111111-1111-1111-1111-111111111111", + "server": {"id": "66a3b25b-4518-43c3-9e61-33b82873d617", "name": "test-sdk-python-fixture"}, + "size": 20000000000, "state": "available", "creation_date": "2025-09-16T17:38:27.303680+00:00", + "modification_date": "2025-09-16T17:38:27.303680+00:00", "tags": [], "zone": + "fr-par-1"}}, "tags": [], "state": "stopped", "protected": false, "state_detail": + "", "public_ip": null, "public_ips": [], "mac_address": "de:00:00:c8:be:d7", + "routed_ip_enabled": true, "ipv6": null, "extra_networks": [], "dynamic_ip_required": + false, "enable_ipv6": false, "private_ip": null, "creation_date": "2025-09-16T17:38:27.303680+00:00", + "modification_date": "2025-09-16T17:38:27.303680+00:00", "bootscript": null, + "security_group": {"id": "1c1fc99f-b2de-408d-9eb0-da801a3e2744", "name": "Default + security group"}, "location": null, "maintenances": [], "allowed_actions": + ["poweron", "backup"], "placement_group": null, "private_nics": [], "zone": + "fr-par-1", "filesystems": [], "end_of_service": false}}' + headers: + content-length: + - '2163' + date: + - Tue, 16 Sep 2025 17:38:27 GMT + location: + - https://api.scaleway.com/instance/v1/zones/fr-par-1/servers/66a3b25b-4518-43c3-9e61-33b82873d617 + server: + - Scaleway API Gateway (fr-par-2;edge02) + x-request-id: + - cf1425a5-4c54-464b-bfa3-b175537ec160 + status: + code: 201 + message: Created +- request: + body: '{}' + headers: + Content-Length: + - '2' + user-agent: + - scaleway-sdk-python/2.0.0 + method: GET + uri: https://api.scaleway.com/instance/v1/zones/fr-par-1/servers/66a3b25b-4518-43c3-9e61-33b82873d617 + response: + body: + string: '{"server": {"id": "66a3b25b-4518-43c3-9e61-33b82873d617", "name": "test-sdk-python-fixture", + "arch": "x86_64", "commercial_type": "DEV1-S", "boot_type": "local", "organization": + "11111111-1111-1111-1111-111111111111", "project": "11111111-1111-1111-1111-111111111111", + "hostname": "test-sdk-python-fixture", "image": {"id": "c00ae53c-1e29-4087-a384-47f3c5c1cd84", + "name": "Ubuntu 20.04 Focal Fossa", "organization": "11111111-1111-1111-1111-111111111111", + "project": "11111111-1111-1111-1111-111111111111", "root_volume": {"id": "6644dfd6-0731-45cc-a581-62f561eff7bf", + "name": "Ubuntu 20.04 Focal Fossa", "volume_type": "l_ssd", "size": 10000000000}, + "extra_volumes": {}, "public": true, "arch": "x86_64", "creation_date": "2025-02-03T13:36:50.774356+00:00", + "modification_date": "2025-02-03T13:36:50.774356+00:00", "default_bootscript": + null, "from_server": "", "state": "available", "tags": [], "zone": "fr-par-1"}, + "volumes": {"0": {"boot": false, "id": "bda6aff6-7ca2-41de-a3fb-47be986c5c0a", + "name": "Ubuntu 20.04 Focal Fossa", "volume_type": "l_ssd", "export_uri": + null, "organization": "11111111-1111-1111-1111-111111111111", "project": "11111111-1111-1111-1111-111111111111", + "server": {"id": "66a3b25b-4518-43c3-9e61-33b82873d617", "name": "test-sdk-python-fixture"}, + "size": 20000000000, "state": "available", "creation_date": "2025-09-16T17:38:27.303680+00:00", + "modification_date": "2025-09-16T17:38:27.303680+00:00", "tags": [], "zone": + "fr-par-1"}}, "tags": [], "state": "stopped", "protected": false, "state_detail": + "", "public_ip": null, "public_ips": [], "mac_address": "de:00:00:c8:be:d7", + "routed_ip_enabled": true, "ipv6": null, "extra_networks": [], "dynamic_ip_required": + false, "enable_ipv6": false, "private_ip": null, "creation_date": "2025-09-16T17:38:27.303680+00:00", + "modification_date": "2025-09-16T17:38:27.303680+00:00", "bootscript": null, + "security_group": {"id": "1c1fc99f-b2de-408d-9eb0-da801a3e2744", "name": "Default + security group"}, "location": null, "maintenances": [], "allowed_actions": + ["poweron", "backup"], "placement_group": null, "private_nics": [], "zone": + "fr-par-1", "filesystems": [], "end_of_service": false}}' + headers: + content-length: + - '2163' + date: + - Tue, 16 Sep 2025 17:38:30 GMT + server: + - Scaleway API Gateway (fr-par-2;edge03) + x-request-id: + - b5cdd266-e8db-4235-9191-80b4fe13dc4b + status: + code: 200 + message: OK +- request: + body: '{}' + headers: + Content-Length: + - '2' + user-agent: + - scaleway-sdk-python/2.0.0 + method: DELETE + uri: https://api.scaleway.com/instance/v1/zones/fr-par-1/servers/66a3b25b-4518-43c3-9e61-33b82873d617 + response: + body: + string: '' + headers: + date: + - Tue, 16 Sep 2025 17:38:47 GMT + server: + - Scaleway API Gateway (fr-par-2;edge01) + x-request-id: + - c35b3c38-2ac3-448a-96ce-df5674242d5f + status: + code: 204 + message: No Content +version: 1 diff --git a/scaleway/scaleway/instance/v1/tests/cassettes/test_set_and_get_all_user_data.cassette.yaml b/scaleway/scaleway/instance/v1/tests/cassettes/test_set_and_get_all_user_data.cassette.yaml new file mode 100644 index 000000000..98fd3ab47 --- /dev/null +++ b/scaleway/scaleway/instance/v1/tests/cassettes/test_set_and_get_all_user_data.cassette.yaml @@ -0,0 +1,188 @@ +interactions: +- request: + body: '{}' + headers: + Content-Length: + - '2' + user-agent: + - scaleway-sdk-python/2.0.0 + method: GET + uri: https://api.scaleway.com/instance/v1/zones/fr-par-1/servers/66a3b25b-4518-43c3-9e61-33b82873d617/user_data + response: + body: + string: '{"user_data": ["first key"]}' + headers: + content-length: + - '28' + date: + - Tue, 16 Sep 2025 17:38:36 GMT + server: + - Scaleway API Gateway (fr-par-2;edge01) + x-request-id: + - da763635-45c0-4081-9b22-61db87a4f0a5 + status: + code: 200 + message: OK +- request: + body: test content + headers: + Content-Length: + - '12' + user-agent: + - scaleway-sdk-python/2.0.0 + method: PATCH + uri: https://api.scaleway.com/instance/v1/zones/fr-par-1/servers/66a3b25b-4518-43c3-9e61-33b82873d617/user_data/second%20key + response: + body: + string: '' + headers: + date: + - Tue, 16 Sep 2025 17:38:37 GMT + server: + - Scaleway API Gateway (fr-par-2;edge02) + x-request-id: + - db1aacee-4d93-4447-aaa2-562df54e2440 + status: + code: 204 + message: No Content +- request: + body: another content to test + headers: + Content-Length: + - '23' + user-agent: + - scaleway-sdk-python/2.0.0 + method: PATCH + uri: https://api.scaleway.com/instance/v1/zones/fr-par-1/servers/66a3b25b-4518-43c3-9e61-33b82873d617/user_data/third%20key + response: + body: + string: '' + headers: + date: + - Tue, 16 Sep 2025 17:38:37 GMT + server: + - Scaleway API Gateway (fr-par-2;edge02) + x-request-id: + - 374243f1-1d2d-4847-894a-40bfdfdc58d9 + status: + code: 204 + message: No Content +- request: + body: content first key + headers: + Content-Length: + - '17' + user-agent: + - scaleway-sdk-python/2.0.0 + method: PATCH + uri: https://api.scaleway.com/instance/v1/zones/fr-par-1/servers/66a3b25b-4518-43c3-9e61-33b82873d617/user_data/first%20key + response: + body: + string: '' + headers: + date: + - Tue, 16 Sep 2025 17:38:39 GMT + server: + - Scaleway API Gateway (fr-par-2;edge02) + x-request-id: + - b4a6bb3a-6c01-4f30-8cf1-4d3d2a3e25d4 + status: + code: 204 + message: No Content +- request: + body: '{}' + headers: + Content-Length: + - '2' + user-agent: + - scaleway-sdk-python/2.0.0 + method: GET + uri: https://api.scaleway.com/instance/v1/zones/fr-par-1/servers/66a3b25b-4518-43c3-9e61-33b82873d617/user_data + response: + body: + string: '{"user_data": ["first key", "second key", "third key"]}' + headers: + content-length: + - '55' + date: + - Tue, 16 Sep 2025 17:38:40 GMT + server: + - Scaleway API Gateway (fr-par-2;edge02) + x-request-id: + - 6bac81f0-cce6-40a6-a55e-5a920ca5aec3 + status: + code: 200 + message: OK +- request: + body: '{"server_id": "66a3b25b-4518-43c3-9e61-33b82873d617", "key": "first key"}' + headers: + Content-Length: + - '73' + user-agent: + - scaleway-sdk-python/2.0.0 + method: GET + uri: https://api.scaleway.com/instance/v1/zones/fr-par-1/servers/66a3b25b-4518-43c3-9e61-33b82873d617/user_data/first%20key + response: + body: + string: content first key + headers: + content-length: + - '17' + date: + - Tue, 16 Sep 2025 17:38:41 GMT + server: + - Scaleway API Gateway (fr-par-2;edge02) + x-request-id: + - 3b2ad45d-108a-4867-8ea3-5c81546f7696 + status: + code: 200 + message: OK +- request: + body: '{"server_id": "66a3b25b-4518-43c3-9e61-33b82873d617", "key": "second key"}' + headers: + Content-Length: + - '74' + user-agent: + - scaleway-sdk-python/2.0.0 + method: GET + uri: https://api.scaleway.com/instance/v1/zones/fr-par-1/servers/66a3b25b-4518-43c3-9e61-33b82873d617/user_data/second%20key + response: + body: + string: test content + headers: + content-length: + - '12' + date: + - Tue, 16 Sep 2025 17:38:42 GMT + server: + - Scaleway API Gateway (fr-par-2;edge02) + x-request-id: + - 71c301ad-28df-47d2-9c93-b76e064202f9 + status: + code: 200 + message: OK +- request: + body: '{"server_id": "66a3b25b-4518-43c3-9e61-33b82873d617", "key": "third key"}' + headers: + Content-Length: + - '73' + user-agent: + - scaleway-sdk-python/2.0.0 + method: GET + uri: https://api.scaleway.com/instance/v1/zones/fr-par-1/servers/66a3b25b-4518-43c3-9e61-33b82873d617/user_data/third%20key + response: + body: + string: another content to test + headers: + content-length: + - '23' + date: + - Tue, 16 Sep 2025 17:38:44 GMT + server: + - Scaleway API Gateway (fr-par-2;edge02) + x-request-id: + - 557a41e4-4b5c-4f8d-95ca-fef7ba6c200c + status: + code: 200 + message: OK +version: 1 diff --git a/scaleway/scaleway/instance/v1/tests/cassettes/test_set_and_get_server_user_data.cassette.yaml b/scaleway/scaleway/instance/v1/tests/cassettes/test_set_and_get_server_user_data.cassette.yaml new file mode 100644 index 000000000..af837c32e --- /dev/null +++ b/scaleway/scaleway/instance/v1/tests/cassettes/test_set_and_get_server_user_data.cassette.yaml @@ -0,0 +1,48 @@ +interactions: +- request: + body: this-is-a-test + headers: + Content-Length: + - '14' + user-agent: + - scaleway-sdk-python/2.0.0 + method: PATCH + uri: https://api.scaleway.com/instance/v1/zones/fr-par-1/servers/66a3b25b-4518-43c3-9e61-33b82873d617/user_data/first%20key + response: + body: + string: '' + headers: + date: + - Tue, 16 Sep 2025 17:38:32 GMT + server: + - Scaleway API Gateway (fr-par-2;edge01) + x-request-id: + - 0ed3c2da-9914-462b-b123-f0bd05e159e2 + status: + code: 204 + message: No Content +- request: + body: '{"server_id": "66a3b25b-4518-43c3-9e61-33b82873d617", "key": "first key"}' + headers: + Content-Length: + - '73' + user-agent: + - scaleway-sdk-python/2.0.0 + method: GET + uri: https://api.scaleway.com/instance/v1/zones/fr-par-1/servers/66a3b25b-4518-43c3-9e61-33b82873d617/user_data/first%20key + response: + body: + string: this-is-a-test + headers: + content-length: + - '14' + date: + - Tue, 16 Sep 2025 17:38:33 GMT + server: + - Scaleway API Gateway (fr-par-2;edge02) + x-request-id: + - 553413c2-2def-401d-be92-3c7e7476d070 + status: + code: 200 + message: OK +version: 1 diff --git a/scaleway/scaleway/instance/v1/tests/test_custom_api.py b/scaleway/scaleway/instance/v1/tests/test_custom_api.py new file mode 100644 index 000000000..2bbd86795 --- /dev/null +++ b/scaleway/scaleway/instance/v1/tests/test_custom_api.py @@ -0,0 +1,77 @@ +from typing import Any, Generator + +import pytest + +from scaleway.instance.v1 import Server, BootType +from scaleway.instance.v1.custom_api import InstanceUtilsV1API +from tests.utils import initialize_client_test +from vcr_config import scw_vcr + +server_name = "test-sdk-python-fixture" +server_name_extra = "test-sdk-python-extra" +max_retry = 10 +interval = 0.01 +commercial_type = "DEV1-S" +zone = "fr-par-1" + +# mypy: ignore-errors + + +@pytest.fixture(scope="module") +def instance_api() -> InstanceUtilsV1API: + client = initialize_client_test() + return InstanceUtilsV1API(client, bypass_validation=True) + + +@pytest.fixture(scope="module") +@scw_vcr.use_cassette +def server(instance_api: InstanceUtilsV1API) -> Generator[Server, Any, None]: + instance = instance_api._create_server( + commercial_type=commercial_type, + zone=zone, + name=server_name, + dynamic_ip_required=False, + protected=False, + boot_type=BootType.LOCAL, + image="c00ae53c-1e29-4087-a384-47f3c5c1cd84", + ) + server = instance.server + assert server is not None, "Server creation failed" + assert server.id is not None, "Server ID is None after creation" + instance_api.wait_instance_server(server.id, zone=zone) + + yield server + + instance_api.delete_server(server_id=server.id, zone=zone) + + +@scw_vcr.use_cassette +def test_set_and_get_server_user_data( + instance_api: InstanceUtilsV1API, server: Server +) -> None: + key = "first key" + content = b"this-is-a-test" + instance_api.set_server_user_data(server.id, zone=zone, key=key, content=content) + user_data = instance_api.get_server_user_data(server.id, key=key) + + assert user_data is not None + + +@scw_vcr.use_cassette +def test_set_and_get_all_user_data( + instance_api: InstanceUtilsV1API, server: Server +) -> None: + key = "first key" + content = b"content first key" + key_bis = "second key" + content_bis = b"test content" + another_key = "third key" + another_content = b"another content to test" + user_data: dict[str, bytes] = { + key_bis: content_bis, + another_key: another_content, + key: content, + } + instance_api.set_all_server_user_data(server_id=server.id, user_data=user_data) + response = instance_api.get_all_server_user_data(server_id=server.id) + assert response.user_data == user_data