33
44from tests .integration .helpers import (
55 BASE_CMDS ,
6- exec_test_command , get_random_text ,
6+ exec_test_command ,
7+ get_random_text ,
78)
89
910
@@ -16,6 +17,23 @@ def get_region():
1617 yield first_id
1718
1819
20+ def wait_for_image_status (id , expected_status , timeout = 180 , interval = 5 ):
21+ import time
22+
23+ current_status = exec_test_command (
24+ BASE_CMDS ["images" ] + ["view" , id , "--text" , "--no-headers" , "--delimiter" , "," , "--format" , "status" ]
25+ ).splitlines ()
26+ timer = 0
27+ while current_status [0 ] != expected_status and timer < timeout :
28+ time .sleep (interval )
29+ timer += interval
30+ current_status = exec_test_command (
31+ BASE_CMDS ["images" ] + ["view" , id , "--text" , "--no-headers" , "--delimiter" , "," , "--format" , "status" ]
32+ ).splitlines ()
33+ if timer >= timeout :
34+ raise TimeoutError (f"Created image did not reach status '{ expected_status } ' within { timeout } seconds." )
35+
36+
1937@pytest .fixture (scope = "function" )
2038def create_image_id (get_region ):
2139 linode_id = exec_test_command (
@@ -30,7 +48,7 @@ def create_image_id(get_region):
3048 BASE_CMDS ["images" ] + ["create" , "--label" , "linode-cli-test-image-sharing-image" , "--disk_id" , disks [0 ],
3149 "--text" , "--no-headers" , "--delimiter" , "," , "--format" , "id" ]
3250 )
33- # TODO: wait_for_status
51+ wait_for_image_status ( image_id , "available" )
3452 yield linode_id , image_id
3553
3654
@@ -42,13 +60,3 @@ def create_share_group():
4260 "--format" , "id,uuid" ]
4361 ).split ("," )
4462 yield share_group [0 ], share_group [1 ]
45-
46-
47- @pytest .fixture (scope = "function" )
48- def create_token ():
49- label = get_random_text (8 ) + "_sharegroup_cli_test"
50- created_token = exec_test_command (
51- BASE_CMDS ["profile" ] + ["token-create" , "--label" , label , "--text" , "--no-headers" , "--delimiter" , "," ,
52- "--format" , "token" ]
53- )
54- yield jwt .encode ({"some" : "payload" }, created_token , algorithm = "HS256" )
0 commit comments