diff --git a/lisa/sut_orchestrator/azure/features.py b/lisa/sut_orchestrator/azure/features.py index db8646edef..fe750e7d73 100644 --- a/lisa/sut_orchestrator/azure/features.py +++ b/lisa/sut_orchestrator/azure/features.py @@ -2431,7 +2431,7 @@ def create_setting( return availability_settings @classmethod - def on_before_deployment(cls, *args: Any, **kwargs: Any) -> None: + def on_before_deployment(cls, *args: Any, **kwargs: Any) -> None: # noqa: C901 environment = cast(Environment, kwargs.get("environment")) arm_parameters = cast(AzureArmParameter, kwargs.get("arm_parameters")) settings = cast(AvailabilitySettings, kwargs.get("settings")) @@ -2477,11 +2477,12 @@ def on_before_deployment(cls, *args: Any, **kwargs: Any) -> None: for zone in params.availability_zones if zone in settings.availability_zones ] - assert params.availability_zones, ( - "Invalid zones provided. " - "This SKU in this location supports zones: " - f"{settings.availability_zones}. " - ) + if not params.availability_zones: + raise SkippedException( + "Invalid zones provided. " + "This SKU in this location supports zones: " + f"{settings.availability_zones}. " + ) elif settings.availability_zones: params.availability_zones = [settings.availability_zones.items[0]] @@ -2489,15 +2490,16 @@ def on_before_deployment(cls, *args: Any, **kwargs: Any) -> None: type.value for type in AvailabilityType ], ("Not a valid Availability Type: " f"{params.availability_type}") - assert ( + if not ( AvailabilityType(params.availability_type) in settings.availability_type - ), ( - f"Availability Type " - f"'{params.availability_type}' " - "is not supported in the current configuration. Please select one of " - f"{[type.value for type in settings.availability_type.items]}. " - "Or consider changing the disk type or location." - ) + ): + raise SkippedException( + f"Availability Type " + f"'{params.availability_type}' " + "is not supported in the current configuration. Please select one of " + f"{[type.value for type in settings.availability_type.items]}. " + "Or consider changing the disk type or location." + ) # If the availability_type is still set to Default, then # resolve the default without considering capabilities @@ -2517,9 +2519,14 @@ def on_before_deployment(cls, *args: Any, **kwargs: Any) -> None: if "platformUpdateDomainCount" not in params.availability_set_properties: params.availability_set_properties["platformUpdateDomainCount"] = 1 elif params.availability_type == AvailabilityType.AvailabilityZone: - assert ( - params.availability_zones - ), "Availability Zone is selected, but no zone was provided." + if not params.availability_zones: + raise SkippedException( + "Availability Zone is selected, but no zone was provided. " + "Please consider one of the following\n" + "1. Providing availability_zones in the runbook\n" + "2. Selecting a different availability_type in the runbook\n" + "3. Setting maximize_capability to false so the zone can be selected automatically." + ) params.availability_zones = [params.availability_zones[0]] params.availability_set_tags.clear() params.availability_set_properties.clear()