diff --git a/microsoft/testsuites/core/vm_resize.py b/microsoft/testsuites/core/vm_resize.py index 6faa395b7d..c143ff70b8 100644 --- a/microsoft/testsuites/core/vm_resize.py +++ b/microsoft/testsuites/core/vm_resize.py @@ -110,58 +110,41 @@ def verify_vm_resize_decrease(self, result: TestResult) -> None: resize_action=ResizeAction.DecreaseCoreCount, hot_resize=False, ) - - def _verify_vm_resize( - self, - test_result: TestResult, - resize_action: ResizeAction = ResizeAction.IncreaseCoreCount, - hot_resize: bool = True, - ) -> None: - environment = test_result.environment - assert environment, "fail to get environment from testresult" - node = cast(RemoteNode, environment.nodes[0]) - - resize = node.features[Resize] - if not hot_resize: - start_stop = node.features[StartStop] - start_stop.stop() - retry = 1 - maxretry = 20 - while retry < maxretry: - try: - expected_vm_capability: Optional[NodeSpace] = None - expected_vm_capability, origin_vm_size, final_vm_size = resize.resize( - resize_action - ) - break - except Exception as identifier: - if "no available size for resizing" in str(identifier): - raise SkippedException(str(identifier)) - if ( - "cannot find current vm size in eligible list" in str(identifier) - or "OperationNotAllowed" in str(identifier) - or "Allocation failed" in str(identifier) - or "AllocationFailed" in str(identifier) - or "PropertyChangeNotAllowed" in str(identifier) - or "cannot boot Hypervisor Generation" in str(identifier) - or "due to different CPU Architectures" in str(identifier) - or "An existing connection was forcibly closed by the remote host" - in str(identifier) - or "Following SKUs have failed for Capacity Restrictions" - in str(identifier) - ): - retry = retry + 1 - else: - raise identifier - time.sleep(1) - finally: - if not hot_resize: - start_stop.start() - assert expected_vm_capability, "fail to find proper vm size" - +def _verify_vm_resize( + self, + test_result: TestResult, + resize_action: ResizeAction = ResizeAction.IncreaseCoreCount, + hot_resize: bool = True, +): + environment = test_result.environment + assert environment, "Failed to get environment from test result" + node = cast(RemoteNode, environment.nodes[0]) + + resize = node.features[Resize] + if not hot_resize: + start_stop = node.features[StartStop] + start_stop.stop() + + try: + expected_vm_capability, origin_vm_size, final_vm_size = resize.resize( + resize_action + ) test_result.information["final_vm_size"] = final_vm_size test_result.information["origin_vm_size"] = origin_vm_size self._verify_core_count(node, expected_vm_capability) + except Exception as e: + if "no available size for resizing" in str(e): + raise SkippedException("No available VM size for resizing.") + elif "cannot find current vm size in eligible list" in str(e): + raise SkippedException("Current VM size not in eligible list.") + # Add more specific error handling as needed + else: + raise + + finally: + if not hot_resize: + start_stop.start() + def _verify_core_count(self, node: Node, expected_vm_capability: NodeSpace) -> None: lscpu = node.tools[Lscpu]