Skip to content
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

add assess_patch test #3217

Merged
merged 11 commits into from
Mar 25, 2024
97 changes: 97 additions & 0 deletions microsoft/testsuites/vm_extensions/linux_patch_extension.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# Copyright (c) Microsoft Corporation. Licensed under the MIT license.

from typing import Any

from assertpy.assertpy import assert_that

from lisa import (
Environment,
Logger,
Node,
TestCaseMetadata,
TestSuite,
TestSuiteMetadata,
simple_requirement,
)
from lisa.base_tools.service import Service
from lisa.operating_system import BSD
from lisa.sut_orchestrator import AZURE
from lisa.sut_orchestrator.azure.common import (
get_compute_client,
get_node_context,
wait_operation,
)
from lisa.sut_orchestrator.azure.platform_ import AzurePlatform


def _set_up_vm(node: Node, environment: Environment) -> Any:
assert environment.platform, "platform shouldn't be None."
platform: AzurePlatform = environment.platform # type: ignore
assert isinstance(
platform, AzurePlatform
), "platform should be AzurePlatform instance"
assert isinstance(
platform, AzurePlatform
), "platform should be AzurePlatform instance"
compute_client = get_compute_client(platform)
node_context = get_node_context(node)
resource_group_name = node_context.resource_group_name
vm_name = node_context.vm_name

return compute_client, resource_group_name, vm_name


def _verify_vm_agent_running(node: Node, log: Logger) -> None:
service = node.tools[Service]
is_vm_agent_running = service.is_service_running(
"walinuxagent"
) or service.is_service_running("waagent")

log.debug(f"verify walinuxagent or waagent running:{is_vm_agent_running}")
LiliDeng marked this conversation as resolved.
Show resolved Hide resolved

assert_that(is_vm_agent_running).described_as(
"Expected walinuxagent or waagent service is running"
).is_true()


@TestSuiteMetadata(
area="vm_extension",
category="functional",
description="Test for Linux Patch Extension",
requirement=simple_requirement(
supported_platform_type=[AZURE], unsupported_os=[BSD]
),
)
class LinuxPatchExtensionBVT(TestSuite):
@TestCaseMetadata(
description="""
Verify walinuxagent or waagent service is running on vm. Perform assess
patches to trigger Microsoft.CPlat.Core.LinuxPatchExtension creation in
vm. Verify status file response for validity.
""",
priority=1,
)
def verify_vm_assess_patches(
self, node: Node, environment: Environment, log: Logger
) -> None:
compute_client, resource_group_name, vm_name = _set_up_vm(node, environment)

# verify vm agent service is running, lpe is a dependent of vm agent
# service
_verify_vm_agent_running(node, log)

operation = compute_client.virtual_machines.begin_assess_patches(
resource_group_name=resource_group_name, vm_name=vm_name
)
# set wait operation timeout 10 min, status file should be generated
# before timeout
assess_result = wait_operation(operation, 600)

assert assess_result, "assess_result shouldn't be None"
assert_that(assess_result["status"]).described_as(
"Expected the assess patches to succeed"
).is_equal_to("Succeeded")

assert_that(assess_result["error"]["code"]).described_as(
"Expected no error in assess patches operation"
).is_equal_to("0")
Loading