From 6c629fb6ee587b633d8a8b16db9fdfbb0144e6ac Mon Sep 17 00:00:00 2001 From: john feng Date: Wed, 8 Jan 2025 00:39:09 -0800 Subject: [PATCH 1/6] add lpe supported image list --- .../vm_extensions/linux_patch_extension.py | 45 +++++++++++-------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/microsoft/testsuites/vm_extensions/linux_patch_extension.py b/microsoft/testsuites/vm_extensions/linux_patch_extension.py index 65eb611519..4aad310d77 100644 --- a/microsoft/testsuites/vm_extensions/linux_patch_extension.py +++ b/microsoft/testsuites/vm_extensions/linux_patch_extension.py @@ -15,7 +15,16 @@ simple_requirement, ) from lisa.base_tools.service import Service -from lisa.operating_system import BSD, SLES, CBLMariner, CentOs, Debian, Oracle, Ubuntu +from lisa.operating_system import ( + BSD, + SLES, + CBLMariner, + CentOs, + Debian, + Oracle, + Redhat, + Ubuntu, +) from lisa.sut_orchestrator import AZURE from lisa.sut_orchestrator.azure.common import ( get_compute_client, @@ -48,28 +57,26 @@ def _verify_supported_arm64_images(node: Node, log: Logger, full_version: Any) - _unsupported_image_exception_msg(node) -def _verify_unsupported_images(node: Node, full_version: Any) -> None: - # Unsupported detailed versions for x86_64 - unsupported_versions_x86_64 = { - # Major Minor Gen - SLES: ["15.5.1", "15.5.2"], - CBLMariner: ["1.0.1", "2.0.1", "2.0.2", "3.0.1"], - Debian: [ - "10.12.1", - "10.12.2", - "10.13.1", - "11.6.1", - "11.7.1", - "11.7.2", - "11.9.2", - ], +def _verify_lpe_supported_images(node: Node, log: Logger, full_version: Any) -> None: + # lpe current supported images + lpe_supported_images_versions = { + # major.minor.gen + CentOs: ["7.7.1", "7.7.2", "7.9.2"], + Oracle: ["7.9.1", "7.9.2", "8.1.1", "8.1.2", "8.2.1", "8.2.2", "8.3.1", "8.3.2", "8.4.1", "8.4.2", "8.5.1", "8.5.2", "8.9.1", "8.9.2", "8.10.1", "8.10.2", "9.0.1", "9.0.2", "9.1.1", "9.1.2", "9.4.1", "9.4.2"], + Redhat: ["7.2.1", "7.2.2", "7.3.1", "7.3.2", "7.4.1", "7.4.2", "7.5.1", "7.5.2", "7.6.1", "7.6.2","7.7.1", "7.7.2", "7.8.1", "7.8.2", "7.9.1", "7.9.2", "8.0.1", "8.0.2", "8.1.1", "8.1.2", "8.2.1", "8.2.2", "8.3.1", "8.3.2", "8.4.1", "8.4.2", "8.5.1", "8.5.2", "8.6.1", "8.6.2", "8.7.1", "8.8.1", "8.8.2", "8.9.1", "8.9.2", "8.10.1", "8.10.2", "9.0.1", "9.0.2", "9.1.1", "9.1.2", "9.2.1", "9.2.2", "9.3.1", "9.3.2", "9.4.1", "9.4.2", "9.5.1", "9.5.2"], + SLES: ["12.5.1", "12.5.2", "15.2.1", "15.2.2"], + Ubuntu: ["16.4.1", "16.4.2", "18.4.1", "18.4.2", "20.4.1", "20.4.2", "22.4.1", "22.4.2"], } - for distro in unsupported_versions_x86_64: + for distro in lpe_supported_images_versions: if isinstance(node.os, distro): - version_list = unsupported_versions_x86_64.get(distro) + version_list = lpe_supported_images_versions.get(distro) if version_list is not None and full_version in version_list: + log.debug(f"This is a supported image: {full_version}") + return + else: # Raise an exception for unsupported version + log.debug(f"This is an unsupported image: {full_version}") _unsupported_image_exception_msg(node) @@ -126,7 +133,7 @@ def _verify_supported_images_and_vm_agent(node: Node, log: Logger) -> None: if arch == "aarch64": _verify_supported_arm64_images(node, log, full_version) else: - _verify_unsupported_images(node, full_version) + _verify_lpe_supported_images(node, log, full_version) # Verify if VM agent service is running, lpe is a dependent of VM agent _verify_vm_agent_running(node, log) From 76693662ce166ba3fa0f642c04cef9ee0f1af8e2 Mon Sep 17 00:00:00 2001 From: john feng Date: Wed, 8 Jan 2025 00:46:49 -0800 Subject: [PATCH 2/6] apply lisa code format --- .../vm_extensions/linux_patch_extension.py | 99 ++++++++++++++++--- 1 file changed, 86 insertions(+), 13 deletions(-) diff --git a/microsoft/testsuites/vm_extensions/linux_patch_extension.py b/microsoft/testsuites/vm_extensions/linux_patch_extension.py index 4aad310d77..80734a566e 100644 --- a/microsoft/testsuites/vm_extensions/linux_patch_extension.py +++ b/microsoft/testsuites/vm_extensions/linux_patch_extension.py @@ -15,16 +15,7 @@ simple_requirement, ) from lisa.base_tools.service import Service -from lisa.operating_system import ( - BSD, - SLES, - CBLMariner, - CentOs, - Debian, - Oracle, - Redhat, - Ubuntu, -) +from lisa.operating_system import BSD, SLES, CentOs, Oracle, Redhat, Ubuntu from lisa.sut_orchestrator import AZURE from lisa.sut_orchestrator.azure.common import ( get_compute_client, @@ -62,10 +53,92 @@ def _verify_lpe_supported_images(node: Node, log: Logger, full_version: Any) -> lpe_supported_images_versions = { # major.minor.gen CentOs: ["7.7.1", "7.7.2", "7.9.2"], - Oracle: ["7.9.1", "7.9.2", "8.1.1", "8.1.2", "8.2.1", "8.2.2", "8.3.1", "8.3.2", "8.4.1", "8.4.2", "8.5.1", "8.5.2", "8.9.1", "8.9.2", "8.10.1", "8.10.2", "9.0.1", "9.0.2", "9.1.1", "9.1.2", "9.4.1", "9.4.2"], - Redhat: ["7.2.1", "7.2.2", "7.3.1", "7.3.2", "7.4.1", "7.4.2", "7.5.1", "7.5.2", "7.6.1", "7.6.2","7.7.1", "7.7.2", "7.8.1", "7.8.2", "7.9.1", "7.9.2", "8.0.1", "8.0.2", "8.1.1", "8.1.2", "8.2.1", "8.2.2", "8.3.1", "8.3.2", "8.4.1", "8.4.2", "8.5.1", "8.5.2", "8.6.1", "8.6.2", "8.7.1", "8.8.1", "8.8.2", "8.9.1", "8.9.2", "8.10.1", "8.10.2", "9.0.1", "9.0.2", "9.1.1", "9.1.2", "9.2.1", "9.2.2", "9.3.1", "9.3.2", "9.4.1", "9.4.2", "9.5.1", "9.5.2"], + Oracle: [ + "7.9.1", + "7.9.2", + "8.1.1", + "8.1.2", + "8.2.1", + "8.2.2", + "8.3.1", + "8.3.2", + "8.4.1", + "8.4.2", + "8.5.1", + "8.5.2", + "8.9.1", + "8.9.2", + "8.10.1", + "8.10.2", + "9.0.1", + "9.0.2", + "9.1.1", + "9.1.2", + "9.4.1", + "9.4.2", + ], + Redhat: [ + "7.2.1", + "7.2.2", + "7.3.1", + "7.3.2", + "7.4.1", + "7.4.2", + "7.5.1", + "7.5.2", + "7.6.1", + "7.6.2", + "7.7.1", + "7.7.2", + "7.8.1", + "7.8.2", + "7.9.1", + "7.9.2", + "8.0.1", + "8.0.2", + "8.1.1", + "8.1.2", + "8.2.1", + "8.2.2", + "8.3.1", + "8.3.2", + "8.4.1", + "8.4.2", + "8.5.1", + "8.5.2", + "8.6.1", + "8.6.2", + "8.7.1", + "8.8.1", + "8.8.2", + "8.9.1", + "8.9.2", + "8.10.1", + "8.10.2", + "9.0.1", + "9.0.2", + "9.1.1", + "9.1.2", + "9.2.1", + "9.2.2", + "9.3.1", + "9.3.2", + "9.4.1", + "9.4.2", + "9.5.1", + "9.5.2", + ], SLES: ["12.5.1", "12.5.2", "15.2.1", "15.2.2"], - Ubuntu: ["16.4.1", "16.4.2", "18.4.1", "18.4.2", "20.4.1", "20.4.2", "22.4.1", "22.4.2"], + Ubuntu: [ + "16.4.1", + "16.4.2", + "18.4.1", + "18.4.2", + "20.4.1", + "20.4.2", + "22.4.1", + "22.4.2", + ], } for distro in lpe_supported_images_versions: From 61469b94df3a3c9d43bf63de797f8690e103f064 Mon Sep 17 00:00:00 2001 From: john feng Date: Wed, 8 Jan 2025 22:05:12 -0800 Subject: [PATCH 3/6] use range to shorten the image list --- .../vm_extensions/linux_patch_extension.py | 91 ++++--------------- 1 file changed, 20 insertions(+), 71 deletions(-) diff --git a/microsoft/testsuites/vm_extensions/linux_patch_extension.py b/microsoft/testsuites/vm_extensions/linux_patch_extension.py index 80734a566e..041aac2aaa 100644 --- a/microsoft/testsuites/vm_extensions/linux_patch_extension.py +++ b/microsoft/testsuites/vm_extensions/linux_patch_extension.py @@ -54,79 +54,22 @@ def _verify_lpe_supported_images(node: Node, log: Logger, full_version: Any) -> # major.minor.gen CentOs: ["7.7.1", "7.7.2", "7.9.2"], Oracle: [ - "7.9.1", - "7.9.2", - "8.1.1", - "8.1.2", - "8.2.1", - "8.2.2", - "8.3.1", - "8.3.2", - "8.4.1", - "8.4.2", - "8.5.1", - "8.5.2", - "8.9.1", - "8.9.2", - "8.10.1", - "8.10.2", - "9.0.1", - "9.0.2", - "9.1.1", - "9.1.2", - "9.4.1", - "9.4.2", + f"{major}.{minor}.{gen}" + for major in range(7, 10) # major 7-9 + for minor in range(0, 10) # minor 0-9 + for gen in range(1, 3) # gen 1 and 2 + if not (major == 7 and minor < 9) # skip 7.x.x for minor < 9 + and not ( + major == 8 and minor not in [1, 2, 3, 4, 5, 9, 10] + ) # skip 8.6.x, 8.7.x, 8.8.x + and not (major == 9 and minor not in [0, 1, 4]) # skip 9.2.x, 9.3.x ], Redhat: [ - "7.2.1", - "7.2.2", - "7.3.1", - "7.3.2", - "7.4.1", - "7.4.2", - "7.5.1", - "7.5.2", - "7.6.1", - "7.6.2", - "7.7.1", - "7.7.2", - "7.8.1", - "7.8.2", - "7.9.1", - "7.9.2", - "8.0.1", - "8.0.2", - "8.1.1", - "8.1.2", - "8.2.1", - "8.2.2", - "8.3.1", - "8.3.2", - "8.4.1", - "8.4.2", - "8.5.1", - "8.5.2", - "8.6.1", - "8.6.2", - "8.7.1", - "8.8.1", - "8.8.2", - "8.9.1", - "8.9.2", - "8.10.1", - "8.10.2", - "9.0.1", - "9.0.2", - "9.1.1", - "9.1.2", - "9.2.1", - "9.2.2", - "9.3.1", - "9.3.2", - "9.4.1", - "9.4.2", - "9.5.1", - "9.5.2", + f"{major}.{minor}.{gen}" + for major in range(7, 10) # major 7-9 + for minor in range(0, 10) # minor 0-9 + for gen in range(1, 3) # gen 1 and 2 + if not (major == 7 and minor < 2) # skip 7.0.x, 7.1.x ], SLES: ["12.5.1", "12.5.2", "15.2.1", "15.2.2"], Ubuntu: [ @@ -141,6 +84,12 @@ def _verify_lpe_supported_images(node: Node, log: Logger, full_version: Any) -> ], } + # check if image is not supported, raise an exception + if not any(isinstance(node.os, distro) for distro in lpe_supported_images_versions): + # Raise an exception for unsupported distro + log.debug(f"This is an unsupported image: {full_version}") + _unsupported_image_exception_msg(node) + for distro in lpe_supported_images_versions: if isinstance(node.os, distro): version_list = lpe_supported_images_versions.get(distro) From 98a3c71926f53f7aca2befcb501b002b7b948724 Mon Sep 17 00:00:00 2001 From: john feng Date: Fri, 10 Jan 2025 13:15:41 -0800 Subject: [PATCH 4/6] use parse_version for image validation --- .../vm_extensions/linux_patch_extension.py | 60 ++++++++++--------- 1 file changed, 32 insertions(+), 28 deletions(-) diff --git a/microsoft/testsuites/vm_extensions/linux_patch_extension.py b/microsoft/testsuites/vm_extensions/linux_patch_extension.py index 041aac2aaa..60050099e5 100644 --- a/microsoft/testsuites/vm_extensions/linux_patch_extension.py +++ b/microsoft/testsuites/vm_extensions/linux_patch_extension.py @@ -24,7 +24,7 @@ ) from lisa.sut_orchestrator.azure.platform_ import AzurePlatform from lisa.sut_orchestrator.azure.tools import VmGeneration -from lisa.util import SkippedException, UnsupportedDistroException +from lisa.util import SkippedException, UnsupportedDistroException, parse_version def _verify_supported_arm64_images(node: Node, log: Logger, full_version: Any) -> None: @@ -53,24 +53,6 @@ def _verify_lpe_supported_images(node: Node, log: Logger, full_version: Any) -> lpe_supported_images_versions = { # major.minor.gen CentOs: ["7.7.1", "7.7.2", "7.9.2"], - Oracle: [ - f"{major}.{minor}.{gen}" - for major in range(7, 10) # major 7-9 - for minor in range(0, 10) # minor 0-9 - for gen in range(1, 3) # gen 1 and 2 - if not (major == 7 and minor < 9) # skip 7.x.x for minor < 9 - and not ( - major == 8 and minor not in [1, 2, 3, 4, 5, 9, 10] - ) # skip 8.6.x, 8.7.x, 8.8.x - and not (major == 9 and minor not in [0, 1, 4]) # skip 9.2.x, 9.3.x - ], - Redhat: [ - f"{major}.{minor}.{gen}" - for major in range(7, 10) # major 7-9 - for minor in range(0, 10) # minor 0-9 - for gen in range(1, 3) # gen 1 and 2 - if not (major == 7 and minor < 2) # skip 7.0.x, 7.1.x - ], SLES: ["12.5.1", "12.5.2", "15.2.1", "15.2.2"], Ubuntu: [ "16.4.1", @@ -84,22 +66,44 @@ def _verify_lpe_supported_images(node: Node, log: Logger, full_version: Any) -> ], } - # check if image is not supported, raise an exception - if not any(isinstance(node.os, distro) for distro in lpe_supported_images_versions): - # Raise an exception for unsupported distro - log.debug(f"This is an unsupported image: {full_version}") - _unsupported_image_exception_msg(node) + # check for supported Redhat image versions [7.2.1 -> 9.5.2] + if ( + isinstance(node.os, Redhat) + and full_version >= parse_version("7.2.1") + and full_version <= parse_version("9.5.2") + ): + log.debug(f"This is a supported image: {full_version}") + return + + # check for supported Oracle image versions [7.9.1-> 8.5.2] [8.9.1 -> 9.1.2] [9.4.1 -> 9.4.2] + if isinstance(node.os, Oracle) and ( + ( + full_version >= parse_version("7.9.1") + and full_version <= parse_version("8.5.2") + ) + or ( + full_version >= parse_version("8.9.1") + and full_version <= parse_version("9.1.2") + ) + or ( + full_version >= parse_version("9.4.1") + and full_version <= parse_version("9.4.2") + ) + ): + log.debug(f"This is a supported image: {full_version}") + return + # check for other supported image versions for distro in lpe_supported_images_versions: if isinstance(node.os, distro): version_list = lpe_supported_images_versions.get(distro) if version_list is not None and full_version in version_list: log.debug(f"This is a supported image: {full_version}") return - else: - # Raise an exception for unsupported version - log.debug(f"This is an unsupported image: {full_version}") - _unsupported_image_exception_msg(node) + else: + # Raise an exception for unsupported image version + log.debug(f"This is an unsupported image: {full_version}") + _unsupported_image_exception_msg(node) def _verify_unsupported_vm_agent( From 938d58d967554142ba43346adb431ffb562c127b Mon Sep 17 00:00:00 2001 From: john feng Date: Fri, 10 Jan 2025 17:02:38 -0800 Subject: [PATCH 5/6] reformat line character to under 88 --- microsoft/testsuites/vm_extensions/linux_patch_extension.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/microsoft/testsuites/vm_extensions/linux_patch_extension.py b/microsoft/testsuites/vm_extensions/linux_patch_extension.py index 60050099e5..88489ef628 100644 --- a/microsoft/testsuites/vm_extensions/linux_patch_extension.py +++ b/microsoft/testsuites/vm_extensions/linux_patch_extension.py @@ -75,7 +75,8 @@ def _verify_lpe_supported_images(node: Node, log: Logger, full_version: Any) -> log.debug(f"This is a supported image: {full_version}") return - # check for supported Oracle image versions [7.9.1-> 8.5.2] [8.9.1 -> 9.1.2] [9.4.1 -> 9.4.2] + # check for supported Oracle image versions [7.9.1-> 8.5.2] + # [8.9.1 -> 9.1.2] [9.4.1 -> 9.4.2] if isinstance(node.os, Oracle) and ( ( full_version >= parse_version("7.9.1") @@ -246,7 +247,8 @@ def _unsupported_image_exception_msg(node: Node) -> None: def _assert_assessment_patch( - node: Node, log: Logger, compute_client: Any, resource_group_name: Any, vm_name: Any + node: Node, log: Logger, compute_client: Any, + resource_group_name: Any, vm_name: Any ) -> None: try: log.debug("Initiate the API call for the assessment patches.") From 944352b95924267b404bc43ff7370180be41e9f0 Mon Sep 17 00:00:00 2001 From: john feng Date: Sun, 12 Jan 2025 11:39:29 -0800 Subject: [PATCH 6/6] fix the logic in _verify_lpe_supported_images and refactor the code --- .../vm_extensions/linux_patch_extension.py | 40 +++++++++---------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/microsoft/testsuites/vm_extensions/linux_patch_extension.py b/microsoft/testsuites/vm_extensions/linux_patch_extension.py index 88489ef628..e5cfa57201 100644 --- a/microsoft/testsuites/vm_extensions/linux_patch_extension.py +++ b/microsoft/testsuites/vm_extensions/linux_patch_extension.py @@ -36,16 +36,8 @@ def _verify_supported_arm64_images(node: Node, log: Logger, full_version: Any) - Ubuntu: ["20.4.2"], } - for distro in supported_versions_arm64: - if isinstance(node.os, distro): - version_list = supported_versions_arm64.get(distro) - if version_list is not None and full_version in version_list: - log.debug(f"supported arm64 os: {full_version}") - return - else: - # Raise an exception for unsupported version - log.debug(f"unsupported arm64 os: {full_version}") - _unsupported_image_exception_msg(node) + # check for other supported image versions + _validate_supported_distro(node, log, full_version, supported_versions_arm64) def _verify_lpe_supported_images(node: Node, log: Logger, full_version: Any) -> None: @@ -95,16 +87,21 @@ def _verify_lpe_supported_images(node: Node, log: Logger, full_version: Any) -> return # check for other supported image versions - for distro in lpe_supported_images_versions: - if isinstance(node.os, distro): - version_list = lpe_supported_images_versions.get(distro) - if version_list is not None and full_version in version_list: - log.debug(f"This is a supported image: {full_version}") - return - else: - # Raise an exception for unsupported image version - log.debug(f"This is an unsupported image: {full_version}") - _unsupported_image_exception_msg(node) + _validate_supported_distro(node, log, full_version, lpe_supported_images_versions) + + +def _validate_supported_distro( + node: Node, log: Logger, full_version: Any, supported_distro_list: Any +) -> None: + # check for other supported image versions + for distro, version_list in supported_distro_list.items(): + if isinstance(node.os, distro) and full_version in version_list: + log.debug(f"This is a supported image: {full_version}") + return + + # Raise an exception for unsupported image versions + log.debug(f"This is an unsupported image: {full_version}") + _unsupported_image_exception_msg(node) def _verify_unsupported_vm_agent( @@ -247,8 +244,7 @@ def _unsupported_image_exception_msg(node: Node) -> None: def _assert_assessment_patch( - node: Node, log: Logger, compute_client: Any, - resource_group_name: Any, vm_name: Any + node: Node, log: Logger, compute_client: Any, resource_group_name: Any, vm_name: Any ) -> None: try: log.debug("Initiate the API call for the assessment patches.")