[PATCH 3/4] tests/functional: avoid tearDown failure when QEMU dies

Daniel P. Berrangé posted 4 patches 1 day, 11 hours ago
Maintainers: Thomas Huth <thuth@redhat.com>, "Philippe Mathieu-Daudé" <philmd@linaro.org>, "Daniel P. Berrangé" <berrange@redhat.com>
[PATCH 3/4] tests/functional: avoid tearDown failure when QEMU dies
Posted by Daniel P. Berrangé 1 day, 11 hours ago
In a QEMU process under test dies unexpectedly, the 'shutdown'
method may well raise an exeception. This causes the tearDown
method to fail, which means any later cleanup code fails to
get run. Most notably the log handlers don't get removed so
the base.log file from an earlier test will get polluted with
messages from any subsequent tests. The tearDown failure also
results in pages of exceptions printed on the console, which
obscures the real failure message / trace printed by the test.

Ignore any shutdown failures in the tearDown method, since any
test which cares about clean shutdown should have already
cleaned up any running VMs. The tearDown method is just there
as a safety net to cleanup resources. The base.log file will
still containing log messages from the failed 'vm.shutdown'
call too.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 tests/functional/qemu_test/testcase.py | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/tests/functional/qemu_test/testcase.py b/tests/functional/qemu_test/testcase.py
index 82a7724404..faa0a4f0db 100644
--- a/tests/functional/qemu_test/testcase.py
+++ b/tests/functional/qemu_test/testcase.py
@@ -404,7 +404,10 @@ def set_vm_arg(self, arg, value):
 
     def tearDown(self):
         for vm in self._vms.values():
-            vm.shutdown()
+            try:
+                vm.shutdown()
+            except Exception as ex:
+                self.log.error("Failed to teardown VM: %s" % ex)
         logging.getLogger('console').removeHandler(self._console_log_fh)
         self._console_log_fh.close()
         super().tearDown()
-- 
2.50.1


Re: [PATCH 3/4] tests/functional: avoid tearDown failure when QEMU dies
Posted by Thomas Huth 14 hours ago
On 08/09/2025 15.57, Daniel P. Berrangé wrote:
> In a QEMU process under test dies unexpectedly, the 'shutdown'
> method may well raise an exeception. This causes the tearDown
> method to fail, which means any later cleanup code fails to
> get run. Most notably the log handlers don't get removed so
> the base.log file from an earlier test will get polluted with
> messages from any subsequent tests. The tearDown failure also
> results in pages of exceptions printed on the console, which
> obscures the real failure message / trace printed by the test.
> 
> Ignore any shutdown failures in the tearDown method, since any
> test which cares about clean shutdown should have already
> cleaned up any running VMs. The tearDown method is just there
> as a safety net to cleanup resources. The base.log file will
> still containing log messages from the failed 'vm.shutdown'
> call too.
> 
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
>   tests/functional/qemu_test/testcase.py | 5 ++++-
>   1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/tests/functional/qemu_test/testcase.py b/tests/functional/qemu_test/testcase.py
> index 82a7724404..faa0a4f0db 100644
> --- a/tests/functional/qemu_test/testcase.py
> +++ b/tests/functional/qemu_test/testcase.py
> @@ -404,7 +404,10 @@ def set_vm_arg(self, arg, value):
>   
>       def tearDown(self):
>           for vm in self._vms.values():
> -            vm.shutdown()
> +            try:
> +                vm.shutdown()
> +            except Exception as ex:
> +                self.log.error("Failed to teardown VM: %s" % ex)
>           logging.getLogger('console').removeHandler(self._console_log_fh)
>           self._console_log_fh.close()
>           super().tearDown()

Reviewed-by: Thomas Huth <thuth@redhat.com>