Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions modules/python/fio/fio.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import argparse
import json
import os
import shlex
import subprocess
from datetime import datetime, timezone
import yaml
Expand Down Expand Up @@ -55,7 +56,9 @@ def calculate_pod_startup_latency(pod):
logger.error(f"Error calculating pod startup latency for pod {pod.metadata.name}: {str(e)}")
return None

def execute(block_size, iodepth, method, runtime, numjobs, file_size, storage_name, kustomize_dir, result_dir):
def execute(block_size, iodepth, method, runtime, numjobs, file_size, storage_name, kustomize_dir, result_dir, image):
if not image.strip():
raise ValueError("A non-empty Fio container image is required")
fio_nodes = KUBERNETES_CLIENT.get_ready_nodes(label_selector='fio-dedicated=true')
if not fio_nodes:
raise RuntimeError("No ready and schedulable nodes found with label 'fio-dedicated=true'.")
Expand Down Expand Up @@ -97,7 +100,7 @@ def execute(block_size, iodepth, method, runtime, numjobs, file_size, storage_na
"spec": {
"template": {
"spec": {
"containers": [{"name": "fio", "command": fio_command}],
"containers": [{"name": "fio", "command": fio_command, "image": image}],
"nodeSelector": {
"kubernetes.io/hostname": node_name
},
Expand All @@ -111,9 +114,10 @@ def execute(block_size, iodepth, method, runtime, numjobs, file_size, storage_na
with open(patch_file, "w", encoding="utf-8") as f:
yaml.dump(patch, f)

create_command = f"kustomize build {kustomize_dir}/overlays/{storage_name}/deployment | name={job_name} envsubst | kubectl apply -f -"
logger.info(f"Running command: {create_command}")
subprocess.run(create_command, shell=True, check=True, capture_output=True)
overlay = shlex.quote(os.path.join(kustomize_dir, "overlays", storage_name, "deployment"))
create_command = f"kubectl kustomize {overlay} | name={job_name} envsubst | kubectl apply -f -"
logger.info("Running command: %s", create_command)
subprocess.run(["bash", "-o", "pipefail", "-c", create_command], check=True)

metadata_path = f"{result_dir}/fio-{block_size}-{iodepth}-{method}-{numjobs}-{file_size}-metadata.json"
result_path = f"{result_dir}/fio-{block_size}-{iodepth}-{method}-{numjobs}-{file_size}.json"
Expand Down Expand Up @@ -172,9 +176,9 @@ def execute(block_size, iodepth, method, runtime, numjobs, file_size, storage_na
f.write(json.dumps(metadata) + "\n")
logger.info(f"Metadata saved to {metadata_path}")

delete_command = f"kustomize build {kustomize_dir}/overlays/{storage_name}/deployment | name={job_name} envsubst | kubectl delete -f -"
logger.info(f"Running command: {delete_command}")
subprocess.run(delete_command, shell=True, check=True, capture_output=True)
delete_command = f"kubectl kustomize {overlay} | name={job_name} envsubst | kubectl delete -f -"
logger.info("Running command: %s", delete_command)
subprocess.run(["bash", "-o", "pipefail", "-c", delete_command], check=True)

def collect(vm_size, block_size, iodepth, method, numjobs, file_size, result_dir, run_url, cloud_info):
raw_result_path = f"{result_dir}/fio-{block_size}-{iodepth}-{method}-{numjobs}-{file_size}.json"
Expand Down Expand Up @@ -254,6 +258,7 @@ def main():
parser_execute.add_argument("--numjobs", type=int, help="Number of jobs")
parser_execute.add_argument("--file_size", type=str, help="File size")
parser_execute.add_argument("--storage_name", type=str, help="Storage name")
parser_execute.add_argument("--image", required=True, help="Fio container image")
parser_execute.add_argument("--kustomize_dir", type=str, help="Directory for kustomize")
parser_execute.add_argument(
"--result_dir", type=str, help="Directory to store results"
Expand Down Expand Up @@ -289,6 +294,7 @@ def main():
args.storage_name,
args.kustomize_dir,
args.result_dir,
args.image,
)
elif args.command == "collect":
collect(
Expand Down
30 changes: 16 additions & 14 deletions modules/python/tests/test_fio.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,23 +64,18 @@ def test_execute_success(
storage_name,
kustomize_dir,
result_dir,
image="example.registry/fio:3.40",
)

# Verify the yaml patch was written (once per node)
mock_yaml_dump.assert_called_once()
job_patch = mock_yaml_dump.call_args.args[0]
self.assertEqual(job_patch["spec"]["template"]["spec"]["containers"][0]["image"], "example.registry/fio:3.40")

# Verify subprocess.run was called twice (create and delete commands)
self.assertEqual(mock_run.call_count, 2)

# Verify the create command
create_call = mock_run.call_args_list[0]
self.assertTrue("kustomize build" in create_call[0][0])
self.assertTrue("kubectl apply" in create_call[0][0])

# Verify the delete command
delete_call = mock_run.call_args_list[1]
self.assertTrue("kustomize build" in delete_call[0][0])
self.assertTrue("kubectl delete" in delete_call[0][0])
render = "kubectl kustomize /tmp/kustomize/overlays/fio/deployment | name=fio-0 envsubst"
self.assertEqual([call.args[0][-1] for call in mock_run.call_args_list], [
f"{render} | kubectl apply -f -", f"{render} | kubectl delete -f -",
])

# Verify the result directory was created
mock_makedirs.assert_called_once_with(result_dir, exist_ok=True)
Expand Down Expand Up @@ -132,10 +127,15 @@ def test_execute_failure_with_no_nodes(self, mock_k8s_client):
storage_name,
kustomize_dir,
result_dir,
image="example.registry/fio:3.40",
)

self.assertEqual(str(context.exception), "No ready and schedulable nodes found with label 'fio-dedicated=true'.")

def test_execute_rejects_empty_image(self):
with self.assertRaisesRegex(ValueError, "non-empty Fio container image"):
execute("4k", 16, "read", 60, 1, "10G", "fio", "/tmp/kustomize", "/tmp/results", " ")

@patch("fio.fio.KUBERNETES_CLIENT")
@patch("fio.fio.yaml.dump")
@patch("fio.fio.os.makedirs")
Expand Down Expand Up @@ -177,11 +177,12 @@ def test_execute_with_no_pods_found(
storage_name,
kustomize_dir,
result_dir,
image="example.registry/fio:3.40",
)

# The function should still create the job and patch file
mock_yaml_dump.assert_called_once()
self.assertEqual(mock_run.call_count, 1) # only create command, delete is skipped due to no pods
self.assertEqual(mock_run.call_count, 1)

@patch('builtins.open', new_callable=mock_open)
@patch('fio.fio.datetime')
Expand Down Expand Up @@ -327,13 +328,14 @@ def test_main_execute_command(self, mock_execute, mock_parse_args):
mock_args.file_size = "10G"
mock_args.storage_name = "fio"
mock_args.kustomize_dir = "/tmp/kustomize"
mock_args.image = "example.registry/fio:3.40"
mock_args.result_dir = "/tmp/results"
mock_parse_args.return_value = mock_args

main()

mock_execute.assert_called_once_with(
"4k", 16, "read", 60, 1, "10G", "fio", "/tmp/kustomize", "/tmp/results"
"4k", 16, "read", 60, 1, "10G", "fio", "/tmp/kustomize", "/tmp/results", "example.registry/fio:3.40"
)

@patch("argparse.ArgumentParser.parse_args")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ stages:
topology: k8s-os-disk
engine: fio
engine_input:
fio_image: telescope.azurecr.io/perf-eval/fio:3.40
fio_command_array:
- "128k|16|write|600|16|32G"
- "128k|16|read|600|16|32G"
Expand Down
3 changes: 3 additions & 0 deletions pipelines/perf-eval/Storage Benchmark/k8s-os-disk-fio.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ stages:
topology: k8s-os-disk
engine: fio
engine_input:
fio_image: telescope.azurecr.io/perf-eval/fio:3.40
fio_command_array:
- "4k|32|randread|180|1|10G"
- "4k|32|randwrite|180|1|10G"
Expand Down Expand Up @@ -76,6 +77,7 @@ stages:
topology: k8s-os-disk
engine: fio
engine_input:
fio_image: telescope.azurecr.io/perf-eval/fio:3.40
fio_command_array:
- "4k|32|randread|180|1|10G"
- "4k|32|randwrite|180|1|10G"
Expand Down Expand Up @@ -113,6 +115,7 @@ stages:
topology: k8s-os-disk
engine: fio
engine_input:
fio_image: 891516228446.dkr.ecr.us-west-2.amazonaws.com/telescope-benchmarks:fio-3.40
fio_command_array:
- "4k|32|randread|180|1|10G"
- "4k|32|randwrite|180|1|10G"
Expand Down
12 changes: 10 additions & 2 deletions steps/engine/fio/execute.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
parameters:
fio_properties: {} # format: block_size|iodepth|method|runtime|numjobs|file_size
storage_name: ''
- name: fio_properties # format: block_size|iodepth|method|runtime|numjobs|file_size
type: object
default: {}
- name: storage_name
type: string
default: ''
- name: fio_image
type: string

steps:
- ${{ each property in parameters.fio_properties }}:
Expand All @@ -23,6 +29,7 @@ steps:
--numjobs $numjobs \
--file_size $file_size \
--storage_name $STORAGE_NAME \
--image "$FIO_IMAGE" \
--kustomize_dir $KUSTOMIZE_DIR \
--result_dir $RESULT_DIR

Expand All @@ -33,4 +40,5 @@ steps:
KUSTOMIZE_DIR: $(Pipeline.Workspace)/s/modules/kustomize/fio
RESULT_DIR: $(TEST_RESULTS_DIR)
FIO_PROPERTY: ${{ property }}
FIO_IMAGE: ${{ parameters.fio_image }}
STORAGE_NAME: ${{ parameters.storage_name }}
1 change: 1 addition & 0 deletions steps/topology/k8s-os-disk/execute-fio.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ steps:
- template: /steps/engine/fio/execute.yml
parameters:
fio_properties: ${{ parameters.engine_input.fio_command_array }}
fio_image: ${{ parameters.engine_input.fio_image }}
storage_name: $(STORAGE_NAME)
Loading