3
3
4
4
import pytest
5
5
6
+ from linode_api4 import ApiError
6
7
from linode_api4 .linode_client import LinodeClient
7
8
8
9
ENV_TOKEN_NAME = "LINODE_TOKEN"
@@ -29,15 +30,15 @@ def run_long_tests():
29
30
30
31
31
32
@pytest .fixture (scope = "session" )
32
- def create_linode (get_client ):
33
- client = get_client
33
+ def create_linode (test_linode_client ):
34
+ client = test_linode_client
34
35
available_regions = client .regions ()
35
36
chosen_region = available_regions [0 ]
36
- timestamp = str (int ( time .time () ))
37
+ timestamp = str (time .time_ns ( ))
37
38
label = "TestSDK-" + timestamp
38
39
39
40
linode_instance , password = client .linode .instance_create (
40
- "g5-standard-4 " , chosen_region , image = "linode/debian9 " , label = label
41
+ "g6-nanode-1 " , chosen_region , image = "linode/debian10 " , label = label
41
42
)
42
43
43
44
yield linode_instance
@@ -46,15 +47,15 @@ def create_linode(get_client):
46
47
47
48
48
49
@pytest .fixture
49
- def create_linode_for_pass_reset (get_client ):
50
- client = get_client
50
+ def create_linode_for_pass_reset (test_linode_client ):
51
+ client = test_linode_client
51
52
available_regions = client .regions ()
52
53
chosen_region = available_regions [0 ]
53
- timestamp = str (int ( time .time () ))
54
+ timestamp = str (time .time_ns ( ))
54
55
label = "TestSDK-" + timestamp
55
56
56
57
linode_instance , password = client .linode .instance_create (
57
- "g5-standard-4 " , chosen_region , image = "linode/debian9 " , label = label
58
+ "g6-nanode-1 " , chosen_region , image = "linode/debian10 " , label = label
58
59
)
59
60
60
61
yield linode_instance , password
@@ -80,7 +81,7 @@ def ssh_key_gen():
80
81
81
82
82
83
@pytest .fixture (scope = "session" )
83
- def get_client ():
84
+ def test_linode_client ():
84
85
token = get_token ()
85
86
api_url = get_api_url ()
86
87
api_ca_file = get_api_ca_file ()
@@ -93,8 +94,8 @@ def get_client():
93
94
94
95
95
96
@pytest .fixture
96
- def set_account_settings ( get_client ):
97
- client = get_client
97
+ def test_account_settings ( test_linode_client ):
98
+ client = test_linode_client
98
99
account_settings = client .account .settings ()
99
100
account_settings ._populated = True
100
101
account_settings .network_helper = True
@@ -103,10 +104,10 @@ def set_account_settings(get_client):
103
104
104
105
105
106
@pytest .fixture (scope = "session" )
106
- def create_domain ( get_client ):
107
- client = get_client
107
+ def test_domain ( test_linode_client ):
108
+ client = test_linode_client
108
109
109
- timestamp = str (int ( time .time () ))
110
+ timestamp = str (time .time_ns ( ))
110
111
domain_addr = timestamp + "-example.com"
111
112
112
113
@@ -130,23 +131,36 @@ def create_domain(get_client):
130
131
131
132
132
133
@pytest .fixture (scope = "session" )
133
- def create_volume ( get_client ):
134
- client = get_client
135
- timestamp = str (int ( time .time () ))
134
+ def test_volume ( test_linode_client ):
135
+ client = test_linode_client
136
+ timestamp = str (time .time_ns ( ))
136
137
label = "TestSDK-" + timestamp
137
138
138
139
volume = client .volume_create (label = label , region = "ap-west" )
139
140
140
141
yield volume
141
142
142
- volume .delete ()
143
+ timeout = 100 # give 100s for volume to be detached before deletion
144
+
145
+ start_time = time .time ()
146
+
147
+ while time .time () - start_time < timeout :
148
+ try :
149
+ res = volume .delete ()
150
+ if res :
151
+ break
152
+ else :
153
+ time .sleep (3 )
154
+ except ApiError as e :
155
+ if time .time () - start_time > timeout :
156
+ raise e
143
157
144
158
145
159
@pytest .fixture
146
- def create_tag ( get_client ):
147
- client = get_client
160
+ def test_tag ( test_linode_client ):
161
+ client = test_linode_client
148
162
149
- timestamp = str (int ( time .time () ))
163
+ timestamp = str (time .time_ns ( ))
150
164
label = "TestSDK-" + timestamp
151
165
152
166
tag = client .tag_create (label = label )
@@ -157,10 +171,10 @@ def create_tag(get_client):
157
171
158
172
159
173
@pytest .fixture
160
- def create_nodebalancer ( get_client ):
161
- client = get_client
174
+ def test_nodebalancer ( test_linode_client ):
175
+ client = test_linode_client
162
176
163
- timestamp = str (int ( time .time () ))
177
+ timestamp = str (time .time_ns ( ))
164
178
label = "TestSDK-" + timestamp
165
179
166
180
nodebalancer = client .nodebalancer_create (region = "us-east" , label = label )
@@ -171,9 +185,9 @@ def create_nodebalancer(get_client):
171
185
172
186
173
187
@pytest .fixture
174
- def create_longview_client ( get_client ):
175
- client = get_client
176
- timestamp = str (int ( time .time () ))
188
+ def test_longview_client ( test_linode_client ):
189
+ client = test_linode_client
190
+ timestamp = str (time .time_ns ( ))
177
191
label = "TestSDK-" + timestamp
178
192
longview_client = client .longview .client_create (label = label )
179
193
@@ -183,9 +197,9 @@ def create_longview_client(get_client):
183
197
184
198
185
199
@pytest .fixture
186
- def upload_sshkey ( get_client , ssh_key_gen ):
200
+ def test_sshkey ( test_linode_client , ssh_key_gen ):
187
201
pub_key = ssh_key_gen [0 ]
188
- client = get_client
202
+ client = test_linode_client
189
203
key = client .profile .ssh_key_upload (pub_key , "IntTestSDK-sshkey" )
190
204
191
205
yield key
@@ -194,8 +208,8 @@ def upload_sshkey(get_client, ssh_key_gen):
194
208
195
209
196
210
@pytest .fixture
197
- def create_ssh_keys_object_storage ( get_client ):
198
- client = get_client
211
+ def ssh_keys_object_storage ( test_linode_client ):
212
+ client = test_linode_client
199
213
label = "TestSDK-obj-storage-key"
200
214
key = client .object_storage .keys_create (label )
201
215
@@ -205,8 +219,8 @@ def create_ssh_keys_object_storage(get_client):
205
219
206
220
207
221
@pytest .fixture (scope = "session" )
208
- def create_firewall ( get_client ):
209
- client = get_client
222
+ def test_firewall ( test_linode_client ):
223
+ client = test_linode_client
210
224
rules = {
211
225
"outbound" : [],
212
226
"outbound_policy" : "DROP" ,
@@ -224,8 +238,8 @@ def create_firewall(get_client):
224
238
225
239
226
240
@pytest .fixture
227
- def create_oauth_client ( get_client ):
228
- client = get_client
241
+ def test_oauth_client ( test_linode_client ):
242
+ client = test_linode_client
229
243
oauth_client = client .account .oauth_client_create (
230
244
"test-oauth-client" , "https://localhost/oauth/callback"
231
245
)
0 commit comments