Skip to content

Commit

Permalink
tests(lxd): avoid failure on multiple calls to --show-log (canonical#…
Browse files Browse the repository at this point in the history
…5811)

Cope with repeated calls to lxc console --show-log which exits 1
with the error "no such file or directory" when the log entries
have already been processed and no new log entries exist.

Preserve lxc_log on the client instance and return former log content
on lxd platforms when "no such file or directory" runtime errors are
raised
  • Loading branch information
blackboxsw committed Oct 10, 2024
1 parent 40f9bae commit a62656c
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions tests/integration_tests/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -538,10 +538,20 @@ def get_console_log(client: "IntegrationInstance"):
console_log = client.instance.console_log()
except NotImplementedError:
pytest.skip("NotImplementedError when requesting console log")
except RuntimeError as e:
if "open : no such file or directory" in str(e):
if hasattr(client, "lxc_log"):
return client.lxc_log
raise e
if console_log is None:
pytest.skip("Console log has not been setup")
if console_log.lower().startswith("no console output"):
pytest.fail("no console output")
if PLATFORM in ("lxd_vm", "lxd_container"):
# Preserve non empty console log on lxc platforms because
# lxc console --show-log can be called once and the log is flushed.
# Multiple calls to --show-log error on "no such file or directory".
client.lxc_log = console_log # type: ignore[attr-defined]
return console_log


Expand Down

0 comments on commit a62656c

Please sign in to comment.