Skip to content

Commit 775523c

Browse files
authored
fix: support filters that start with minus sign (#4436)
The issue was the root cause of RHINENG-15287. Commit d1065f5 resolved the issue using reversed sorting, making a silent assumption that each component would have at least one filter message that starts with a character with lower precedence than `-`. This commit uses the `grep` command line option `--` which causes all following arguments to be interpreted as operands (positional arguments) even if they start with `-`. See `info grep`. This works even if a component has a single filter message and the filter message starts with `-`. Signed-off-by: Jan Holeček <[email protected]>
1 parent 268805d commit 775523c

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

insights/core/spec_factory.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ def create_args(self):
275275
# Pre-filtering ONLY when collecting data
276276
log.debug("Pre-filtering %s", self.relative_path)
277277
args.append(
278-
["grep", "-F", "\n".join(sorted(self._filters.keys(), reverse=True)), self.path]
278+
["grep", "-F", "--", "\n".join(self._filters.keys()), self.path]
279279
)
280280

281281
return args
@@ -409,7 +409,7 @@ def create_args(self):
409409

410410
if self.split and self._filters:
411411
log.debug("Pre-filtering %s", self.relative_path)
412-
command.append(["grep", "-F", "\n".join(sorted(self._filters.keys(), reverse=True))])
412+
command.append(["grep", "-F", "--", "\n".join(self._filters.keys())])
413413

414414
return command
415415

insights/tests/specs/test_specs.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,21 @@ def test_exp_no_filters():
366366
assert exception_cnt == 11111111
367367

368368

369+
def test_filter_starts_with_minus_sign():
370+
# if interpreted as a grep command line option,
371+
# broker[self_spec].content would raise ContentException
372+
# because grep output would be empty
373+
filter_message = "--quiet"
374+
375+
broker = dr.Broker()
376+
broker[HostContext] = HostContext()
377+
self_spec = simple_file(this_file, filterable=True)
378+
add_filter(self_spec, filter_message)
379+
broker = dr.run(dr.get_dependency_graph(self_spec), broker)
380+
381+
assert ' filter_message = "{}"'.format(filter_message) in broker[self_spec].content
382+
383+
369384
@pytest.mark.parametrize("obfuscate", [True, False])
370385
@patch('insights.cleaner.Cleaner.generate_report', return_value=None)
371386
def test_specs_collect(gen, obfuscate):

0 commit comments

Comments
 (0)