@@ -159,8 +159,67 @@ def run_module():
159159 input_tests .append ((normalized , line if line .endswith ('\n ' ) else line + '\n ' ))
160160
161161 if allowlist_file and blocklist_file :
162- module .fail_json (msg = "parameters are mutually exclusive: "
163- "allowlist_file|blocklist_file" , ** result )
162+ # Apply allowlist first, then blocklist (used by lb_tests: [lb] allow + ingress block).
163+ tests_to_run = []
164+ try :
165+ with open (allowlist_file , 'r' ) as f :
166+ allowlist = [line for line in f ]
167+ except IOError :
168+ module .fail_json (msg = "Error opening the allowlist file" )
169+
170+ for allowlist_test in allowlist :
171+ allow_norm = normalize_test_line (allowlist_test )
172+ if allow_norm is None :
173+ continue
174+ allowlist_test_in_input_tests = False
175+ escaped_allow_test = escape_special_characters (allow_norm )
176+
177+ for test_norm , test_raw in input_tests :
178+ if re .fullmatch (escaped_allow_test , test_norm ):
179+ tests_to_run .append ((test_norm , test_raw ))
180+ allowlist_test_in_input_tests = True
181+
182+ if not allowlist_test_in_input_tests :
183+ module .fail_json (msg = "Error: Found a test that exists in {} but not in {} -"
184+ " '{}'" .format (allowlist_file ,
185+ input_tests_file ,
186+ allowlist_test ), ** result )
187+
188+ try :
189+ with open (blocklist_file , 'r' ) as f :
190+ blocklist = [line for line in f ]
191+ except IOError :
192+ module .fail_json (msg = "Error opening the blocklist file" )
193+
194+ blocklist_norms = []
195+ for blocklist_test in blocklist :
196+ block_norm = normalize_test_line (blocklist_test )
197+ if block_norm is not None :
198+ blocklist_norms .append ((block_norm , blocklist_test ))
199+
200+ filtered_tests = []
201+ blocked_tests = []
202+ for test_norm , test_raw in tests_to_run :
203+ test_in_blocklist = False
204+ for block_norm , _block_raw in blocklist_norms :
205+ escaped_block_test = escape_special_characters (block_norm )
206+ if re .fullmatch (escaped_block_test , test_norm ):
207+ test_in_blocklist = True
208+ break
209+ if test_in_blocklist :
210+ blocked_tests .append (test_raw )
211+ else :
212+ filtered_tests .append (test_raw )
213+
214+ try :
215+ with open (output_file , 'w' ) as f :
216+ f .writelines (filtered_tests )
217+ except IOError :
218+ module .fail_json (msg = "Error writing to output file" )
219+
220+ result ['filter_type' ] = 'allowlist+blocklist'
221+ result ['filter_tests_file' ] = allowlist_file
222+ result ['changed' ] = True
164223
165224 elif allowlist_file :
166225 tests_to_run = []
0 commit comments