1818# limitations under the License.
1919
2020import os
21+ import socket
2122
2223Test .Summary = '''
2324Test the enforcement of proxy.config.log.max_space_mb_for_logs.
@@ -46,7 +47,7 @@ class TestLogRetention:
4647 }
4748
4849 __server = None
49- __ts_counter = 1
50+ __ts_counter = 0
5051 __server_is_started = False
5152
5253 def __init__ (self , records_config , run_description , command = "traffic_manager" ):
@@ -144,14 +145,17 @@ def get_command_to_rotate_thrice(self):
144145
145146
146147#
147- # Run 1 : Verify that log deletion happens when no min_count is specified.
148+ # Test 0 : Verify that log deletion happens when no min_count is specified.
148149#
150+ specified_hostname = 'my_hostname'
149151twelve_meg_log_space = {
150152 # The following configures a 12 MB log cap with a required 2 MB head room.
151153 # Thus the rotated log of just over 10 MB should be deleted because it
152154 # will not leave enough head room.
153155 'proxy.config.log.max_space_mb_headroom' : 2 ,
154156 'proxy.config.log.max_space_mb_for_logs' : 12 ,
157+ # Verify that setting a hostname changes the hostname used in rolled logs.
158+ 'proxy.config.log.hostname' : specified_hostname ,
155159}
156160test = TestLogRetention (twelve_meg_log_space ,
157161 "Verify log rotation and deletion of the configured log file with no min_count." )
@@ -187,7 +191,7 @@ def get_command_to_rotate_thrice(self):
187191 "Verify manager.log auto-delete configuration" )
188192# Verify test_deletion was rotated and deleted.
189193test .ts .Streams .stderr += Testers .ContainsExpression (
190- "The rolled logfile.*test_deletion.log_.*was auto-deleted.*bytes were reclaimed" ,
194+ f "The rolled logfile.*test_deletion.log_{ specified_hostname } .*was auto-deleted.*bytes were reclaimed" ,
191195 "Verify that space was reclaimed" )
192196
193197test .tr .Processes .Default .Command = test .get_command_to_rotate_once ()
@@ -198,7 +202,7 @@ def get_command_to_rotate_thrice(self):
198202
199203
200204#
201- # Test 2 : Verify log deletion happens with a min_count of 1.
205+ # Test 1 : Verify log deletion happens with a min_count of 1.
202206#
203207test = TestLogRetention (twelve_meg_log_space ,
204208 "Verify log rotation and deletion of the configured log file with a min_count of 1." )
@@ -236,7 +240,7 @@ def get_command_to_rotate_thrice(self):
236240 "Verify manager.log auto-delete configuration" )
237241# Verify test_deletion was rotated and deleted.
238242test .ts .Streams .stderr += Testers .ContainsExpression (
239- "The rolled logfile.*test_deletion.log_.*was auto-deleted.*bytes were reclaimed" ,
243+ f "The rolled logfile.*test_deletion.log_{ specified_hostname } .*was auto-deleted.*bytes were reclaimed" ,
240244 "Verify that space was reclaimed" )
241245
242246test .tr .Processes .Default .Command = test .get_command_to_rotate_once ()
@@ -246,7 +250,7 @@ def get_command_to_rotate_thrice(self):
246250
247251
248252#
249- # Test 3 : Verify log deletion happens for a plugin's logs.
253+ # Test 2 : Verify log deletion happens for a plugin's logs.
250254#
251255test = TestLogRetention (twelve_meg_log_space ,
252256 "Verify log rotation and deletion of plugin logs." )
@@ -279,7 +283,7 @@ def get_command_to_rotate_thrice(self):
279283test .tr .StillRunningAfter = test .server
280284
281285#
282- # Test 4 : Verify log deletion priority behavior.
286+ # Test 3 : Verify log deletion priority behavior.
283287#
284288twenty_two_meg_log_space = {
285289 # The following configures a 22 MB log cap with a required 2 MB head room.
@@ -332,8 +336,12 @@ def get_command_to_rotate_thrice(self):
332336test .ts .Streams .stderr += Testers .ExcludesExpression (
333337 "The rolled logfile.*test_low_priority_deletion.log_.*was auto-deleted.*bytes were reclaimed" ,
334338 "Verify that space was reclaimed from test_high_priority_deletion" )
339+
340+ # Verify that ATS derives the hostname correctly if the user does not specify a
341+ # hostname via 'proxy.config.log.hostname'.
342+ hostname = socket .gethostname ()
335343test .ts .Streams .stderr += Testers .ContainsExpression (
336- "The rolled logfile.*test_high_priority_deletion.log_.*was auto-deleted.*bytes were reclaimed" ,
344+ f "The rolled logfile.*test_high_priority_deletion.log_{ hostname } .*was auto-deleted.*bytes were reclaimed" ,
337345 "Verify that space was reclaimed from test_high_priority_deletion" )
338346
339347test .tr .Processes .Default .Command = test .get_command_to_rotate_once ()
@@ -342,7 +350,7 @@ def get_command_to_rotate_thrice(self):
342350test .tr .StillRunningAfter = test .server
343351
344352#
345- # Test 5 : Verify min_count configuration overrides.
353+ # Test 4 : Verify min_count configuration overrides.
346354#
347355various_min_count_overrides = {
348356 'proxy.config.log.max_space_mb_for_logs' : 22 ,
@@ -381,11 +389,13 @@ def get_command_to_rotate_thrice(self):
381389
382390
383391#
384- # Test 6 : Verify log deletion does not happen when it is disabled.
392+ # Test 5 : Verify log deletion does not happen when it is disabled.
385393#
386394auto_delete_disabled = twelve_meg_log_space .copy ()
387395auto_delete_disabled .update ({
388396 'proxy.config.log.auto_delete_rolled_files' : 0 ,
397+ # Verify that setting a hostname changes the hostname used in rolled logs.
398+ 'proxy.config.log.hostname' : 'my_hostname' ,
389399})
390400test = TestLogRetention (auto_delete_disabled ,
391401 "Verify log deletion does not happen when auto-delet is disabled." )
@@ -432,7 +442,7 @@ def get_command_to_rotate_thrice(self):
432442test .tr .StillRunningAfter = test .server
433443
434444#
435- # Test 7 : Verify that max_roll_count is respected.
445+ # Test 6 : Verify that max_roll_count is respected.
436446#
437447max_roll_count_of_2 = {
438448 'proxy.config.diags.debug.tags' : 'log-file' ,
@@ -472,7 +482,7 @@ def get_command_to_rotate_thrice(self):
472482test .tr .StillRunningAfter = test .server
473483
474484#
475- # Test 8 : Verify log deletion happens after a config reload.
485+ # Test 7 : Verify log deletion happens after a config reload.
476486#
477487test = TestLogRetention (twelve_meg_log_space ,
478488 "Verify log rotation and deletion after a config reload." )
0 commit comments