@@ -234,6 +234,28 @@ def linode_with_disk_encryption(test_linode_client, request):
234234 linode_instance .delete ()
235235
236236
237+ @pytest .fixture (scope = "session" )
238+ def create_linode_with_authorized_key (test_linode_client , ssh_key_gen ):
239+ client = test_linode_client
240+
241+ region = get_region (client , {"Linodes" , "Cloud Firewall" }, site_type = "core" )
242+ label = get_test_label (length = 8 )
243+
244+ linode_instance = client .linode .instance_create (
245+ "g6-nanode-1" ,
246+ region ,
247+ image = "linode/debian12" ,
248+ label = label ,
249+ kernel = "linode/latest-64bit" ,
250+ boot_size = 9000 ,
251+ authorized_keys = ssh_key_gen [0 ],
252+ )
253+
254+ yield linode_instance
255+
256+ linode_instance .delete ()
257+
258+
237259# Test helper
238260def get_status (linode : Instance , status : str ):
239261 return linode .status == status
@@ -1159,3 +1181,56 @@ def test_update_linode_maintenance_policy(create_linode, test_linode_client):
11591181 linode .invalidate ()
11601182 assert result
11611183 assert linode .maintenance_policy_id == non_default_policy .slug
1184+
1185+
1186+ def test_expected_error_if_fields_authorized_users_authorized_keys_root_pass_are_not_set (
1187+ test_linode_client ,
1188+ ):
1189+ client = test_linode_client
1190+ region = get_region (client , {"Linodes" , "Cloud Firewall" }, site_type = "core" )
1191+ label = get_test_label (length = 8 )
1192+
1193+ with pytest .raises (ValueError ) as create_instance_error :
1194+ client .linode .instance_create (
1195+ "g6-nanode-1" ,
1196+ region ,
1197+ image = "linode/debian12" ,
1198+ label = label ,
1199+ kernel = "linode/latest-64bit" ,
1200+ boot_size = 9000 ,
1201+ )
1202+ assert (
1203+ "When creating an Instance from an Image, at least one of root_pass, authorized_users, or authorized_keys must be provided."
1204+ in str (create_instance_error .value )
1205+ )
1206+
1207+
1208+ def test_create_linode_with_kernel_and_boot_size_then_add_disk_and_rebuild (
1209+ create_linode_with_authorized_key ,
1210+ ssh_key_gen ,
1211+ ):
1212+ linode_create = create_linode_with_authorized_key
1213+ assert linode_create .image .id == "linode/debian12"
1214+
1215+ wait_for_condition (10 , 300 , get_status , linode_create , "running" )
1216+ disk_create = send_request_when_resource_available (
1217+ 300 ,
1218+ linode_create .disk_create ,
1219+ size = 2000 ,
1220+ image = "linode/debian12" ,
1221+ label = "python-disk-test-" + get_test_label (),
1222+ root_pass = "aComplex@Password123" ,
1223+ )
1224+ wait_for_disk_status (disk_create , 120 )
1225+ assert disk_create .status == "ready"
1226+
1227+ retry_sending_request (
1228+ 3 ,
1229+ linode_create .rebuild ,
1230+ "linode/debian12" ,
1231+ authorized_keys = ssh_key_gen [0 ],
1232+ )
1233+ wait_for_condition (10 , 300 , get_status , linode_create , "rebuilding" )
1234+ assert linode_create .status == "rebuilding"
1235+ wait_for_condition (10 , 300 , get_status , linode_create , "running" )
1236+ assert linode_create .image .id == "linode/debian12"
0 commit comments