@@ -45,8 +45,8 @@ def prepare_agent():
4545 log .info ("Executing script update-waagent-conf to enable agent cgroups config flag" )
4646 result = shellutil .run_command (["update-waagent-conf" , "Debug.CgroupCheckPeriod=30" , "Debug.CgroupLogMetrics=y" ,
4747 "Debug.CgroupDisableOnProcessCheckFailure=n" ,
48- "Debug.CgroupDisableOnQuotaCheckFailure=n" ,
49- "Debug.AgentMemoryQuota=104857600" ])
48+ "Debug.CgroupDisableOnQuotaCheckFailure=n"
49+ ])
5050 log .info ("Successfully enabled agent cgroups config flag: {0}" .format (result ))
5151
5252 found : bool = retry_if_false (
@@ -55,24 +55,24 @@ def prepare_agent():
5555 fail ("Agent cgroups not enabled" )
5656
5757
58- def verify_agent_has_memory_quota_set ():
58+ def verify_agent_has_no_memory_quota_set ():
5959 """
60- This method verifies that the agent's cgroup has memory quota set
60+ This method verifies that the agent's cgroup does NOT have a memory quota set.
61+ The agent no longer enforces a memory limit via systemd; MemoryHigh should be 'infinity'.
6162 """
62- log .info ("** Verifying agent cgroup has memory quota set" )
63+ log .info ("** Verifying agent cgroup has no memory quota set (MemoryHigh=infinity) " )
6364
64- def check_memory_quota () -> bool :
65+ def check_no_memory_quota () -> bool :
6566 quota = get_agent_memory_quota ()
66- if quota is None or quota == "infinity" :
67- return False
68- return True
67+ # 'infinity' means no memory limit is enforced.
68+ return quota .strip ().lower () == "infinity"
6969
70- found : bool = retry_if_false (check_memory_quota )
70+ found : bool = retry_if_false (check_no_memory_quota )
7171 if found :
7272 log .info ("Agent Memory Quota: %s" , get_agent_memory_quota ())
73- log .info ("Successfully verified agent cgroup has memory quota set" )
73+ log .info ("Successfully verified agent cgroup has no memory quota set" )
7474 else :
75- fail ("The agent's cgroup doesn't seem to have memory quota set. Agent Memory Quota: {0}" .format (get_agent_memory_quota ()))
75+ fail ("The agent's cgroup should not have a memory quota set, but MemoryHigh= {0}" .format (get_agent_memory_quota ()))
7676
7777
7878def verify_agent_reported_memory_metrics ():
@@ -105,41 +105,43 @@ def check_agent_log_for_metrics() -> bool:
105105
106106def verify_memory_throttling_check_on_agent_cgroups ():
107107 """
108- This method verifies that the agent detects memory throttling on its cgroup
108+ This method verifies that the agent reports memory throttling metrics on its cgroup,
109+ and that all reported values are zero. Since the agent no longer enforces a memory limit
110+ (MemoryHigh=infinity), there should be no memory throttling events.
109111 """
110- log .info ("** Verifying agent detected memory throttling on its cgroup" )
112+ log .info ("** Verifying agent reports zero memory throttling on its cgroup" )
111113
114+ # Only consider records logged from now on; older entries (e.g. from before this test
115+ # configured the agent) must not influence the assertion.
112116 throttled_events = []
113- pressure_time = []
114117
115118 def check_agent_log_for_metrics () -> bool :
119+ # Rebuild on every attempt so the assertion reflects only the latest scan window
120+ # and does not accumulate values across retries.
121+ del throttled_events [:]
116122 for record in AgentLog ().read ():
117123 match = re .search (r"Memory/Total Memory Throttled Events \s*\[walinuxagent.service\]\s*=\s*([0-9.]+)" , record .message )
118124 if match is not None :
119125 throttled_events .append (float (match .group (1 )))
120- else :
121- match = re .search (r"Memory/Memory Pressure \(s\)\s*\[walinuxagent.service\]\s*=\s*([0-9.]+)" , record .message )
122- if match is not None :
123- pressure_time .append (float (match .group (1 )))
124- if len (pressure_time ) < 1 or len (throttled_events ) < 1 :
125- return False
126- return True
126+ return len (throttled_events ) >= 1
127127
128- distro = shellutil .run_command ("get_distro.py" ).rstrip ().lower ()
128+ found : bool = retry_if_false (check_agent_log_for_metrics , delay = 60 )
129+ if not found :
130+ fail (
131+ "The agent doesn't seem to be collecting Memory Throttling metrics. Agent found Memory Throttle Events: {0}" .format (
132+ throttled_events ))
129133
130- if "rhel" in distro :
131- log .info ("Skipping memory throttling check verification on RHEL distros due to known issues with memory pressure file not present." )
132- return
134+ log .info ("Memory Throttle Events: %s" , throttled_events )
133135
134- found : bool = retry_if_false (check_agent_log_for_metrics , delay = 60 )
135- if found :
136- log .info ("Memory Throttle Events: %s" , throttled_events )
137- log .info ("Memory Pressure Time: %s" , pressure_time )
138- log .info ("Successfully verified agent reported memory throttling metrics" )
139- else :
136+ # No memory quota is enforced, so every reported value must be zero.
137+ non_zero_throttled = [v for v in throttled_events if v != 0.0 ]
138+ if non_zero_throttled :
140139 fail (
141- "The agent doesn't seem to be collecting Memory Throttling metrics. Agent found Memory Throttle Events: {0} and Pressure: {1}" .format (
142- throttled_events , pressure_time ))
140+ "Expected all memory throttling values to be zero (no memory limit is enforced), "
141+ "but found non-zero Memory Throttle Events: {0}" .format (
142+ non_zero_throttled ))
143+
144+ log .info ("Successfully verified agent reported zero memory throttling metrics" )
143145
144146
145147def cleanup_test_setup ():
@@ -161,7 +163,7 @@ def cleanup_test_setup():
161163def main ():
162164 skip_if_distro_not_supports_memory_quota ()
163165 prepare_agent ()
164- verify_agent_has_memory_quota_set ()
166+ verify_agent_has_no_memory_quota_set ()
165167 verify_agent_reported_memory_metrics ()
166168 verify_memory_throttling_check_on_agent_cgroups ()
167169 cleanup_test_setup ()
0 commit comments