1+ import json
2+
13from tests .integration .helpers import (
24 BASE_CMDS ,
35 assert_headers_in_lines ,
1416)
1517
1618
19+ def _get_smallest_disk_id (linode_id ):
20+ """Return the disk ID of the smallest disk (e.g. swap) on the Linode."""
21+ disks_json = exec_test_command (
22+ BASE_CMDS ["linodes" ]
23+ + [
24+ "disks-list" ,
25+ linode_id ,
26+ "--json" ,
27+ ]
28+ )
29+ disks = json .loads (disks_json )
30+ smallest = min (disks , key = lambda d : d ["size" ])
31+ return str (smallest ["id" ])
32+
33+
1734def test_disk_resize_clone_and_create (linode_instance_disk_tests ):
1835 linode_id = linode_instance_disk_tests
1936
20- disk_id = get_disk_ids (linode_id = linode_id )[0 ]
37+ # Ensure disks are available
38+ def disks_ready ():
39+ return len (get_disk_ids (linode_id = linode_id )) >= 2
40+
41+ wait_for_condition (10 , 120 , disks_ready )
42+
43+ # Use the smallest disk (swap) for resize/clone — the main OS disk
44+ # is too large to shrink to 50 MB because it contains filesystem data.
45+ disk_id = _get_smallest_disk_id (linode_id )
46+
47+ def disk_poll_func ():
48+ status = exec_test_command (
49+ BASE_CMDS ["linodes" ]
50+ + [
51+ "disk-view" ,
52+ linode_id ,
53+ disk_id ,
54+ "--text" ,
55+ "--no-headers" ,
56+ "--format=status" ,
57+ ]
58+ )
59+
60+ return status .strip () == "ready"
61+
62+ # Make sure the disk is ready before resizing
63+ wait_for_condition (15 , 300 , disk_poll_func )
2164
2265 # resize disk
2366 retry_exec_test_command_with_delay (
@@ -29,27 +72,30 @@ def test_disk_resize_clone_and_create(linode_instance_disk_tests):
2972 "--size" ,
3073 "50" ,
3174 ],
32- retries = 3 ,
33- delay = 10 ,
75+ retries = 10 ,
76+ delay = 15 ,
3477 )
3578
36- def disk_poll_func ():
37- status = exec_test_command (
79+ # Wait for the disk to be ready after resize
80+ wait_for_condition (15 , 300 , disk_poll_func )
81+
82+ def disk_size_poll_func ():
83+ size = exec_test_command (
3884 BASE_CMDS ["linodes" ]
3985 + [
4086 "disk-view" ,
4187 linode_id ,
4288 disk_id ,
4389 "--text" ,
4490 "--no-headers" ,
45- "--format=status " ,
91+ "--format=size " ,
4692 ]
4793 )
4894
49- return status == "ready "
95+ return size . strip () == "50 "
5096
51- # Wait for the instance to be ready
52- wait_for_condition (15 , 150 , disk_poll_func )
97+ # Verify the resize actually took effect
98+ wait_for_condition (15 , 300 , disk_size_poll_func )
5399
54100 # clone disk
55101 res = retry_exec_test_command_with_delay (
@@ -60,8 +106,8 @@ def disk_poll_func():
60106 disk_id ,
61107 "--text" ,
62108 ],
63- retries = 3 ,
64- delay = 10 ,
109+ retries = 10 ,
110+ delay = 15 ,
65111 )
66112
67113 headers = ["id" , "label" , "status" , "size" , "filesystem" , "disk_encryption" ]
0 commit comments