Skip to content

Commit

Permalink
added fallback on dd if fallocate is not in the $PATH (#716)
Browse files Browse the repository at this point in the history
Signed-off-by: Tullio Sebastiani <[email protected]>
  • Loading branch information
tsebastiani authored Oct 10, 2024
1 parent a36b0c7 commit 4b869ba
Showing 1 changed file with 30 additions and 3 deletions.
33 changes: 30 additions & 3 deletions krkn/scenario_plugins/pvc/pvc_scenario_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down

0 comments on commit 4b869ba

Please sign in to comment.