Skip to content

Commit

Permalink
block_size parameter for dd
Browse files Browse the repository at this point in the history
Signed-off-by: Tullio Sebastiani <[email protected]>

removed log

Signed-off-by: Tullio Sebastiani <[email protected]>
  • Loading branch information
tsebastiani committed Oct 16, 2024
1 parent 04e4473 commit ce8ab91
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 40 deletions.
46 changes: 6 additions & 40 deletions krkn/scenario_plugins/pvc/pvc_scenario_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ def run(
pvc_name = get_yaml_item_value(scenario_config, "pvc_name", "")
pod_name = get_yaml_item_value(scenario_config, "pod_name", "")
namespace = get_yaml_item_value(scenario_config, "namespace", "")
block_size = get_yaml_item_value(
scenario_config, "block_size", "102400"
)
target_fill_percentage = get_yaml_item_value(
scenario_config, "fill_percentage", "50"
)
Expand Down Expand Up @@ -197,10 +200,12 @@ def run(
str(full_path),
)
elif dd is not None:
block_size = int(block_size)
blocks = int(file_size_kb / int(block_size / 1024))
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"
command = f"dd if=/dev/urandom of={str(full_path)} bs={str(block_size)} count={str(blocks)} oflag=direct"
else:
logging.error(
"failed to locate required binaries fallocate or dd to execute the scenario"
Expand Down Expand Up @@ -241,45 +246,6 @@ def run(
)
return 1

# Calculate file size
file_size_kb = int(
(float(target_fill_percentage / 100) * float(pvc_capacity_kb))
- float(pvc_used_kb)
)
logging.debug("File size: %s KB" % file_size_kb)

file_name = "kraken.tmp"
logging.info(
"Creating %s file, %s KB size, in pod %s at %s (ns %s)"
% (
str(file_name),
str(file_size_kb),
str(pod_name),
str(mount_path),
str(namespace),
)
)

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),
)
logging.debug("Create temp file in the PVC command:\n %s" % command)
lib_telemetry.get_lib_kubernetes().exec_cmd_in_pod(
[command], pod_name, namespace, container_name
)

# Check if file is created
command = "ls -lh %s" % (str(mount_path))
logging.debug("Check file is created command:\n %s" % command)
response = lib_telemetry.get_lib_kubernetes().exec_cmd_in_pod(
[command], pod_name, namespace, container_name
)
logging.info("\n" + str(response))
if str(file_name).lower() in str(response).lower():
logging.info(
"Waiting for the specified duration in the config: %ss" % duration
)
Expand Down
1 change: 1 addition & 0 deletions scenarios/openshift/pvc_scenario.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ pvc_scenario:
namespace: <namespace_name> # Namespace where the PVC is
fill_percentage: 50 # Target percentage to fill up the cluster, value must be higher than current percentage, valid values are between 0 and 99
duration: 60 # Duration in seconds for the fault
block_size: 102400 # used only by dd if fallocate not present in the container

0 comments on commit ce8ab91

Please sign in to comment.