diff --git a/modules/python/fio/fio.py b/modules/python/fio/fio.py index e6c1bf3612..2b0db4f9b9 100644 --- a/modules/python/fio/fio.py +++ b/modules/python/fio/fio.py @@ -1,6 +1,7 @@ import argparse import json import os +import shlex import subprocess from datetime import datetime, timezone import yaml @@ -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'.") @@ -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 }, @@ -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" @@ -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" @@ -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" @@ -289,6 +294,7 @@ def main(): args.storage_name, args.kustomize_dir, args.result_dir, + args.image, ) elif args.command == "collect": collect( diff --git a/modules/python/tests/test_fio.py b/modules/python/tests/test_fio.py index 508ed8acae..e2bf9afbae 100644 --- a/modules/python/tests/test_fio.py +++ b/modules/python/tests/test_fio.py @@ -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) @@ -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") @@ -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') @@ -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") diff --git a/pipelines/perf-eval/Storage Benchmark/k8s-nvme-disk-fio.yml b/pipelines/perf-eval/Storage Benchmark/k8s-nvme-disk-fio.yml index 1110ab2f89..fe3fecd922 100644 --- a/pipelines/perf-eval/Storage Benchmark/k8s-nvme-disk-fio.yml +++ b/pipelines/perf-eval/Storage Benchmark/k8s-nvme-disk-fio.yml @@ -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" diff --git a/pipelines/perf-eval/Storage Benchmark/k8s-os-disk-fio.yml b/pipelines/perf-eval/Storage Benchmark/k8s-os-disk-fio.yml index 3452da562c..7ca470e145 100644 --- a/pipelines/perf-eval/Storage Benchmark/k8s-os-disk-fio.yml +++ b/pipelines/perf-eval/Storage Benchmark/k8s-os-disk-fio.yml @@ -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" @@ -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" @@ -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" diff --git a/steps/engine/fio/execute.yml b/steps/engine/fio/execute.yml index 10baa7adef..139ee4ccc9 100644 --- a/steps/engine/fio/execute.yml +++ b/steps/engine/fio/execute.yml @@ -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 }}: @@ -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 @@ -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 }} diff --git a/steps/topology/k8s-os-disk/execute-fio.yml b/steps/topology/k8s-os-disk/execute-fio.yml index 5a2a77b884..cdf2b648d1 100644 --- a/steps/topology/k8s-os-disk/execute-fio.yml +++ b/steps/topology/k8s-os-disk/execute-fio.yml @@ -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)