@@ -377,6 +377,8 @@ def run_app_in_cloud(
377377 [constants .LIGHTNING_CLOUD_PROJECT_ID ],
378378 )
379379
380+ admin_page .reload ()
381+
380382 view_page = context .new_page ()
381383 i = 1
382384 while True :
@@ -385,10 +387,10 @@ def run_app_in_cloud(
385387
386388 # wait until the app is running and openapi.json is ready
387389 if app .status .phase == V1LightningappInstanceState .RUNNING :
388- view_page .goto (f"{ app .status .url } /view" )
389390 status_code = requests .get (f"{ app .status .url } /openapi.json" ).status_code
390391 if status_code == 200 :
391392 print ("App is running, continuing with testing..." )
393+ view_page .goto (f"{ app .status .url } /view" )
392394 break
393395 msg = f"Received status code { status_code } at { app .status .url !r} "
394396 elif app .status .phase not in (V1LightningappInstanceState .PENDING , V1LightningappInstanceState .NOT_STARTED ):
@@ -478,6 +480,19 @@ def _delete_lightning_app(client, project_id, app_id, app_name):
478480 print (f"Failed to delete { app_name } . Exception { ex } " )
479481
480482
483+ def _delete_cloud_space (client , project_id , cloud_space_id , app_name ):
484+ """Used to delete the parent cloudspace."""
485+ print (f"Deleting { app_name } id: { cloud_space_id } " )
486+ try :
487+ res = client .cloud_space_service_delete_cloud_space (
488+ project_id = project_id ,
489+ id = cloud_space_id ,
490+ )
491+ assert res == {}
492+ except ApiException as ex :
493+ print (f"Failed to delete { app_name } . Exception { ex } " )
494+
495+
481496def delete_cloud_lightning_apps ():
482497 """Cleanup cloud apps that start with the name test-{PR_NUMBER}-{TEST_APP_NAME}.
483498
@@ -502,10 +517,16 @@ def delete_cloud_lightning_apps():
502517 if pr_number and app_name and not lit_app .name .startswith (f"test-{ pr_number } -{ app_name } -" ):
503518 continue
504519 _delete_lightning_app (client , project_id = project_id , app_id = lit_app .id , app_name = lit_app .name )
520+ _delete_cloud_space (
521+ client , project_id = project_id , cloud_space_id = lit_app .spec .cloud_space_id , app_name = lit_app .name
522+ )
505523
506524 print ("deleting apps that were created more than 1 hour ago." )
507525
508526 for lit_app in list_apps .lightningapps :
509527
510528 if lit_app .created_at < datetime .datetime .now (lit_app .created_at .tzinfo ) - datetime .timedelta (hours = 1 ):
511529 _delete_lightning_app (client , project_id = project_id , app_id = lit_app .id , app_name = lit_app .name )
530+ _delete_cloud_space (
531+ client , project_id = project_id , cloud_space_id = lit_app .spec .cloud_space_id , app_name = lit_app .name
532+ )
0 commit comments