Skip to content

Commit

Permalink
Johnf/modify assert status logic (#3382)
Browse files Browse the repository at this point in the history
* add mariner1 to unsupported list

* modify assert logic to check for any error

* refactor unspported msg

* remove duplicate platform assertion

* use Any instead of list for status_file
  • Loading branch information
feng-j678 authored Aug 16, 2024
1 parent bd03361 commit 14bdcb8
Showing 1 changed file with 37 additions and 22 deletions.
59 changes: 37 additions & 22 deletions microsoft/testsuites/vm_extensions/linux_patch_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,23 +54,20 @@ def _verify_unsupported_images(node: Node) -> None:
def _verify_unsupported_vm_agent(
node: Node, status_result: Any, error_code: str
) -> None:
if (
error_code == "1"
and "Unsupported older Azure Linux Agent version"
in status_result["error"]["details"][0]["message"]
unsupported_agent_msg = "Unsupported older Azure Linux Agent version"
if error_code == "1" and any(
unsupported_agent_msg in details["message"]
for details in status_result["error"]["details"]
if "message" in details
):
_unsupported_image_exception_msg(node)


def _set_up_vm(node: Node, environment: Environment) -> Any:
platform_msg = "platform should be AzurePlatform instance"
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"
assert isinstance(platform, AzurePlatform), platform_msg
compute_client = get_compute_client(platform)
node_context = get_node_context(node)
resource_group_name = node_context.resource_group_name
Expand Down Expand Up @@ -99,25 +96,36 @@ def _verify_vm_agent_running(node: Node, log: Logger) -> None:
def _assert_status_file_result(
node: Node, status_file: Any, error_code: str, api_type: Optional[str] = None
) -> None:
expected_succeeded_status_msg = "Expected the status file status to be Succeeded"
expected_warning_status_msg = (
"Expected the status file status to be CompletedWithWarnings"
)
error_details_not_empty = len(status_file["error"]["details"]) > 0
truncated_package_code = (
_verify_details_code(status_file, "PACKAGE_LIST_TRUNCATED")
if error_details_not_empty
else False
)

if (
error_details_not_empty
and status_file["error"]["details"][0]["code"] == "PACKAGE_LIST_TRUNCATED"
):
ua_esm_required_code = (
_verify_details_code(status_file, "UA_ESM_REQUIRED")
if error_details_not_empty
else False
)

if truncated_package_code:
assert_that(status_file["status"]).described_as(
"Expected the status file patches to CompletedWithWarnings"
expected_warning_status_msg
).is_equal_to("CompletedWithWarnings")
elif (
_is_supported_linux_distro(node)
and node.os.information.version.major == 18
and error_details_not_empty
and status_file["error"]["details"][0]["code"] == "UA_ESM_REQUIRED"
and ua_esm_required_code
):
# Ubuntu 1804 OS image has UA patches that needs upgrade OS to Pro version
# Set error code to 1 notify customers to upgrade OS to Pro to install patches
assert_that(status_file["status"]).described_as(
"Expected the status file patches to succeed"
expected_succeeded_status_msg
).is_equal_to("Succeeded")
assert_that(error_code).described_as(
"Expected 1 error in status file patches operation"
Expand All @@ -126,29 +134,36 @@ def _assert_status_file_result(
api_type is not None
and _is_supported_linux_distro(node)
and node.os.information.version.major == 16
and error_details_not_empty
and status_file["error"]["details"][0]["code"] == "UA_ESM_REQUIRED"
and ua_esm_required_code
):
# This only applies on installation api call
# Ubuntu 1604 OS image has UA patches that needs upgrade OS to Pro version
# Set error code to 1 notify customers to upgrade OS to Pro to install patches
assert_that(status_file["status"]).described_as(
"Expected the status file patches to CompletedWithWarnings"
expected_warning_status_msg
).is_equal_to("CompletedWithWarnings")
assert_that(error_code).described_as(
"Expected 1 error in status file patches operation"
).is_equal_to("1")

else:
assert_that(status_file["status"]).described_as(
"Expected the status file patches to succeed"
expected_succeeded_status_msg
).is_equal_to("Succeeded")

assert_that(error_code).described_as(
"Expected no error in status file patches operation"
).is_equal_to("0")


def _verify_details_code(status_file: Any, code: str) -> bool:
return any(
code in detail_code["code"]
for detail_code in status_file["error"]["details"]
if "code" in detail_code
)


def _is_supported_linux_distro(node: Node) -> bool:
supported_major_versions = {
Ubuntu: [18, 16],
Expand Down

0 comments on commit 14bdcb8

Please sign in to comment.