From dcd738c33d6c0d377e90af4842c03303fad738a7 Mon Sep 17 00:00:00 2001 From: Xiangce Liu Date: Wed, 15 Jan 2025 17:44:40 +0800 Subject: [PATCH] fix: reverse the filters order when grep (#4332) - this is to avoid the first keyword from starting with a dash ('-') - see RHINENG-15287 Signed-off-by: Xiangce Liu (cherry picked from commit d1065f5ec25ece259acd38c9cef78ac0721da863) --- insights/core/spec_factory.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/insights/core/spec_factory.py b/insights/core/spec_factory.py index 6eaac2c70..c115d4e05 100644 --- a/insights/core/spec_factory.py +++ b/insights/core/spec_factory.py @@ -208,7 +208,7 @@ def __init__(self, relative_path, root="/", save_as=None, ds=None, ctx=None, cle if self.ds and filters.ENABLED else False ) - self._filters = filters.get_filters(self.ds, True) if self.ds else set() + self._filters = filters.get_filters(self.ds, True) if self.ds else dict() self.validate() @@ -267,7 +267,9 @@ def create_args(self): args = [] if self._filters: log.debug("Pre-filtering %s", self.relative_path) - args.append(["grep", "-F", "\n".join(self._filters), self.path]) + args.append( + ["grep", "-F", "\n".join(sorted(self._filters.keys(), reverse=True)), self.path] + ) return args @@ -361,7 +363,7 @@ def __init__( if self.ds and filters.ENABLED else False ) - self._filters = filters.get_filters(self.ds, True) if self.ds else set() + self._filters = filters.get_filters(self.ds, True) if self.ds else dict() self.validate() @@ -389,7 +391,7 @@ def create_args(self): if self.split and self._filters: log.debug("Pre-filtering %s", self.relative_path) - command.append(["grep", "-F", "\n".join(self._filters)]) + command.append(["grep", "-F", "\n".join(sorted(self._filters.keys(), reverse=True))]) return command