Skip to content

Commit b3da781

Browse files
authored
chore: print app logs and openstack servers for debugging (#598)
* chore: print app logs and openstack servers for debugging * feat: only print debug log on test failure * fix: logging add server name
1 parent 455d2ec commit b3da781

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

tests/integration/conftest.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
from tests.integration.helpers.common import (
4242
MONGODB_APP_NAME,
4343
deploy_github_runner_charm,
44+
get_github_runner_manager_service_log,
4445
wait_for,
4546
wait_for_runner_ready,
4647
)
@@ -295,6 +296,7 @@ def openstack_connection_fixture(
295296
clouds_yaml_contents: str,
296297
app_name: str,
297298
existing_app_suffix: str,
299+
request: pytest.FixtureRequest,
298300
) -> Generator[Connection, None, None]:
299301
"""The openstack connection instance."""
300302
clouds_yaml = yaml.safe_load(clouds_yaml_contents)
@@ -304,11 +306,19 @@ def openstack_connection_fixture(
304306
with openstack.connect(first_cloud) as connection:
305307
yield connection
306308

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+
307317
if not existing_app_suffix:
308318
# servers, keys, security groups, security rules, images are created by the charm.
309319
# don't remove security groups & rules since they are single instances.
310320
# don't remove images since it will be moved to image-builder
311-
for server in connection.list_servers():
321+
for server in servers:
312322
server_name: str = server.name
313323
if server_name.startswith(app_name):
314324
connection.delete_server(server_name)
@@ -438,6 +448,7 @@ async def app_openstack_runner_fixture(
438448
flavor_name: str,
439449
existing_app_suffix: Optional[str],
440450
image_builder: Application,
451+
request: pytest.FixtureRequest,
441452
) -> AsyncIterator[Application]:
442453
"""Application launching VMs and no runners."""
443454
if existing_app_suffix:
@@ -474,7 +485,14 @@ async def app_openstack_runner_fixture(
474485
timeout=IMAGE_BUILDER_INTEGRATION_TIMEOUT_IN_SECONDS,
475486
)
476487

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.")
478496

479497

480498
@pytest_asyncio.fixture(scope="module", name="app_scheduled_events")

0 commit comments

Comments
 (0)