From e503f707e28123c40454468558f66a9dd0a04585 Mon Sep 17 00:00:00 2001 From: liyu-ma Date: Fri, 6 Mar 2026 21:58:41 +1000 Subject: [PATCH 1/5] Record terraform run result metadata --- .../extract_terraform_operation_metadata.py | 67 ++++++++++++++----- 1 file changed, 50 insertions(+), 17 deletions(-) diff --git a/modules/python/terraform/extract_terraform_operation_metadata.py b/modules/python/terraform/extract_terraform_operation_metadata.py index 9e993fe7af..1e7c90d257 100644 --- a/modules/python/terraform/extract_terraform_operation_metadata.py +++ b/modules/python/terraform/extract_terraform_operation_metadata.py @@ -4,8 +4,18 @@ import os import datetime -# Regex to extract: full module path and time -PATTERN = re.compile(r"(module\.[^:]+): (?:Creation|Destruction) complete after (\d+h\d+m\d+s|\d+h\d+s|\d+m\d+s|\d+s)") +# Regex to extract: full module path and time from completion lines +COMPLETE_PATTERN = re.compile(r"(module\.[^:]+): (?:Creation|Destruction) complete after (\d+h\d+m\d+s|\d+h\d+s|\d+m\d+s|\d+s)") + +# Regex to extract: full module path from initial "Creating"/"Destroying" lines +# e.g. module.azapi["ccp-provisioning-H4"].azapi_resource.aks_cluster: Creating... +# e.g. module.azapi["ccp-provisioning-H4"].azapi_resource.aks_cluster: Destroying +START_PATTERN = re.compile(r"(module\.[^:]+): (?:Creating|Destroying)") + +# Regex to extract: elapsed time from "Still creating/destroying..." lines +# e.g. module.azapi[...].azapi_resource.aks_cluster: Still creating... [29m51s elapsed] +# or: module.azapi[...].azapi_resource.aks_cluster: Still destroying... 00m40s elapsed] +ELAPSED_PATTERN = re.compile(r"Still (?:creating|destroying)\.\.\. \[?(\d+h\d+m\d+s|\d+h\d+s|\d+m\d+s|\d+s) elapsed\]") def time_to_seconds(time_str): try: @@ -33,6 +43,23 @@ def parse_module_path(full_path): return module_name, submodule_path, resource_name +def build_result(full_path, time_str, run_id, _command_type, _scenario_type, _scenario_name, completed): + seconds = time_to_seconds(time_str) + module, submodule, resource = parse_module_path(full_path) + + return { + "timestamp": datetime.datetime.now().isoformat(), + "run_id": run_id, + "scenario_type": _scenario_type, + "scenario_name": _scenario_name, + "module_name": module, + "submodule_name": submodule, + "resource_name": resource, + "action": _command_type, + "time_taken_seconds": seconds, + "result": {"success": completed} + } + def process_terraform_logs(log_path, _command_type, _scenario_type, _scenario_name): log_file = os.path.join(log_path, f"terraform_{_command_type}.log") run_id = os.getenv("RUN_ID", "") @@ -43,25 +70,31 @@ def process_terraform_logs(log_path, _command_type, _scenario_type, _scenario_na return results try: + full_path = None + last_elapsed_time_str = None + completed = False + with open(log_file, "r", encoding='utf-8') as f: for line in f: - match = PATTERN.search(line) + match = COMPLETE_PATTERN.search(line) if match: full_path, time_str = match.groups() - seconds = time_to_seconds(time_str) - module, submodule, resource = parse_module_path(full_path) - - results.append({ - "timestamp": datetime.datetime.now().isoformat(), - "run_id": run_id, - "scenario_type": _scenario_type, - "scenario_name": _scenario_name, - "module_name": module, - "submodule_name": submodule, - "resource_name": resource, - "action": _command_type, - "time_taken_seconds": seconds - }) + completed = True + results.append(build_result(full_path, time_str, run_id, _command_type, _scenario_type, _scenario_name, True)) + break + + if not full_path: + start_match = START_PATTERN.search(line) + if start_match: + full_path = start_match.group(1) + + elapsed_match = ELAPSED_PATTERN.search(line) + if elapsed_match: + last_elapsed_time_str = elapsed_match.group(1) + + # If the action never completed, use the last elapsed time as fallback + if not completed and full_path and last_elapsed_time_str: + results.append(build_result(full_path, last_elapsed_time_str, run_id, _command_type, _scenario_type, _scenario_name, False)) except Exception as e: print(f"[ERROR] Failed to process log file '{log_file}': {e}") From 745c7d342f3d536056a1161c2ba04149d7a132a3 Mon Sep 17 00:00:00 2001 From: liyu-ma Date: Sun, 8 Mar 2026 16:15:45 +1000 Subject: [PATCH 2/5] Support multiple runs resulted from retries --- .../extract_terraform_operation_metadata.py | 40 ++++++++++------ ...st_extract_terraform_operation_metadata.py | 47 +++++++++++++++++++ 2 files changed, 73 insertions(+), 14 deletions(-) diff --git a/modules/python/terraform/extract_terraform_operation_metadata.py b/modules/python/terraform/extract_terraform_operation_metadata.py index 1e7c90d257..de69d6e9b1 100644 --- a/modules/python/terraform/extract_terraform_operation_metadata.py +++ b/modules/python/terraform/extract_terraform_operation_metadata.py @@ -61,6 +61,12 @@ def build_result(full_path, time_str, run_id, _command_type, _scenario_type, _sc } def process_terraform_logs(log_path, _command_type, _scenario_type, _scenario_name): + """Process terraform log file and collect operation metadata for each run. + A single log file may contain multiple runs of the same module when failures + trigger retries. Each run starts with a "Creating..."/"Destroying..." line. + We collect data for all runs: successful runs use the completion time, and + failed runs use the last reported elapsed time as a fallback. + """ log_file = os.path.join(log_path, f"terraform_{_command_type}.log") run_id = os.getenv("RUN_ID", "") results = [] @@ -70,31 +76,37 @@ def process_terraform_logs(log_path, _command_type, _scenario_type, _scenario_na return results try: - full_path = None - last_elapsed_time_str = None - completed = False + current_full_path = None + current_elapsed_time_str = None + current_completed = False with open(log_file, "r", encoding='utf-8') as f: for line in f: + start_match = START_PATTERN.search(line) + if start_match: + # A new run is starting; flush the previous run if it was incomplete + if current_full_path and not current_completed and current_elapsed_time_str: + results.append(build_result(current_full_path, current_elapsed_time_str, run_id, _command_type, _scenario_type, _scenario_name, False)) + + current_full_path = start_match.group(1) + current_elapsed_time_str = None + current_completed = False + continue + match = COMPLETE_PATTERN.search(line) if match: full_path, time_str = match.groups() - completed = True + current_completed = True results.append(build_result(full_path, time_str, run_id, _command_type, _scenario_type, _scenario_name, True)) - break - - if not full_path: - start_match = START_PATTERN.search(line) - if start_match: - full_path = start_match.group(1) + continue elapsed_match = ELAPSED_PATTERN.search(line) if elapsed_match: - last_elapsed_time_str = elapsed_match.group(1) + current_elapsed_time_str = elapsed_match.group(1) - # If the action never completed, use the last elapsed time as fallback - if not completed and full_path and last_elapsed_time_str: - results.append(build_result(full_path, last_elapsed_time_str, run_id, _command_type, _scenario_type, _scenario_name, False)) + # Flush the last run if it was incomplete + if current_full_path and not current_completed and current_elapsed_time_str: + results.append(build_result(current_full_path, current_elapsed_time_str, run_id, _command_type, _scenario_type, _scenario_name, False)) except Exception as e: print(f"[ERROR] Failed to process log file '{log_file}': {e}") diff --git a/modules/python/tests/test_extract_terraform_operation_metadata.py b/modules/python/tests/test_extract_terraform_operation_metadata.py index 13003db2d1..960f0e892c 100644 --- a/modules/python/tests/test_extract_terraform_operation_metadata.py +++ b/modules/python/tests/test_extract_terraform_operation_metadata.py @@ -169,5 +169,52 @@ def test_process_terraform_logs_with_invalid_log_line(self, mock_open_file, mock mock_open_file.assert_called_once_with('/fake/path/terraform_apply.log', 'r', encoding='utf-8') mock_isfile.assert_called_once_with("/fake/path/terraform_apply.log") + @patch("os.path.isfile", return_value=True) + @patch("builtins.open", new_callable=mock_open, read_data=( + "module.azapi[\"ccp\"].azapi_resource.aks_cluster: Creating...\n" + "module.azapi[\"ccp\"].azapi_resource.aks_cluster: Still creating... [10m0s elapsed]\n" + "module.azapi[\"ccp\"].azapi_resource.aks_cluster: Still creating... 20m0s elapsed]\n" + "│ Error: Failed to create/update resource\n" + "module.azapi[\"ccp\"].azapi_resource.aks_cluster: Creating...\n" + "module.azapi[\"ccp\"].azapi_resource.aks_cluster: Still creating... [15m0s elapsed]\n" + "module.azapi[\"ccp\"].azapi_resource.aks_cluster: Still creating... 25m30s elapsed]\n" + "module.azapi[\"ccp\"].azapi_resource.aks_cluster: Creating...\n" + "module.azapi[\"ccp\"].azapi_resource.aks_cluster: Still creating... [5m0s elapsed]\n" + "module.azapi[\"ccp\"].azapi_resource.aks_cluster: Still creating... 30m45s elapsed]\n" + "module.azapi[\"ccp\"].azapi_resource.aks_cluster: Creation complete after 30m55s [id=/subscriptions/b8ceb4e5-f05b-4562-a9f5-14acb1f24219/resourceGroups/57202-578c08a2/providers/Microsoft.ContainerService/managedClusters/ccp-provisioning-H4]\n" + )) + def test_process_terraform_logs_with_failed_run_and_retries(self, mock_open_file, mock_isfile): + os.environ["RUN_ID"] = "9988776655" + + results = process_terraform_logs( + log_path="/fake/path", + _command_type="apply", + _scenario_type="perf-eval", + _scenario_name="test_scenario_name", + ) + + self.assertEqual(len(results), 3) + + # First failed run - last elapsed was 20m0s = 1200s + self.assertEqual(results[0]["module_name"], "azapi[\"ccp\"]") + self.assertEqual(results[0]["resource_name"], "aks_cluster") + self.assertEqual(results[0]["time_taken_seconds"], 1200) + self.assertEqual(results[0]["result"], {"success": False}) + + # Second failed run (retry 1) - last elapsed was 25m30s = 1530s + self.assertEqual(results[1]["module_name"], "azapi[\"ccp\"]") + self.assertEqual(results[1]["resource_name"], "aks_cluster") + self.assertEqual(results[1]["time_taken_seconds"], 1530) + self.assertEqual(results[1]["result"], {"success": False}) + + # Third failed run (retry 2) - last elapsed was 30m45s = 1845s + self.assertEqual(results[2]["module_name"], "azapi[\"ccp\"]") + self.assertEqual(results[2]["resource_name"], "aks_cluster") + self.assertEqual(results[2]["time_taken_seconds"], 1855) + self.assertEqual(results[2]["result"], {"success": True}) + + mock_open_file.assert_called_once_with('/fake/path/terraform_apply.log', 'r', encoding='utf-8') + mock_isfile.assert_called_once_with("/fake/path/terraform_apply.log") + if __name__ == "__main__": unittest.main() From 7ff3c776dde3194b101f49e4c43526d3ec594bac Mon Sep 17 00:00:00 2001 From: liyu-ma Date: Tue, 10 Mar 2026 15:53:27 +1000 Subject: [PATCH 3/5] Capture timeout in terraform run --- .../extract_terraform_operation_metadata.py | 17 ++++++--- ...st_extract_terraform_operation_metadata.py | 36 +++++++++++++++++-- steps/terraform/run-command.yml | 2 +- 3 files changed, 46 insertions(+), 9 deletions(-) diff --git a/modules/python/terraform/extract_terraform_operation_metadata.py b/modules/python/terraform/extract_terraform_operation_metadata.py index de69d6e9b1..90ab816246 100644 --- a/modules/python/terraform/extract_terraform_operation_metadata.py +++ b/modules/python/terraform/extract_terraform_operation_metadata.py @@ -43,7 +43,7 @@ def parse_module_path(full_path): return module_name, submodule_path, resource_name -def build_result(full_path, time_str, run_id, _command_type, _scenario_type, _scenario_name, completed): +def build_result(full_path, time_str, run_id, _command_type, _scenario_type, _scenario_name, completed, timed_out): seconds = time_to_seconds(time_str) module, submodule, resource = parse_module_path(full_path) @@ -57,7 +57,7 @@ def build_result(full_path, time_str, run_id, _command_type, _scenario_type, _sc "resource_name": resource, "action": _command_type, "time_taken_seconds": seconds, - "result": {"success": completed} + "result": {"success": completed, "timed_out": timed_out} } def process_terraform_logs(log_path, _command_type, _scenario_type, _scenario_name): @@ -79,34 +79,41 @@ def process_terraform_logs(log_path, _command_type, _scenario_type, _scenario_na current_full_path = None current_elapsed_time_str = None current_completed = False + current_timed_out = False with open(log_file, "r", encoding='utf-8') as f: for line in f: + # Check for timeout on every line before any continue statements + if "context deadline exceeded" in line: + current_timed_out = True + start_match = START_PATTERN.search(line) if start_match: # A new run is starting; flush the previous run if it was incomplete if current_full_path and not current_completed and current_elapsed_time_str: - results.append(build_result(current_full_path, current_elapsed_time_str, run_id, _command_type, _scenario_type, _scenario_name, False)) + results.append(build_result(current_full_path, current_elapsed_time_str, run_id, _command_type, _scenario_type, _scenario_name, False, current_timed_out)) current_full_path = start_match.group(1) current_elapsed_time_str = None current_completed = False + current_timed_out = False continue match = COMPLETE_PATTERN.search(line) if match: full_path, time_str = match.groups() current_completed = True - results.append(build_result(full_path, time_str, run_id, _command_type, _scenario_type, _scenario_name, True)) + results.append(build_result(full_path, time_str, run_id, _command_type, _scenario_type, _scenario_name, True, False)) continue elapsed_match = ELAPSED_PATTERN.search(line) if elapsed_match: current_elapsed_time_str = elapsed_match.group(1) + continue # Flush the last run if it was incomplete if current_full_path and not current_completed and current_elapsed_time_str: - results.append(build_result(current_full_path, current_elapsed_time_str, run_id, _command_type, _scenario_type, _scenario_name, False)) + results.append(build_result(current_full_path, current_elapsed_time_str, run_id, _command_type, _scenario_type, _scenario_name, False, current_timed_out)) except Exception as e: print(f"[ERROR] Failed to process log file '{log_file}': {e}") diff --git a/modules/python/tests/test_extract_terraform_operation_metadata.py b/modules/python/tests/test_extract_terraform_operation_metadata.py index 960f0e892c..2dd23a63d4 100644 --- a/modules/python/tests/test_extract_terraform_operation_metadata.py +++ b/modules/python/tests/test_extract_terraform_operation_metadata.py @@ -199,19 +199,49 @@ def test_process_terraform_logs_with_failed_run_and_retries(self, mock_open_file self.assertEqual(results[0]["module_name"], "azapi[\"ccp\"]") self.assertEqual(results[0]["resource_name"], "aks_cluster") self.assertEqual(results[0]["time_taken_seconds"], 1200) - self.assertEqual(results[0]["result"], {"success": False}) + self.assertEqual(results[0]["result"], {"success": False, "timed_out": False}) # Second failed run (retry 1) - last elapsed was 25m30s = 1530s self.assertEqual(results[1]["module_name"], "azapi[\"ccp\"]") self.assertEqual(results[1]["resource_name"], "aks_cluster") self.assertEqual(results[1]["time_taken_seconds"], 1530) - self.assertEqual(results[1]["result"], {"success": False}) + self.assertEqual(results[1]["result"], {"success": False, "timed_out": False}) # Third failed run (retry 2) - last elapsed was 30m45s = 1845s self.assertEqual(results[2]["module_name"], "azapi[\"ccp\"]") self.assertEqual(results[2]["resource_name"], "aks_cluster") self.assertEqual(results[2]["time_taken_seconds"], 1855) - self.assertEqual(results[2]["result"], {"success": True}) + self.assertEqual(results[2]["result"], {"success": True, "timed_out": False}) + + mock_open_file.assert_called_once_with('/fake/path/terraform_apply.log', 'r', encoding='utf-8') + mock_isfile.assert_called_once_with("/fake/path/terraform_apply.log") + + @patch("os.path.isfile", return_value=True) + @patch("builtins.open", new_callable=mock_open, read_data=( + "module.azapi[\"ccp\"].azapi_resource.aks_cluster: Creating...\n" + "module.azapi[\"ccp\"].azapi_resource.aks_cluster: Still creating... [5m0s elapsed]\n" + "module.azapi[\"ccp\"].azapi_resource.aks_cluster: Still creating... [10m0s elapsed]\n" + "creating/updating Resource: (ResourceId\n" + "/subscriptions/b8ceb4e5-f05b-4562-a9f5-14acb1f24219/resourceGroups/58296-a6a4e57b/providers/Microsoft.ContainerService/managedClusters/ccp-provisioning-H8\n" + "│ Error: creating/updating Resource: context deadline exceeded\n" + )) + def test_process_terraform_logs_with_timeout(self, mock_open_file, mock_isfile): + os.environ["RUN_ID"] = "1234567890" + + results = process_terraform_logs( + log_path="/fake/path", + _command_type="apply", + _scenario_type="perf-eval", + _scenario_name="test_scenario_name", + ) + + self.assertEqual(len(results), 1) + + # Run timed out + self.assertEqual(results[0]["module_name"], "azapi[\"ccp\"]") + self.assertEqual(results[0]["resource_name"], "aks_cluster") + self.assertEqual(results[0]["time_taken_seconds"], 600) + self.assertEqual(results[0]["result"], {"success": False, "timed_out": True}) mock_open_file.assert_called_once_with('/fake/path/terraform_apply.log', 'r', encoding='utf-8') mock_isfile.assert_called_once_with("/fake/path/terraform_apply.log") diff --git a/steps/terraform/run-command.yml b/steps/terraform/run-command.yml index e2cbdc173c..2af1d1dab6 100644 --- a/steps/terraform/run-command.yml +++ b/steps/terraform/run-command.yml @@ -41,7 +41,7 @@ steps: fi set +e - terraform ${{ parameters.command }} --auto-approve ${{ parameters.arguments }} -var-file $terraform_input_file -var json_input="$terraform_input_variables" | tee terraform_${{ parameters.command }}.log + terraform ${{ parameters.command }} --auto-approve ${{ parameters.arguments }} -var-file $terraform_input_file -var json_input="$terraform_input_variables" 2>&1 | tee terraform_${{ parameters.command }}.log exit_code=${PIPESTATUS[0]} if [[ $exit_code -ne 0 ]]; then if [[ ${{ parameters.command }} == "apply" && "$CLOUD" == "azure" ]]; then From a0a3dd1ad3537bfc641bbd46634fb7f470a94a1f Mon Sep 17 00:00:00 2001 From: liyu-ma Date: Wed, 11 Mar 2026 13:25:26 +1000 Subject: [PATCH 4/5] update timeout for pipeline --- modules/terraform/azure/azapi/main.tf | 4 ++++ .../Hyperscale Cluster Benchmark/ccp-provisioning-H2.yml | 2 +- .../Hyperscale Cluster Benchmark/ccp-provisioning-H4.yml | 2 +- .../Hyperscale Cluster Benchmark/ccp-provisioning-H8.yml | 2 +- 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/modules/terraform/azure/azapi/main.tf b/modules/terraform/azure/azapi/main.tf index 7a3348d64a..52542983a0 100644 --- a/modules/terraform/azure/azapi/main.tf +++ b/modules/terraform/azure/azapi/main.tf @@ -62,4 +62,8 @@ resource "azapi_resource" "aks_cluster" { response_export_values = [ "properties.fqdn" ] + + timeouts { + create = "60m" + } } diff --git a/pipelines/perf-eval/Hyperscale Cluster Benchmark/ccp-provisioning-H2.yml b/pipelines/perf-eval/Hyperscale Cluster Benchmark/ccp-provisioning-H2.yml index c3e8d002c2..f2662b6fa8 100644 --- a/pipelines/perf-eval/Hyperscale Cluster Benchmark/ccp-provisioning-H2.yml +++ b/pipelines/perf-eval/Hyperscale Cluster Benchmark/ccp-provisioning-H2.yml @@ -32,5 +32,5 @@ stages: max_parallel: 1 credential_type: service_connection ssh_key_enabled: false - timeout_in_minutes: 60 + timeout_in_minutes: 120 retry_attempt_count: 0 diff --git a/pipelines/perf-eval/Hyperscale Cluster Benchmark/ccp-provisioning-H4.yml b/pipelines/perf-eval/Hyperscale Cluster Benchmark/ccp-provisioning-H4.yml index 3dbd3b5643..4958e584a9 100644 --- a/pipelines/perf-eval/Hyperscale Cluster Benchmark/ccp-provisioning-H4.yml +++ b/pipelines/perf-eval/Hyperscale Cluster Benchmark/ccp-provisioning-H4.yml @@ -32,5 +32,5 @@ stages: max_parallel: 1 credential_type: service_connection ssh_key_enabled: false - timeout_in_minutes: 60 + timeout_in_minutes: 120 retry_attempt_count: 0 diff --git a/pipelines/perf-eval/Hyperscale Cluster Benchmark/ccp-provisioning-H8.yml b/pipelines/perf-eval/Hyperscale Cluster Benchmark/ccp-provisioning-H8.yml index f850637e01..255df4f26a 100644 --- a/pipelines/perf-eval/Hyperscale Cluster Benchmark/ccp-provisioning-H8.yml +++ b/pipelines/perf-eval/Hyperscale Cluster Benchmark/ccp-provisioning-H8.yml @@ -32,5 +32,5 @@ stages: max_parallel: 1 credential_type: service_connection ssh_key_enabled: false - timeout_in_minutes: 60 + timeout_in_minutes: 120 retry_attempt_count: 0 From b3c2e0377e2143dfc35e1fcebfd8e89a50867f36 Mon Sep 17 00:00:00 2001 From: liyu-ma Date: Wed, 11 Mar 2026 15:52:52 +1000 Subject: [PATCH 5/5] Improve tests --- ...st_extract_terraform_operation_metadata.py | 68 +++++++++++++++++-- 1 file changed, 64 insertions(+), 4 deletions(-) diff --git a/modules/python/tests/test_extract_terraform_operation_metadata.py b/modules/python/tests/test_extract_terraform_operation_metadata.py index 2dd23a63d4..9d4ab33ed0 100644 --- a/modules/python/tests/test_extract_terraform_operation_metadata.py +++ b/modules/python/tests/test_extract_terraform_operation_metadata.py @@ -222,10 +222,13 @@ def test_process_terraform_logs_with_failed_run_and_retries(self, mock_open_file "module.azapi[\"ccp\"].azapi_resource.aks_cluster: Still creating... [5m0s elapsed]\n" "module.azapi[\"ccp\"].azapi_resource.aks_cluster: Still creating... [10m0s elapsed]\n" "creating/updating Resource: (ResourceId\n" - "/subscriptions/b8ceb4e5-f05b-4562-a9f5-14acb1f24219/resourceGroups/58296-a6a4e57b/providers/Microsoft.ContainerService/managedClusters/ccp-provisioning-H8\n" + "/subscriptions/b8ceb4e5/resourceGroups/58296/providers/Microsoft.ContainerService/managedClusters/ccp-H8\n" "│ Error: creating/updating Resource: context deadline exceeded\n" + "module.azapi[\"ccp\"].azapi_resource.aks_cluster: Creating...\n" + "module.azapi[\"ccp\"].azapi_resource.aks_cluster: Still creating... [5m0s elapsed]\n" + "module.azapi[\"ccp\"].azapi_resource.aks_cluster: Creation complete after 8m30s [id=/subscriptions/b8ceb4e5/resourceGroups/58296/providers/Microsoft.ContainerService/managedClusters/ccp-H8]\n" )) - def test_process_terraform_logs_with_timeout(self, mock_open_file, mock_isfile): + def test_process_terraform_logs_with_timeout_and_retry(self, mock_open_file, mock_isfile): os.environ["RUN_ID"] = "1234567890" results = process_terraform_logs( @@ -235,14 +238,71 @@ def test_process_terraform_logs_with_timeout(self, mock_open_file, mock_isfile): _scenario_name="test_scenario_name", ) - self.assertEqual(len(results), 1) + self.assertEqual(len(results), 2) - # Run timed out + # First run timed out self.assertEqual(results[0]["module_name"], "azapi[\"ccp\"]") self.assertEqual(results[0]["resource_name"], "aks_cluster") self.assertEqual(results[0]["time_taken_seconds"], 600) self.assertEqual(results[0]["result"], {"success": False, "timed_out": True}) + # Retry succeeded + self.assertEqual(results[1]["module_name"], "azapi[\"ccp\"]") + self.assertEqual(results[1]["resource_name"], "aks_cluster") + self.assertEqual(results[1]["time_taken_seconds"], 510) + self.assertEqual(results[1]["result"], {"success": True, "timed_out": False}) + + mock_open_file.assert_called_once_with('/fake/path/terraform_apply.log', 'r', encoding='utf-8') + mock_isfile.assert_called_once_with("/fake/path/terraform_apply.log") + + @patch("os.path.isfile", return_value=True) + @patch("builtins.open", new_callable=mock_open, read_data=( + "module.azapi[\"ccp\"].azapi_resource.aks_cluster: Creating...\n" + "module.azapi[\"ccp\"].azapi_resource.aks_cluster: Still creating... [5m0s elapsed]\n" + "module.azapi[\"ccp\"].azapi_resource.aks_cluster: Still creating... [10m0s elapsed]\n" + "│ Error: Failed to create/update resource\n" + "module.azapi[\"ccp\"].azapi_resource.aks_cluster: Creating...\n" + "module.azapi[\"ccp\"].azapi_resource.aks_cluster: Still creating... [5m0s elapsed]\n" + "module.azapi[\"ccp\"].azapi_resource.aks_cluster: Still creating... [10m0s elapsed]\n" + "│ Error: creating/updating Resource: context deadline exceeded\n" + "module.azapi[\"ccp\"].azapi_resource.aks_cluster: Creating...\n" + "module.azapi[\"ccp\"].azapi_resource.aks_cluster: Still creating... [5m0s elapsed]\n" + "module.azapi[\"ccp\"].azapi_resource.aks_cluster: Still creating... [10m0s elapsed]\n" + "│ Error: creating/updating Resource: context deadline exceeded\n" + )) + def test_process_terraform_logs_with_all_retries_failed(self, mock_open_file, mock_isfile): + os.environ["RUN_ID"] = "1112223334" + + results = process_terraform_logs( + log_path="/fake/path", + _command_type="apply", + _scenario_type="perf-eval", + _scenario_name="test_scenario_name", + ) + + self.assertEqual(len(results), 3) + + # First run failed with a non-timeout error + self.assertEqual(results[0]["run_id"], "1112223334") + self.assertEqual(results[0]["module_name"], "azapi[\"ccp\"]") + self.assertEqual(results[0]["resource_name"], "aks_cluster") + self.assertEqual(results[0]["time_taken_seconds"], 600) + self.assertEqual(results[0]["result"], {"success": False, "timed_out": False}) + + # Second run timed out + self.assertEqual(results[1]["run_id"], "1112223334") + self.assertEqual(results[1]["module_name"], "azapi[\"ccp\"]") + self.assertEqual(results[1]["resource_name"], "aks_cluster") + self.assertEqual(results[1]["time_taken_seconds"], 600) + self.assertEqual(results[1]["result"], {"success": False, "timed_out": True}) + + # Third run timed out + self.assertEqual(results[2]["run_id"], "1112223334") + self.assertEqual(results[2]["module_name"], "azapi[\"ccp\"]") + self.assertEqual(results[2]["resource_name"], "aks_cluster") + self.assertEqual(results[2]["time_taken_seconds"], 600) + self.assertEqual(results[2]["result"], {"success": False, "timed_out": True}) + mock_open_file.assert_called_once_with('/fake/path/terraform_apply.log', 'r', encoding='utf-8') mock_isfile.assert_called_once_with("/fake/path/terraform_apply.log")