Skip to content

Commit

Permalink
Fix untyped feature settings
Browse files Browse the repository at this point in the history
The feature settings should be reloaded to the right types, instead of
general type during prepare an environment in ready platform. So the
capability can be configured for ready platform.
  • Loading branch information
squirrelsc authored and LiliDeng committed Sep 29, 2024
1 parent aec6ebf commit 96ff777
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 26 deletions.
32 changes: 31 additions & 1 deletion lisa/feature.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@
Any,
Dict,
Iterable,
List,
Optional,
Type,
TypeVar,
Union,
cast,
)

from lisa import schema
from lisa import schema, search_space
from lisa.util import (
InitializableMixin,
LisaException,
Expand Down Expand Up @@ -188,3 +189,32 @@ def get_feature_settings_by_name(
)

return None


def reload_platform_features(
node_space: schema.NodeSpace, platform_features: List[Type[Feature]]
) -> None:
# no features, no need to reload
if not node_space or not node_space.features:
return

new_settings = search_space.SetSpace[schema.FeatureSettings](is_allow_set=True)

for current_settings in node_space.features.items:
# reload to type specified settings
try:
settings_type = get_feature_settings_type_by_name(
current_settings.type, platform_features
)
except NotMeetRequirementException as identifier:
raise LisaException(f"platform doesn't support all features. {identifier}")
new_setting = schema.load_by_type(settings_type, current_settings)
existing_setting = get_feature_settings_by_name(
new_setting.type, new_settings, True
)
if existing_setting:
new_settings.remove(existing_setting)
new_setting = existing_setting.intersect(new_setting)

new_settings.add(new_setting)
node_space.features = new_settings
26 changes: 2 additions & 24 deletions lisa/sut_orchestrator/azure/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@
from lisa.util import (
LisaException,
LisaTimeoutException,
NotMeetRequirementException,
check_till_timeout,
constants,
field_metadata,
Expand Down Expand Up @@ -3098,31 +3097,10 @@ def convert_to_azure_node_space(node_space: schema.NodeSpace) -> None:
if not node_space:
return

if node_space.features:
new_settings = search_space.SetSpace[schema.FeatureSettings](is_allow_set=True)

for current_settings in node_space.features.items:
# reload to type specified settings
try:
from .platform_ import AzurePlatform
from .platform_ import AzurePlatform

settings_type = feature.get_feature_settings_type_by_name(
current_settings.type, AzurePlatform.supported_features()
)
except NotMeetRequirementException as identifier:
raise LisaException(
f"platform doesn't support all features. {identifier}"
)
new_setting = schema.load_by_type(settings_type, current_settings)
existing_setting = feature.get_feature_settings_by_name(
new_setting.type, new_settings, True
)
if existing_setting:
new_settings.remove(existing_setting)
new_setting = existing_setting.intersect(new_setting)
feature.reload_platform_features(node_space, AzurePlatform.supported_features())

new_settings.add(new_setting)
node_space.features = new_settings
if node_space.disk:
from . import features

Expand Down
5 changes: 4 additions & 1 deletion lisa/sut_orchestrator/ready.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from typing import List, Type

from lisa import features
from lisa import feature, features
from lisa.environment import Environment
from lisa.feature import Feature
from lisa.platform_ import Platform
Expand All @@ -30,6 +30,7 @@ def supported_features(cls) -> List[Type[Feature]]:
features.Hibernation,
features.IsolatedResource,
features.Nfs,
features.SecurityProfile,
]

def _prepare_environment(self, environment: Environment, log: Logger) -> bool:
Expand All @@ -49,6 +50,8 @@ def _prepare_environment(self, environment: Environment, log: Logger) -> bool:
node.capability.disk = DiskOptionSettings()
if node.capability.network_interface is None:
node.capability.network_interface = NetworkInterfaceOptionSettings()
# Reload features to right types
feature.reload_platform_features(node.capability, self.supported_features())

if len(environment.nodes):
# if it has nodes, it's a good environment to run test cases
Expand Down

0 comments on commit 96ff777

Please sign in to comment.