Skip to content

Commit

Permalink
handle when extension has been installed situation
Browse files Browse the repository at this point in the history
  • Loading branch information
LiliDeng committed Sep 20, 2024
1 parent 406a649 commit aa49221
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 35 deletions.
17 changes: 11 additions & 6 deletions microsoft/testsuites/vm_extensions/AzureMonitorAgentLinux.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ def verify_azuremonitoragent_linux(self, log: Logger, node: Node) -> None:

try:
# Delete VM Extension if already present
extension.delete("AzureMonitorLinuxAgent")
extension.delete("Microsoft.Azure.Monitor.AzureMonitorLinuxAgent")
is_extension_present = True
except HttpResponseError as identifier:
if any(s in str(identifier) for s in ["was not found"]):
log.info("AzureMonitorLinuxAgent is not already installed")
Expand All @@ -72,12 +73,16 @@ def verify_azuremonitoragent_linux(self, log: Logger, node: Node) -> None:
"Expected the extension to succeed"
).is_equal_to("Succeeded")

# Delete VM Extension
extension.delete("AzureMonitorLinuxAgent")
if not is_extension_present:
# if extension installed by test then delete the extension
extension.delete("Microsoft.Azure.Monitor.AzureMonitorLinuxAgent")

assert_that(extension.check_exist("AzureMonitorLinuxAgent")).described_as(
"Found the VM Extension still unexpectedly exists on the VM after deletion"
).is_false()
assert_that(
extension.check_exist("Microsoft.Azure.Monitor.AzureMonitorLinuxAgent")
).described_as(
"Found the VM Extension still unexpectedly exists on the VM"
" after deletion"
).is_false()

def _is_supported_linux_distro(self, node: Node) -> bool:
supported_major_versions_x86_64 = {
Expand Down
82 changes: 53 additions & 29 deletions microsoft/testsuites/vm_extensions/azsecpack.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@
from lisa.sut_orchestrator.azure.tools import Azsecd
from lisa.testsuite import TestResult
from lisa.tools import Journalctl, Service
from lisa.util import LisaException, SkippedException, UnsupportedDistroException
from lisa.util import (
LisaException,
SkippedException,
UnsupportedDistroException,
check_till_timeout,
)


@TestSuiteMetadata(
Expand Down Expand Up @@ -161,25 +166,36 @@ def _install_monitor_agent_extension(self, node: Node) -> None:
# This test uses autoconfig, the settings should be {"GCS_AUTO_CONFIG":true}
settings = {"GCS_AUTO_CONFIG": True}
extension = node.features[AzureExtension]
result = extension.create_or_update(
name="AzureMonitorLinuxAgent",
publisher="Microsoft.Azure.Monitor",
type_="AzureMonitorLinuxAgent",
type_handler_version="1.0",
auto_upgrade_minor_version=True,
enable_automatic_upgrade=True,
settings=settings,
)
assert_that(result["provisioning_state"]).described_as(
"Expected the extension to succeed"
).is_equal_to("Succeeded")
try:
result = extension.create_or_update(
name="AzureMonitorLinuxAgent",
publisher="Microsoft.Azure.Monitor",
type_="AzureMonitorLinuxAgent",
type_handler_version="1.0",
auto_upgrade_minor_version=True,
enable_automatic_upgrade=True,
settings=settings,
)
assert_that(result["provisioning_state"]).described_as(
"Expected the extension to succeed"
).is_equal_to("Succeeded")
except HttpResponseError as identifier:
if "already added" in str(identifier):
node.log.debug(
"AzureMonitorLinuxAgent has been installed in current VM."
)
result = extension.get("Microsoft.Azure.Monitor.AzureMonitorLinuxAgent")
node.log.debug(f"extension status {result.provisioning_state}")
else:
raise identifier

# After Azure Monitor Linux Agent extension is installed, the package
# azuremonitoragent should be installed.
posix_os: Posix = cast(Posix, node.os)
assert_that(posix_os.package_exists("azuremonitoragent")).described_as(
"Expected the azuremonitoragent package to be installed"
).is_equal_to(True)
check_till_timeout(
lambda: posix_os.package_exists("azuremonitoragent") is True,
timeout_message="Expected the azuremonitoragent package to be installed",
)

def _install_security_agent_extension(self, node: Node, log: Logger) -> None:
# Install AzureSecurityLinuxAgent VM extension
Expand All @@ -188,26 +204,34 @@ def _install_security_agent_extension(self, node: Node, log: Logger) -> None:
"enableAutoConfig": True,
}
extension = node.features[AzureExtension]
result = extension.create_or_update(
name="AzureSecurityLinuxAgent",
publisher="Microsoft.Azure.Security.Monitoring",
type_="AzureSecurityLinuxAgent",
type_handler_version="2.0",
auto_upgrade_minor_version=True,
enable_automatic_upgrade=True,
settings=azsec_settings,
)
assert_that(result["provisioning_state"]).described_as(
"Expected the extension to succeed"
).is_equal_to("Succeeded")
try:
result = extension.create_or_update(
name="AzureSecurityLinuxAgent",
publisher="Microsoft.Azure.Security.Monitoring",
type_="AzureSecurityLinuxAgent",
type_handler_version="2.0",
auto_upgrade_minor_version=True,
enable_automatic_upgrade=True,
settings=azsec_settings,
)
assert_that(result["provisioning_state"]).described_as(
"Expected the extension to succeed"
).is_equal_to("Succeeded")
except HttpResponseError as identifier:
if "already added" in str(identifier):
node.log.debug(
"AzureSecurityLinuxAgent has been installed in current VM."
)
else:
raise identifier

# Check azure-security, azsec-monitor, azsec-clamav, auoms are installed
# After installing extension, some packages might not be installed completely.
# So add a loop to check if all packages are installed.
posix_os: Posix = cast(Posix, node.os)
azsec_packages = ["azure-security", "azsec-monitor", "azsec-clamav", "auoms"]
loop_count = 0
while loop_count < 10:
while loop_count < 30:
result = True
for package in azsec_packages:
result = posix_os.package_exists(package) and result
Expand Down

0 comments on commit aa49221

Please sign in to comment.