3
3
4
4
import pytest
5
5
6
+ from scaleway .instance .v1 import IpType
6
7
from scaleway .instance .v1 .custom_api import InstanceUtilsV1API
7
8
from scaleway_async .instance .v1 import AttachServerVolumeRequestVolumeType
8
9
from scaleway_core .client import Client
9
- from scaleway .instance .v1 .types import VolumeVolumeType , BootType , Server , VolumeServerTemplate
10
+ from scaleway .instance .v1 .types import (
11
+ VolumeVolumeType ,
12
+ BootType ,
13
+ Server ,
14
+ VolumeServerTemplate ,
15
+ )
10
16
from scaleway .block .v1alpha1 import BlockV1Alpha1API
11
17
from scaleway .block .v1alpha1 .types import Volume , CreateVolumeRequestFromEmpty
12
18
from vcr_config import scw_vcr
18
24
commercial_type = "DEV1-S"
19
25
zone = "fr-par-1"
20
26
27
+ # mypy: ignore-errors
28
+
29
+
21
30
@pytest .fixture (scope = "module" )
22
31
@scw_vcr .use_cassette
23
32
def instance_block_api () -> tuple [InstanceUtilsV1API , BlockV1Alpha1API ]:
@@ -26,10 +35,12 @@ def instance_block_api() -> tuple[InstanceUtilsV1API, BlockV1Alpha1API]:
26
35
block_api = BlockV1Alpha1API (client )
27
36
return instance_api , block_api
28
37
38
+
29
39
@pytest .fixture (scope = "module" )
30
40
@scw_vcr .use_cassette
31
- def instance_volume (instance_block_api : tuple [InstanceUtilsV1API , BlockV1Alpha1API ]) -> Generator [
32
- tuple [Server | None , list [Volume ]], None , None ]:
41
+ def instance_volume (
42
+ instance_block_api : tuple [InstanceUtilsV1API , BlockV1Alpha1API ],
43
+ ) -> Generator [tuple [Server | None , list [Volume ]], None , None ]:
33
44
instance_api , block_api = instance_block_api
34
45
volumes_list : list [Volume ] = []
35
46
volumes = {
@@ -52,40 +63,59 @@ def instance_volume(instance_block_api: tuple[InstanceUtilsV1API, BlockV1Alpha1A
52
63
instance_api .wait_test_instance_server (instance .server .id , zone = zone )
53
64
yield instance .server , volumes_list
54
65
for volume in volumes_list :
55
- instance_api .detach_server_volume (server_id = instance .server .id , volume_id = volume .id , zone = zone )
66
+ instance_api .detach_server_volume (
67
+ server_id = instance .server .id , volume_id = volume .id , zone = zone
68
+ )
56
69
block_api .wait_for_volume (volume_id = volume .id , zone = zone )
57
70
block_api .delete_volume (volume_id = volume .id , zone = zone )
58
71
instance_api .delete_server (server_id = instance .server .id , zone = zone )
59
72
73
+
60
74
@scw_vcr .use_cassette
61
- def test_attach_additionnal_volume (instance_block_api : tuple [InstanceUtilsV1API , BlockV1Alpha1API ], instance_volume : tuple [Server , list [Volume ]]) -> None :
75
+ def test_attach_additionnal_volume (
76
+ instance_block_api : tuple [InstanceUtilsV1API , BlockV1Alpha1API ],
77
+ instance_volume : tuple [Server , list [Volume ]],
78
+ ) -> None :
62
79
instance_api , block_api = instance_block_api
63
80
server , volumes_list = instance_volume
64
81
additional_volume = block_api .create_volume (
65
82
from_empty = CreateVolumeRequestFromEmpty (size = volume_size ),
66
83
)
67
- updated_volume = block_api .wait_for_volume (volume_id = additional_volume .id , zone = zone )
84
+ updated_volume = block_api .wait_for_volume (
85
+ volume_id = additional_volume .id , zone = zone
86
+ )
68
87
volumes_list .append (updated_volume )
69
88
assert updated_volume .size == volume_size
70
89
assert updated_volume .id is not None
71
90
72
- instance_api .attach_server_volume (server_id = server .id , volume_id = additional_volume .id , zone = zone , volume_type = AttachServerVolumeRequestVolumeType .SBS_VOLUME )
91
+ instance_api .attach_server_volume (
92
+ server_id = server .id ,
93
+ volume_id = additional_volume .id ,
94
+ zone = zone ,
95
+ volume_type = AttachServerVolumeRequestVolumeType .SBS_VOLUME ,
96
+ )
73
97
instance_api .wait_test_instance_server (server_id = server .id , zone = zone )
74
98
block_api .wait_for_volume (volume_id = additional_volume .id , zone = zone )
75
99
76
100
server_details = instance_api .get_server (server_id = server .id , zone = zone ).server
77
101
attached_volume_ids = [v .id for v in server_details .volumes .values ()]
78
102
assert additional_volume .id in attached_volume_ids
79
103
104
+
80
105
@scw_vcr .use_cassette
81
- def test_list_server (instance_block_api : tuple [InstanceUtilsV1API , BlockV1Alpha1API ]) -> None :
106
+ def test_list_server (
107
+ instance_block_api : tuple [InstanceUtilsV1API , BlockV1Alpha1API ],
108
+ ) -> None :
82
109
instance_api , block_api = instance_block_api
83
110
servers = instance_api .list_servers (zone = zone )
84
- assert len (servers .servers ) = = 1
111
+ assert len (servers .servers ) > = 1
85
112
assert servers .servers [0 ].name == server_name
86
113
114
+
87
115
@scw_vcr .use_cassette
88
- def test_create_new_server (instance_block_api : tuple [InstanceUtilsV1API , BlockV1Alpha1API ]) -> None :
116
+ def test_create_new_server (
117
+ instance_block_api : tuple [InstanceUtilsV1API , BlockV1Alpha1API ],
118
+ ) -> None :
89
119
instance_api , block_api = instance_block_api
90
120
server = instance_api ._create_server (
91
121
commercial_type = commercial_type ,
@@ -99,10 +129,16 @@ def test_create_new_server(instance_block_api: tuple[InstanceUtilsV1API, BlockV1
99
129
assert server .server .id is not None
100
130
assert server .server .name == server_name
101
131
102
- servers = instance_api .list_servers (zone = zone )
103
- assert len (servers . servers ) = = 2
132
+ servers = instance_api .list_servers_all (zone = zone )
133
+ assert len (servers ) > = 2
104
134
105
135
instance_api .delete_server (server_id = server .server .id , zone = zone )
106
136
107
137
108
-
138
+ @scw_vcr .use_cassette
139
+ def test_create_ip (
140
+ instance_block_api : tuple [InstanceUtilsV1API , BlockV1Alpha1API ],
141
+ ) -> None :
142
+ instance_api , block_api = instance_block_api
143
+ ip = instance_api .create_ip (type_ = IpType .ROUTED_IPV6 ).ip
144
+ assert ip .id is not None
0 commit comments