-
Notifications
You must be signed in to change notification settings - Fork 11
Fix the version comparator bug for ubuntu pro client version extraction #294
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
kjohn-msft
merged 10 commits into
master
from
hotfix/version_comparator_ubuntupro_version
Mar 14, 2025
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
89c5e1a
fix the version comparator for ubuntu pro client version extraction
feng-j678 c842069
fix the version comparator logic
feng-j678 66b29f4
update extraction method for ubuntuproclient
feng-j678 134e65c
add unit test for mock pro client version
feng-j678 324705a
use basepath() to extract last part of lpe path with version
feng-j678 86eddf9
Merge branch 'master' of https://github.com/Azure/LinuxPatchExtension…
feng-j678 2f28261
use constant for linuxpatchextenstion
feng-j678 b68f39d
change MAX_OS_MAJOR_VERSION_SUPPORTED to 20
feng-j678 3b411bf
Version Comparator Comments as Code on PR Branch (#296)
kjohn-msft a722262
remove linuxpatchextension constants and os version comments in handler
feng-j678 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -382,4 +382,3 @@ class BufferMessage(EnumBackport): | |
TRUE = 0 | ||
FALSE = 1 | ||
FLUSH = 2 | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
# Copyright 2024 Microsoft Corporation | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
# Requires Python 2.7+ | ||
import os.path | ||
import re | ||
|
||
|
||
class ExtVersionComparator(object): | ||
|
||
def sort_ext_paths_desc_order(self, ext_paths_with_versions): | ||
# type (list[str]) -> list[str] | ||
""" | ||
Sort paths based on version numbers extracted from paths. | ||
Lpe input: | ||
["/var/lib/waagent/Microsoft.CPlat.Core.LinuxPatchExtension-1.21.1001", | ||
"/var/lib/waagent/Microsoft.CPlat.Core.LinuxPatchExtension-1.6.100", | ||
"/var/lib/waagent/Microsoft.CPlat.Core.LinuxPatchExtension-1.21.100"] | ||
Return: | ||
["/var/lib/waagent/Microsoft.CPlat.Core.LinuxPatchExtension-1.21.1001", | ||
"/var/lib/waagent/Microsoft.CPlat.Core.LinuxPatchExtension-1.21.100", | ||
"/var/lib/waagent/Microsoft.CPlat.Core.LinuxPatchExtension-1.6.100"] | ||
""" | ||
|
||
return sorted(ext_paths_with_versions, key=self.__version_key, reverse=True) | ||
|
||
@staticmethod | ||
def __extract_lpe_path_version_num(lpe_path): | ||
# type (str) -> str | ||
""" | ||
Extract the version part from a given lpe path. | ||
Input Extracted Version | ||
/var/lib/waagent/Microsoft.CPlat.Core.LinuxPatchExtension-1.2.25 "1.2.25" | ||
/var/lib/waagent/Microsoft.CPlat.Core.LinuxPatchExtension-1.2.250 "1.2.250" | ||
/var/lib/waagent/Microsoft.CPlat.Core.LinuxPatchExtension-1.21.2501 "1.21.2501" | ||
/var/lib/waagent/Microsoft.CPlat.Core.LinuxPatchExtension-1.2.25. "1.2.25" | ||
/var/lib/waagent/Microsoft.CPlat.Core.LinuxPatchExtension-1.2.25.. "1.2.25" | ||
/var/lib/waagent/Microsoft.CPlat.Core.LinuxPatchExtension-1.2.25abc "1.2.25" | ||
/var/lib/waagent/Microsoft.CPlat.Core.LinuxPatchExtension-1.2.25.abc "1.2.25" | ||
/var/lib/waagent/Microsoft.CPlat.Core.LinuxPatchExtension-1.2.25+abc.123 "1.2.25" | ||
/var/lib/waagent/Microsoft.CPlat.Core.LinuxPatchExtension-1.2.25-abc+def.123 "1.2.25" | ||
/var/lib/waagent/Microsoft.CPlat.Core.LinuxPatchExtension-a.b.c "" | ||
""" | ||
|
||
lpe_filename = os.path.basename(lpe_path) # Microsoft.CPlat.Core.LinuxPatchExtension-x.x.xx | ||
lpe_version = re.search(r'(\d+(?:\.\d+)*)', lpe_filename) # extract numbers with optional dot-separated parts | ||
return lpe_version.group(1).rstrip('.') if lpe_version else "" | ||
|
||
def __version_key(self, version_input): | ||
# type (str) -> (int) | ||
""" Extract version number from input and return int tuple. | ||
Input: "/var/lib/waagent/Microsoft.CPlat.Core.LinuxPatchExtension-1.6.100" | ||
Return: (1.6.100) | ||
""" | ||
|
||
version_numbers = self.__extract_lpe_path_version_num(lpe_path=version_input) | ||
return tuple(map(int, version_numbers.split('.'))) if version_numbers else (0, 0, 0) |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.