Skip to content

Commit 77e780d

Browse files
Implement latest flag system for OSMorphing tools
Enables marking tools as `latest` version to skip compatibility checks while validating uniqueness per module to ensure proper tool selection. Signed-off-by: Mihaela Balutoiu <[email protected]>
1 parent 1d0bcfa commit 77e780d

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

coriolis/osmorphing/base.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ class BaseLinuxOSMorphingTools(BaseOSMorphingTools):
127127

128128
_packages = {}
129129

130+
latest = False
131+
130132
def __init__(self, conn, os_root_dir, os_root_dev, hypervisor,
131133
event_manager, detected_os_info, osmorphing_parameters,
132134
operation_timeout=None):
@@ -156,6 +158,12 @@ def _version_supported_util(cls, version, minimum, maximum=None):
156158
"Non-string version provided: %s (type %s)" % (
157159
version, type(version)))
158160

161+
if cls.latest:
162+
LOG.debug(
163+
"Skipping all version checks for latest osmorphing tool "
164+
"class: %s", cls.__name__)
165+
return True
166+
159167
float_regex = "([0-9]+(\\.[0-9]+)?)"
160168
match = re.match(float_regex, version)
161169
if not match:

coriolis/osmorphing/manager.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,27 @@ def get_osmorphing_tools_class_for_provider(
8585
"and 'osmorphing_info' %s: %s",
8686
type(provider), os_type, osmorphing_info, available_tools_cls)
8787

88+
module_classes = {}
89+
for toolscls in available_tools_cls:
90+
module_name = toolscls.__module__
91+
if module_name not in module_classes:
92+
module_classes[module_name] = []
93+
module_classes[module_name].append(toolscls)
94+
95+
for module_name, classes in module_classes.items():
96+
latest_flags = [getattr(cls, 'latest', False) for cls in classes]
97+
latest_count = sum(latest_flags)
98+
99+
if latest_count > 1:
100+
latest_classes = [
101+
cls.__name__ for cls in classes if getattr(
102+
cls, 'latest', False)]
103+
raise exception.InvalidOSMorphingTools(
104+
"Provider class '%s' returned multiple 'latest' OSMorphing "
105+
"tools from module '%s': %s. Only one class per module "
106+
"can be marked as 'latest'." % (
107+
type(provider), module_name, latest_classes))
108+
88109
osmorphing_base_class = base_osmorphing.BaseOSMorphingTools
89110
for toolscls in available_tools_cls:
90111
if not issubclass(toolscls, osmorphing_base_class):

0 commit comments

Comments
 (0)