11import os
22import shutil
3+ import sys
34
45import pytest
56
@@ -17,7 +18,8 @@ def get_inode_removed_count(fact_config):
1718 Returns:
1819 The current value of host_scanner_scan{label="InodeRemoved"} metric.
1920 """
20- value = get_metric_value (fact_config , "host_scanner_scan" , {"label" : "InodeRemoved" })
21+ value = get_metric_value (fact_config , "host_scanner_scan" , {
22+ "label" : "InodeRemoved" })
2123 return int (value ) if value is not None else 0
2224
2325
@@ -31,8 +33,10 @@ def get_kernel_rmdir_processed(fact_config):
3133 Returns:
3234 The difference between Total and Ignored kernel_path_rmdir_events.
3335 """
34- total_str = get_metric_value (fact_config , "kernel_path_rmdir_events" , {"label" : "Total" })
35- ignored_str = get_metric_value (fact_config , "kernel_path_rmdir_events" , {"label" : "Ignored" })
36+ total_str = get_metric_value (
37+ fact_config , "kernel_path_rmdir_events" , {"label" : "Total" })
38+ ignored_str = get_metric_value (
39+ fact_config , "kernel_path_rmdir_events" , {"label" : "Ignored" })
3640
3741 total = int (total_str ) if total_str is not None else 0
3842 ignored = int (ignored_str ) if ignored_str is not None else 0
@@ -80,7 +84,7 @@ def test_rmdir_empty(monitored_dir, server, fact_config, dirname):
8084
8185 # File creation should be tracked
8286 e1 = Event (process = process , event_type = EventType .CREATION ,
83- file = test_file , host_path = test_file )
87+ file = test_file , host_path = test_file )
8488
8589 server .wait_events ([e1 ])
8690
@@ -89,7 +93,7 @@ def test_rmdir_empty(monitored_dir, server, fact_config, dirname):
8993
9094 # File deletion should be tracked
9195 e2 = Event (process = process , event_type = EventType .UNLINK ,
92- file = test_file , host_path = test_file )
96+ file = test_file , host_path = test_file )
9397
9498 server .wait_events ([e2 ])
9599
@@ -183,6 +187,10 @@ def test_rmdir_recursive(monitored_dir, server, fact_config):
183187 file = file3 , host_path = file3 ),
184188 ]
185189
190+ # Behavior of shutil.rmtree changed between python versions
191+ if sys .version_info < (3 , 10 ):
192+ unlink_events .reverse ()
193+
186194 server .wait_events (unlink_events )
187195
188196 # Check that all inodes and kernel events were tracked
@@ -244,7 +252,7 @@ def test_rmdir_ignored(monitored_dir, ignored_dir, server, fact_config):
244252
245253 # Monitored file creation should generate an event
246254 e1 = Event (process = process , event_type = EventType .CREATION ,
247- file = monitored_file , host_path = monitored_file )
255+ file = monitored_file , host_path = monitored_file )
248256
249257 server .wait_events ([e1 ])
250258
@@ -301,7 +309,7 @@ def test_rmdir_with_parent_inode(monitored_dir, server, fact_config):
301309
302310 # Verify file creation is tracked
303311 e1 = Event (process = process , event_type = EventType .CREATION ,
304- file = test_file , host_path = test_file )
312+ file = test_file , host_path = test_file )
305313 server .wait_events ([e1 ])
306314
307315 # Create another file at the root level (parent directory)
@@ -310,7 +318,7 @@ def test_rmdir_with_parent_inode(monitored_dir, server, fact_config):
310318 f .write ('root content' )
311319
312320 e2 = Event (process = process , event_type = EventType .CREATION ,
313- file = root_file , host_path = root_file )
321+ file = root_file , host_path = root_file )
314322 server .wait_events ([e2 ])
315323
316324 # Remove the subdirectory and its contents
@@ -344,14 +352,14 @@ def test_rmdir_with_parent_inode(monitored_dir, server, fact_config):
344352 f .write ('new content' )
345353
346354 e4 = Event (process = process , event_type = EventType .CREATION ,
347- file = new_file , host_path = new_file )
355+ file = new_file , host_path = new_file )
348356 server .wait_events ([e4 ])
349357
350358 # Remove the new file to clean up
351359 os .remove (new_file )
352360
353361 e5 = Event (process = process , event_type = EventType .UNLINK ,
354- file = new_file , host_path = new_file )
362+ file = new_file , host_path = new_file )
355363 server .wait_events ([e5 ])
356364
357365 # Final metric check: should be 3 total inodes (test_file, subdir, new_file)
0 commit comments