From ae3e43e02e9dfd3433cedc77d629836f2d28c4ec Mon Sep 17 00:00:00 2001 From: Lili Deng Date: Wed, 20 Nov 2024 13:54:14 +0800 Subject: [PATCH] Check and uninstall extensions before installing it --- .../runtime_extensions/custom_script.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/microsoft/testsuites/vm_extensions/runtime_extensions/custom_script.py b/microsoft/testsuites/vm_extensions/runtime_extensions/custom_script.py index 9cb52117e6..f00d4045e4 100644 --- a/microsoft/testsuites/vm_extensions/runtime_extensions/custom_script.py +++ b/microsoft/testsuites/vm_extensions/runtime_extensions/custom_script.py @@ -21,6 +21,7 @@ from lisa.sut_orchestrator import AZURE from lisa.sut_orchestrator.azure.features import AzureExtension from lisa.sut_orchestrator.azure.tools import Waagent +from lisa.util import LisaException from microsoft.testsuites.vm_extensions.runtime_extensions.common import ( check_waagent_version_supported, execute_command, @@ -38,10 +39,22 @@ def _create_and_verify_extension_run( assert_exception: Any = None, ) -> None: extension = node.features[AzureExtension] + extension_name = "CustomScript" + try: + # Delete VM Extension if already present + extension.delete(extension_name) + except HttpResponseError as identifier: + if any(s in str(identifier) for s in ["was not found"]): + node.log.info(f"{extension_name} is not installed") + else: + raise LisaException( + f"unexpected exception happened {identifier} during delete" + f" extension {extension_name}" + ) from identifier def enable_extension() -> Any: result = extension.create_or_update( - name="CustomScript", + name=extension_name, publisher="Microsoft.Azure.Extensions", type_="CustomScript", type_handler_version="2.1",