@@ -54,23 +54,20 @@ def _verify_unsupported_images(node: Node) -> None:
5454def _verify_unsupported_vm_agent (
5555 node : Node , status_result : Any , error_code : str
5656) -> None :
57- if (
58- error_code == "1"
59- and "Unsupported older Azure Linux Agent version"
60- in status_result ["error" ]["details" ][0 ]["message" ]
57+ unsupported_agent_msg = "Unsupported older Azure Linux Agent version"
58+ if error_code == "1" and any (
59+ unsupported_agent_msg in details ["message" ]
60+ for details in status_result ["error" ]["details" ]
61+ if "message" in details
6162 ):
6263 _unsupported_image_exception_msg (node )
6364
6465
6566def _set_up_vm (node : Node , environment : Environment ) -> Any :
67+ platform_msg = "platform should be AzurePlatform instance"
6668 assert environment .platform , "platform shouldn't be None."
6769 platform : AzurePlatform = environment .platform # type: ignore
68- assert isinstance (
69- platform , AzurePlatform
70- ), "platform should be AzurePlatform instance"
71- assert isinstance (
72- platform , AzurePlatform
73- ), "platform should be AzurePlatform instance"
70+ assert isinstance (platform , AzurePlatform ), platform_msg
7471 compute_client = get_compute_client (platform )
7572 node_context = get_node_context (node )
7673 resource_group_name = node_context .resource_group_name
@@ -99,25 +96,36 @@ def _verify_vm_agent_running(node: Node, log: Logger) -> None:
9996def _assert_status_file_result (
10097 node : Node , status_file : Any , error_code : str , api_type : Optional [str ] = None
10198) -> None :
99+ expected_succeeded_status_msg = "Expected the status file status to be Succeeded"
100+ expected_warning_status_msg = (
101+ "Expected the status file status to be CompletedWithWarnings"
102+ )
102103 error_details_not_empty = len (status_file ["error" ]["details" ]) > 0
104+ truncated_package_code = (
105+ _verify_details_code (status_file , "PACKAGE_LIST_TRUNCATED" )
106+ if error_details_not_empty
107+ else False
108+ )
103109
104- if (
105- error_details_not_empty
106- and status_file ["error" ]["details" ][0 ]["code" ] == "PACKAGE_LIST_TRUNCATED"
107- ):
110+ ua_esm_required_code = (
111+ _verify_details_code (status_file , "UA_ESM_REQUIRED" )
112+ if error_details_not_empty
113+ else False
114+ )
115+
116+ if truncated_package_code :
108117 assert_that (status_file ["status" ]).described_as (
109- "Expected the status file patches to CompletedWithWarnings"
118+ expected_warning_status_msg
110119 ).is_equal_to ("CompletedWithWarnings" )
111120 elif (
112121 _is_supported_linux_distro (node )
113122 and node .os .information .version .major == 18
114- and error_details_not_empty
115- and status_file ["error" ]["details" ][0 ]["code" ] == "UA_ESM_REQUIRED"
123+ and ua_esm_required_code
116124 ):
117125 # Ubuntu 1804 OS image has UA patches that needs upgrade OS to Pro version
118126 # Set error code to 1 notify customers to upgrade OS to Pro to install patches
119127 assert_that (status_file ["status" ]).described_as (
120- "Expected the status file patches to succeed"
128+ expected_succeeded_status_msg
121129 ).is_equal_to ("Succeeded" )
122130 assert_that (error_code ).described_as (
123131 "Expected 1 error in status file patches operation"
@@ -126,29 +134,36 @@ def _assert_status_file_result(
126134 api_type is not None
127135 and _is_supported_linux_distro (node )
128136 and node .os .information .version .major == 16
129- and error_details_not_empty
130- and status_file ["error" ]["details" ][0 ]["code" ] == "UA_ESM_REQUIRED"
137+ and ua_esm_required_code
131138 ):
132139 # This only applies on installation api call
133140 # Ubuntu 1604 OS image has UA patches that needs upgrade OS to Pro version
134141 # Set error code to 1 notify customers to upgrade OS to Pro to install patches
135142 assert_that (status_file ["status" ]).described_as (
136- "Expected the status file patches to CompletedWithWarnings"
143+ expected_warning_status_msg
137144 ).is_equal_to ("CompletedWithWarnings" )
138145 assert_that (error_code ).described_as (
139146 "Expected 1 error in status file patches operation"
140147 ).is_equal_to ("1" )
141148
142149 else :
143150 assert_that (status_file ["status" ]).described_as (
144- "Expected the status file patches to succeed"
151+ expected_succeeded_status_msg
145152 ).is_equal_to ("Succeeded" )
146153
147154 assert_that (error_code ).described_as (
148155 "Expected no error in status file patches operation"
149156 ).is_equal_to ("0" )
150157
151158
159+ def _verify_details_code (status_file : Any , code : str ) -> bool :
160+ return any (
161+ code in detail_code ["code" ]
162+ for detail_code in status_file ["error" ]["details" ]
163+ if "code" in detail_code
164+ )
165+
166+
152167def _is_supported_linux_distro (node : Node ) -> bool :
153168 supported_major_versions = {
154169 Ubuntu : [18 , 16 ],
0 commit comments