From 8b8766c01a1e24efbd760b18bae2e3087c992b63 Mon Sep 17 00:00:00 2001 From: Disha Goel Date: Wed, 23 Oct 2024 14:03:28 +0530 Subject: [PATCH] stress-ng: fix teardown Fix the teardown function to prevent AttributeError by adding checks to see if the attribute and path exists before trying to remove it. Before fix: ERROR: 'Stressng' object has no attribute 'loop_dev' ERROR: 'Stressng' object has no attribute 'stressmnt' After fix: CANCEL: Build Failed, Please check the build logs for details !! Signed-off-by: Disha Goel --- generic/stress-ng.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/generic/stress-ng.py b/generic/stress-ng.py index 1ff449827..ff3991f27 100644 --- a/generic/stress-ng.py +++ b/generic/stress-ng.py @@ -198,11 +198,12 @@ def test(self): "\n".join(ERROR)) def tearDown(self): - if 'filesystem' in self.class_type: + if hasattr(self, 'loop_dev') and os.path.exists(self.loop_dev): process.run("umount %s" % self.loop_dev, ignore_status=True, sudo=True) process.run("losetup -d %s" % self.loop_dev, ignore_status=True, sudo=True) + if os.path.exists('/tmp/blockfile'): process.run("rm -rf /tmp/blockfile", ignore_status=True, sudo=True) - if (os.path.exists(self.stressmnt)): - process.run(f"rm -rf {self.stressmnt}") + if hasattr(self, 'stressmnt') and os.path.exists(self.stressmnt): + process.run(f"rm -rf {self.stressmnt}", ignore_status=True)