From 979c372673ce5f7228f95e10447f120359a0bdb5 Mon Sep 17 00:00:00 2001 From: Anton Sidelnikov <53078276+anton-sidelnikov@users.noreply.github.com> Date: Mon, 28 Dec 2020 15:12:53 +0300 Subject: [PATCH] clearing folder via subprocess (#32) --- csm_test_utils/files_rotation.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/csm_test_utils/files_rotation.py b/csm_test_utils/files_rotation.py index c9dfcde..b590a5b 100644 --- a/csm_test_utils/files_rotation.py +++ b/csm_test_utils/files_rotation.py @@ -6,6 +6,7 @@ import hashlib import os import requests +import subprocess from influx_line_protocol import Metric, MetricCollection from ocomone.logging import setup_logger @@ -43,10 +44,9 @@ def md5(file_name): def create_file(dd_input="/dev/urandom", base_file="/tmp/base_file.data", bs=1200000, count=100): base_copy = f"{base_file}_copy" if not os.path.exists(base_file) or (round(time.time() - os.path.getmtime(base_file)) / 60) > 60: - try: - os.system(f"rm {base_file.split('.')[0]}*") - except Exception as Ex: - LOGGER.error(Ex) + files = [i for i in os.listdir()] + if files: + subprocess.call(['rm', '-r'] + files) os.system(f"/bin/dd if={dd_input} of={base_file} bs={bs} count={count}") LOGGER.info(f"Base file created at {base_file}") base_hash = md5(base_file)