66 wait_for_condition ,
77)
88
9+ import polling
910import pytest
1011
11- from linode_api4 import VPCIPAddress
12+ from linode_api4 import LinodeClient , VPCIPAddress
1213from linode_api4 .errors import ApiError
1314from linode_api4 .objects import (
1415 Config ,
@@ -84,7 +85,7 @@ def linode_for_network_interface_tests(test_linode_client):
8485 linode_instance .delete ()
8586
8687
87- @pytest .fixture ( scope = "session" , autouse = True )
88+ @pytest .fixture
8889def linode_for_disk_tests (test_linode_client ):
8990 client = test_linode_client
9091 available_regions = client .regions ()
@@ -94,21 +95,24 @@ def linode_for_disk_tests(test_linode_client):
9495 linode_instance , password = client .linode .instance_create (
9596 "g6-nanode-1" ,
9697 chosen_region ,
97- image = "linode/debian10 " ,
98+ image = "linode/alpine3.19 " ,
9899 label = label + "_long_tests" ,
99100 )
100101
101- time .sleep (10 )
102-
103102 # Provisioning time
104103 wait_for_condition (10 , 300 , get_status , linode_instance , "running" )
105104
106- time .sleep (10 )
107-
108105 linode_instance .shutdown ()
109106
110107 wait_for_condition (10 , 100 , get_status , linode_instance , "offline" )
111108
109+ # Now it allocates 100% disk space hence need to clear some space for tests
110+ linode_instance .disks [1 ].delete ()
111+
112+ test_linode_client .polling .event_poller_create (
113+ "linode" , "disk_delete" , entity_id = linode_instance .id
114+ )
115+
112116 yield linode_instance
113117
114118 linode_instance .delete ()
@@ -138,6 +142,10 @@ def get_status(linode: Instance, status: str):
138142 return linode .status == status
139143
140144
145+ def instance_type_condition (linode : Instance , type : str ):
146+ return type in str (linode .type )
147+
148+
141149def test_get_linode (test_linode_client , linode_with_volume_firewall ):
142150 linode = test_linode_client .load (Instance , linode_with_volume_firewall .id )
143151
@@ -303,6 +311,7 @@ def test_linode_resize_with_class(
303311
304312
305313def test_linode_resize_with_migration_type (
314+ test_linode_client ,
306315 create_linode_for_long_running_tests ,
307316):
308317 linode = create_linode_for_long_running_tests
@@ -311,18 +320,32 @@ def test_linode_resize_with_migration_type(
311320 wait_for_condition (10 , 100 , get_status , linode , "running" )
312321
313322 time .sleep (5 )
314- res = linode .resize (new_type = "g6-standard-1" , migration_type = m_type )
315323
316- assert res
324+ assert "g6-nanode-1" in str (linode .type )
325+ assert linode .specs .disk == 25600
317326
318- wait_for_condition ( 10 , 300 , get_status , linode , "resizing" )
327+ res = linode . resize ( new_type = "g6-standard-1" , migration_type = m_type )
319328
320- assert linode .status == "resizing"
329+ if res :
330+ # there is no resizing state in warm migration anymore hence wait for resizing and poll event
331+ test_linode_client .polling .event_poller_create (
332+ "linode" , "linode_resize" , entity_id = linode .id
333+ ).wait_for_next_event_finished (interval = 5 )
334+
335+ wait_for_condition (
336+ 10 ,
337+ 100 ,
338+ get_status ,
339+ linode ,
340+ "running" ,
341+ )
342+ else :
343+ raise ApiError
321344
322- # Takes about 3-5 minute to resize, sometimes longer...
323- wait_for_condition ( 30 , 600 , get_status , linode , "running" )
345+ # reload resized linode
346+ resized_linode = test_linode_client . load ( Instance , linode . id )
324347
325- assert linode . status == "running"
348+ assert resized_linode . specs . disk == 51200
326349
327350
328351def test_linode_boot_with_config (create_linode ):
@@ -376,10 +399,9 @@ def test_disk_resize_and_duplicate(test_linode_client, linode_for_disk_tests):
376399
377400 disk = linode .disks [0 ]
378401
379- disk .resize ( 5000 )
402+ send_request_when_resource_available ( 300 , disk .resize , 5000 )
380403
381- # Using hard sleep instead of wait as the status shows ready when it is resizing
382- time .sleep (120 )
404+ time .sleep (100 )
383405
384406 disk = test_linode_client .load (Disk , linode .disks [0 ].id , linode .id )
385407
@@ -397,7 +419,11 @@ def test_disk_resize_and_duplicate(test_linode_client, linode_for_disk_tests):
397419def test_linode_create_disk (test_linode_client , linode_for_disk_tests ):
398420 linode = test_linode_client .load (Instance , linode_for_disk_tests .id )
399421
400- disk = linode .disk_create (size = 500 )
422+ disk = send_request_when_resource_available (
423+ 300 ,
424+ linode .disk_create ,
425+ size = 500 ,
426+ )
401427
402428 wait_for_disk_status (disk , 120 )
403429
0 commit comments