Skip to content

Commit c562fa7

Browse files
rabdulfaizyLiliDeng
authored andcommitted
[AI Generated] BugFix: vm_resize security_profile filter and clearer skip
Two related fixes in the VM resize test path: 1. azure Resize feature: when selecting a candidate VM size to resize to, also filter out SKUs whose advertised security_profile SetSpace does not include the source VM's deployed security profile (CVM / TrustedLaunch / Standard). Without this filter the random picker can choose a non-CVM SKU for a CVM-deployed VM and every Azure update call is rejected with PropertyChangeNotAllowed, exhausting all retries. 2. VmResize test suite: when the retry loop ends without a successful resize, raise SkippedException including the last Azure error instead of asserting 'fail to find proper vm size'. This is an environment limitation (no compatible candidate was picked across retries), not a defect in the system under test.
1 parent f869a27 commit c562fa7

2 files changed

Lines changed: 75 additions & 2 deletions

File tree

lisa/microsoft/testsuites/core/vm_resize.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,12 @@ def _verify_vm_resize(
127127
start_stop.stop()
128128
retry = 1
129129
maxretry = 20
130+
expected_vm_capability: Optional[NodeSpace] = None
131+
origin_vm_size: str = ""
132+
final_vm_size: str = ""
133+
last_error: str = ""
130134
while retry < maxretry:
131135
try:
132-
expected_vm_capability: Optional[NodeSpace] = None
133136
expected_vm_capability, origin_vm_size, final_vm_size = resize.resize(
134137
resize_action
135138
)
@@ -150,14 +153,25 @@ def _verify_vm_resize(
150153
in str(e)
151154
or "Following SKUs have failed for Capacity Restrictions" in str(e)
152155
):
156+
last_error = str(e)
153157
retry = retry + 1
154158
else:
155159
raise e
156160
time.sleep(1)
157161
finally:
158162
if not hot_resize:
159163
start_stop.start()
160-
assert expected_vm_capability, "fail to find proper vm size"
164+
if not expected_vm_capability:
165+
# The retry loop exhausted without a successful resize. This is an
166+
# environment limitation (no compatible candidate happened to be
167+
# picked across all retries), not a defect in the system under
168+
# test, so surface it as SKIPPED rather than the misleading
169+
# "fail to find proper vm size" assertion.
170+
raise SkippedException(
171+
f"no resize-compatible VM size succeeded after {maxretry - 1} "
172+
f"attempts for action {resize_action}. last Azure error: "
173+
f"{last_error or 'unknown'}"
174+
)
161175

162176
test_result.information["final_vm_size"] = final_vm_size
163177
test_result.information["origin_vm_size"] = origin_vm_size

lisa/sut_orchestrator/azure/features.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2546,12 +2546,68 @@ def _check_actual_disk_controller_type(
25462546

25472547
return True
25482548

2549+
def _get_actual_security_profile(self) -> Optional[SecurityProfileType]:
2550+
# Read the security profile the source VM was actually deployed with
2551+
# (a concrete value), as opposed to what the SKU advertises in its
2552+
# capability SetSpace. Resizing a CVM-deployed VM to a SKU whose
2553+
# advertised SetSpace includes CVM AND Standard is fine; resizing
2554+
# to a SKU that only advertises Standard will be rejected by Azure
2555+
# with PropertyChangeNotAllowed.
2556+
if not self._node.capability.features:
2557+
return None
2558+
for feature in self._node.capability.features:
2559+
if feature.type != SecurityProfileSettings.type:
2560+
continue
2561+
if not isinstance(feature, SecurityProfileSettings):
2562+
continue
2563+
sp = feature.security_profile
2564+
if isinstance(sp, SecurityProfileType):
2565+
return sp
2566+
if isinstance(sp, search_space.SetSpace):
2567+
items = list(sp)
2568+
if len(items) == 1:
2569+
return items[0]
2570+
return None
2571+
return None
2572+
2573+
def _compare_security_profile(
2574+
self,
2575+
candidate_size: "AzureCapability",
2576+
actual_security_profile: Optional[SecurityProfileType],
2577+
) -> bool:
2578+
# The candidate SKU must support the source VM's deployed security
2579+
# profile (CVM, TrustedLaunch/SecureBoot, Stateless, Standard).
2580+
# Without this filter, the random selector can pick a non-CVM SKU as
2581+
# a resize target for a CVM VM, and every retry will fail with
2582+
# PropertyChangeNotAllowed.
2583+
if not actual_security_profile:
2584+
return True
2585+
assert candidate_size.capability
2586+
assert candidate_size.capability.features
2587+
candidate_sp = next(
2588+
(
2589+
feature
2590+
for feature in candidate_size.capability.features
2591+
if feature.type == SecurityProfileSettings.type
2592+
),
2593+
None,
2594+
)
2595+
if not isinstance(candidate_sp, SecurityProfileSettings):
2596+
return True
2597+
cand_profiles = candidate_sp.security_profile
2598+
if isinstance(cand_profiles, search_space.SetSpace):
2599+
return actual_security_profile in cand_profiles
2600+
if isinstance(cand_profiles, SecurityProfileType):
2601+
return cand_profiles == actual_security_profile
2602+
return True
2603+
25492604
def _is_candidate_size_valid(
25502605
self,
25512606
candidate_size: "AzureCapability",
25522607
current_vm_size: "AzureCapability",
25532608
resize_action: ResizeAction,
25542609
actual_disk_controller_type: Optional[schema.DiskControllerType],
2610+
actual_security_profile: Optional[SecurityProfileType],
25552611
) -> bool:
25562612
return (
25572613
self._compare_architecture(candidate_size, current_vm_size)
@@ -2562,6 +2618,7 @@ def _is_candidate_size_valid(
25622618
and self._check_actual_disk_controller_type(
25632619
candidate_size, actual_disk_controller_type
25642620
)
2621+
and self._compare_security_profile(candidate_size, actual_security_profile)
25652622
and self._compare_size_generation(candidate_size, current_vm_size)
25662623
and self._compare_network_interface(candidate_size, current_vm_size)
25672624
and self._compare_core_count(candidate_size, current_vm_size, resize_action)
@@ -2626,6 +2683,7 @@ def _select_vm_size(
26262683
assert current_vm_size.capability.features
26272684

26282685
actual_disk_controller_type = self._get_actual_disk_controller_type()
2686+
actual_security_profile = self._get_actual_security_profile()
26292687

26302688
# Filter candidate vm sizes that can't be resized to
26312689
avail_eligible_intersect = [
@@ -2636,6 +2694,7 @@ def _select_vm_size(
26362694
current_vm_size,
26372695
resize_action,
26382696
actual_disk_controller_type,
2697+
actual_security_profile,
26392698
)
26402699
]
26412700

0 commit comments

Comments
 (0)