From 4b869bad8350519f84f0a99fb007539b489b90a4 Mon Sep 17 00:00:00 2001 From: Tullio Sebastiani Date: Thu, 10 Oct 2024 11:15:03 +0200 Subject: [PATCH] added fallback on dd if fallocate is not in the $PATH (#716) Signed-off-by: Tullio Sebastiani --- .../pvc/pvc_scenario_plugin.py | 33 +++++++++++++++++-- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/krkn/scenario_plugins/pvc/pvc_scenario_plugin.py b/krkn/scenario_plugins/pvc/pvc_scenario_plugin.py index d842e955..b252d627 100644 --- a/krkn/scenario_plugins/pvc/pvc_scenario_plugin.py +++ b/krkn/scenario_plugins/pvc/pvc_scenario_plugin.py @@ -176,10 +176,37 @@ def run( start_time = int(time.time()) # Create temp file in the PVC full_path = "%s/%s" % (str(mount_path), str(file_name)) - command = "fallocate -l $((%s*1024)) %s" % ( - str(file_size_kb), - str(full_path), + + fallocate = lib_telemetry.get_lib_kubernetes().exec_cmd_in_pod( + ["command -v fallocate"], + pod_name, + namespace, + container_name, + ) + + dd = lib_telemetry.get_lib_kubernetes().exec_cmd_in_pod( + ["command -v dd"], + pod_name, + namespace, + container_name, ) + + if fallocate: + command = "fallocate -l $((%s*1024)) %s" % ( + str(file_size_kb), + str(full_path), + ) + elif dd is not None: + logging.warning( + "fallocate not found, using dd, it may take longer based on the amount of data, please wait..." + ) + command = f"dd if=/dev/urandom of={str(full_path)} bs=1024 count={str(file_size_kb)} oflag=direct" + else: + logging.error( + "failed to locate required binaries fallocate or dd to execute the scenario" + ) + return 1 + logging.debug("Create temp file in the PVC command:\n %s" % command) lib_telemetry.get_lib_kubernetes().exec_cmd_in_pod( [command],