From d5dd42a600b6752492d8b7fd23f9071e3651d5c7 Mon Sep 17 00:00:00 2001 From: Hu Shuai Date: Thu, 6 Jul 2023 16:58:21 +0800 Subject: [PATCH] hugepage_setup: Cleanup hugepage when setup process fails If the setup process fails, func will raise an error and return. Meanwhile, if the system has created some other hugepages, they will remain on the host to consume memory. Therefore, do the cleanup process after failing. Signed-off-by: Hu Shuai --- virttest/test_setup/__init__.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/virttest/test_setup/__init__.py b/virttest/test_setup/__init__.py index 15565d8ea0..0f8dbdf8c4 100644 --- a/virttest/test_setup/__init__.py +++ b/virttest/test_setup/__init__.py @@ -556,6 +556,8 @@ def set_hugepages(self): msg = "Can't read/write from kernel hugepage file" raise exceptions.TestSetupFail(msg) if loop_hp == hp: + if loop_hp > 0: + self.cleanup() raise ValueError("Cannot set the kernel hugepage setting " "to the target value of %d hugepages." % self.target_hugepages)