From 2bfc80d85248ed0014e396c2cab4b8ffb60e470e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Marcin=20=C5=9Alusarz?= <marcin.slusarz@intel.com>
Date: Tue, 18 Feb 2020 15:51:12 +0100
Subject: [PATCH] test: (py) add require_free_space
---
src/test/obj_defrag_advanced/TESTS.py | 4 ++++
src/test/unittest/context.py | 11 ++++++++---
2 files changed, 12 insertions(+), 3 deletions(-)
diff --git a/src/test/obj_defrag_advanced/TESTS.py b/src/test/obj_defrag_advanced/TESTS.py
index 8979af4a5..daf7d8ecc 100755
--- a/src/test/obj_defrag_advanced/TESTS.py
+++ b/src/test/obj_defrag_advanced/TESTS.py
@@ -49,6 +49,8 @@ class ObjDefragAdvanced(t.BaseTest):
min_root_size = 0
def run(self, ctx):
+ ctx.require_free_space(self.pool_size)
+
path = ctx.create_holey_file(self.pool_size, 'testfile')
dump1 = 'dump1.log'
dump2 = 'dump2.log'
@@ -98,6 +100,8 @@ class ObjDefragAdvancedMt(ObjDefragAdvanced):
ncycles = 2
def run(self, ctx):
+ ctx.require_free_space(self.pool_size)
+
path = ctx.create_holey_file(self.pool_size, 'testfile')
ctx.exec('obj_defrag_advanced',
diff --git a/src/test/unittest/context.py b/src/test/unittest/context.py
index 00a35fba3..2b326ebce 100644
--- a/src/test/unittest/context.py
+++ b/src/test/unittest/context.py
@@ -1,5 +1,5 @@
#
-# Copyright 2019, Intel Corporation
+# Copyright 2019-2020, Intel Corporation
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
@@ -136,9 +136,9 @@ class ContextBase:
return int(proc.stdout)
futils.fail('Could not get size of the file, it is inaccessible or does not exist')
- def get_free_space(self):
+ def get_free_space(self, dir="."):
"""Returns free space for current file system"""
- _, _, free = shutil.disk_usage(".")
+ _, _, free = shutil.disk_usage(dir)
return free
@@ -187,6 +187,11 @@ class Context(ContextBase):
os.chmod(filepath, mode)
return filepath
+ def require_free_space(self, space):
+ if self.get_free_space(self.testdir) < space:
+ futils.skip('Not enough free space (' + str(space / 1024 / 1024) +
+ ' MiB required)')
+
def mkdirs(self, path, mode=None):
"""
Creates directory along with all parent directories required. In the
--
2.17.2