@@ -380,6 +380,8 @@ def run_app_in_cloud(
380380 [constants .LIGHTNING_CLOUD_PROJECT_ID ],
381381 )
382382
383+ admin_page .reload ()
384+
383385 view_page = context .new_page ()
384386 i = 1
385387 while True :
@@ -388,10 +390,10 @@ def run_app_in_cloud(
388390
389391 # wait until the app is running and openapi.json is ready
390392 if app .status .phase == V1LightningappInstanceState .RUNNING :
391- view_page .goto (f"{ app .status .url } /view" )
392393 status_code = requests .get (f"{ app .status .url } /openapi.json" ).status_code
393394 if status_code == 200 :
394395 print ("App is running, continuing with testing..." )
396+ view_page .goto (f"{ app .status .url } /view" )
395397 break
396398 msg = f"Received status code { status_code } at { app .status .url !r} "
397399 elif app .status .phase not in (V1LightningappInstanceState .PENDING , V1LightningappInstanceState .NOT_STARTED ):
@@ -481,6 +483,19 @@ def _delete_lightning_app(client, project_id, app_id, app_name):
481483 print (f"Failed to delete { app_name } . Exception { ex } " )
482484
483485
486+ def _delete_cloud_space (client , project_id , cloud_space_id , app_name ):
487+ """Used to delete the parent cloudspace."""
488+ print (f"Deleting { app_name } id: { cloud_space_id } " )
489+ try :
490+ res = client .cloud_space_service_delete_cloud_space (
491+ project_id = project_id ,
492+ id = cloud_space_id ,
493+ )
494+ assert res == {}
495+ except ApiException as ex :
496+ print (f"Failed to delete { app_name } . Exception { ex } " )
497+
498+
484499def delete_cloud_lightning_apps ():
485500 """Cleanup cloud apps that start with the name test-{PR_NUMBER}-{TEST_APP_NAME}.
486501
@@ -505,10 +520,16 @@ def delete_cloud_lightning_apps():
505520 if pr_number and app_name and not lit_app .name .startswith (f"test-{ pr_number } -{ app_name } -" ):
506521 continue
507522 _delete_lightning_app (client , project_id = project_id , app_id = lit_app .id , app_name = lit_app .name )
523+ _delete_cloud_space (
524+ client , project_id = project_id , cloud_space_id = lit_app .spec .cloud_space_id , app_name = lit_app .name
525+ )
508526
509527 print ("deleting apps that were created more than 1 hour ago." )
510528
511529 for lit_app in list_apps .lightningapps :
512530
513531 if lit_app .created_at < datetime .datetime .now (lit_app .created_at .tzinfo ) - datetime .timedelta (hours = 1 ):
514532 _delete_lightning_app (client , project_id = project_id , app_id = lit_app .id , app_name = lit_app .name )
533+ _delete_cloud_space (
534+ client , project_id = project_id , cloud_space_id = lit_app .spec .cloud_space_id , app_name = lit_app .name
535+ )
0 commit comments