41
41
from tests .integration .helpers .common import (
42
42
MONGODB_APP_NAME ,
43
43
deploy_github_runner_charm ,
44
+ get_github_runner_manager_service_log ,
44
45
wait_for ,
45
46
wait_for_runner_ready ,
46
47
)
@@ -295,6 +296,7 @@ def openstack_connection_fixture(
295
296
clouds_yaml_contents : str ,
296
297
app_name : str ,
297
298
existing_app_suffix : str ,
299
+ request : pytest .FixtureRequest ,
298
300
) -> Generator [Connection , None , None ]:
299
301
"""The openstack connection instance."""
300
302
clouds_yaml = yaml .safe_load (clouds_yaml_contents )
@@ -304,11 +306,19 @@ def openstack_connection_fixture(
304
306
with openstack .connect (first_cloud ) as connection :
305
307
yield connection
306
308
309
+ servers = connection .list_servers (filters = {"name" : app_name })
310
+
311
+ if request .session .testsfailed :
312
+ logging .info ("OpenStack servers: %s" , servers )
313
+ for server in servers :
314
+ console_log = connection .get_server_console (server = server )
315
+ logging .info ("Server %s console log:\n %s" , server .name , console_log )
316
+
307
317
if not existing_app_suffix :
308
318
# servers, keys, security groups, security rules, images are created by the charm.
309
319
# don't remove security groups & rules since they are single instances.
310
320
# don't remove images since it will be moved to image-builder
311
- for server in connection . list_servers () :
321
+ for server in servers :
312
322
server_name : str = server .name
313
323
if server_name .startswith (app_name ):
314
324
connection .delete_server (server_name )
@@ -438,6 +448,7 @@ async def app_openstack_runner_fixture(
438
448
flavor_name : str ,
439
449
existing_app_suffix : Optional [str ],
440
450
image_builder : Application ,
451
+ request : pytest .FixtureRequest ,
441
452
) -> AsyncIterator [Application ]:
442
453
"""Application launching VMs and no runners."""
443
454
if existing_app_suffix :
@@ -474,7 +485,14 @@ async def app_openstack_runner_fixture(
474
485
timeout = IMAGE_BUILDER_INTEGRATION_TIMEOUT_IN_SECONDS ,
475
486
)
476
487
477
- return application
488
+ yield application
489
+
490
+ if request .session .testsfailed :
491
+ try :
492
+ app_log = await get_github_runner_manager_service_log (unit = application .units [0 ])
493
+ logging .info ("Application log: \n %s" , app_log )
494
+ except AssertionError :
495
+ logging .warning ("Failed to get application log." )
478
496
479
497
480
498
@pytest_asyncio .fixture (scope = "module" , name = "app_scheduled_events" )
0 commit comments