From 12bc02294dc1632687d42726368dad744234beec Mon Sep 17 00:00:00 2001 From: hamistao Date: Thu, 9 Jan 2025 23:48:19 -0300 Subject: [PATCH] WIP Signed-off-by: hamistao --- integration/run-integration-tests | 9 +++++++ integration/test_containers.py | 41 ++++++++++++++++++++++--------- pylxd/models/instance.py | 5 ++++ 3 files changed, 44 insertions(+), 11 deletions(-) diff --git a/integration/run-integration-tests b/integration/run-integration-tests index f096f531..f62389b7 100755 --- a/integration/run-integration-tests +++ b/integration/run-integration-tests @@ -55,9 +55,18 @@ save_trust_list > "${OLD_TRUST_LIST}" snap list lxd || true lxc version +set +eu + # finally run the integration tests tox -e integration +set -eu + +# LXD daemon logs +echo "::group::lxd logs" +journalctl --quiet --no-hostname --no-pager --boot=0 --lines=100 --unit=snap.lxd.daemon.service +echo "::endgroup::" + # Remove any cert added to the trusted list by the integration tests NEW_TRUST_LIST="$(mktemp)" save_trust_list > "${NEW_TRUST_LIST}" diff --git a/integration/test_containers.py b/integration/test_containers.py index ca820ef4..bb9e08a9 100644 --- a/integration/test_containers.py +++ b/integration/test_containers.py @@ -158,19 +158,38 @@ def test_execute(self): def test_execute_no_buffer(self): """A command is executed on the container without buffering the output.""" - self.container.start(wait=True) - self.addCleanup(self.container.stop, wait=True) - time.sleep( - 1 - ) # Wait a little to make sure the container is ready to exec since it has just been started. - buffer = [] + while True: + self.container.start(wait=True) + self.addCleanup(self.container.stop, wait=True) + time.sleep(1) + buffer = [] - result = self.container.execute(["echo", "test"], stdout_handler=buffer.append) + result = self.container.execute(["echo", "test"], stdout_handler=buffer.append) - self.assertEqual(0, result.exit_code) - self.assertEqual("", result.stdout) - self.assertEqual("", result.stderr) - self.assertEqual("test\n", "".join(buffer)) + self.assertEqual(0, result.exit_code) + self.assertEqual("", result.stdout) + self.assertEqual("", result.stderr) + self.assertEqual("test\n", "".join(buffer)) + + self.container.stop(wait=True) + time.sleep(1) + + def test_execute_no_buffer_original(self): + """A command is executed on the container without buffering the output.""" + while True: + self.container.start(wait=True) + self.addCleanup(self.container.stop, wait=True) + buffer = [] + + result = self.container.execute(["echo", "test"], stdout_handler=buffer.append) + + self.assertEqual(0, result.exit_code) + self.assertEqual("", result.stdout) + self.assertEqual("", result.stderr) + self.assertEqual("test\n", "".join(buffer)) + + self.container.stop(wait=True) + time.sleep(1) def test_execute_no_decode(self): """A command is executed on the container that isn't utf-8 decodable""" diff --git a/pylxd/models/instance.py b/pylxd/models/instance.py index 6ace85ea..770670b8 100644 --- a/pylxd/models/instance.py +++ b/pylxd/models/instance.py @@ -519,6 +519,11 @@ def execute( manager.stop() manager.join() + print(operation.metadata) + if hasattr(operation, "err"): print(operation.err) + print(stdout.data) + print(stderr.data) + return _InstanceExecuteResult( operation.metadata["return"], stdout.data, stderr.data )