From d6f03497c511c377c7117cd3a0a96894947ba7b1 Mon Sep 17 00:00:00 2001 From: Xiangce Liu Date: Thu, 9 Jan 2025 15:39:23 +0800 Subject: [PATCH] fix: remove the MustGatherContext and InsightsOperatorContext These two contexts are actually used by CCX rules and redefined in CCX Core too. They are not used in case of non-CCX scenario. Leaving them here would cause archive context identification error, see RHINENG-15103 To keep the 'ocp' example working, move them to the `insights.ocp` script, which doesn't affect the data processing. Signed-off-by: Xiangce Liu --- insights/core/context.py | 42 +++++++++++++++++++--------------------- insights/ocp.py | 19 ++++++++++++++++-- 2 files changed, 37 insertions(+), 24 deletions(-) diff --git a/insights/core/context.py b/insights/core/context.py index fb1ba5a926..4a0f3cbc0c 100644 --- a/insights/core/context.py +++ b/insights/core/context.py @@ -85,8 +85,7 @@ def __init__(self, version=DEFAULT_VERSION, release=None): self.release = release def __bool__(self): - return all([(self.version != DEFAULT_VERSION), - bool(self.release)]) + return all([(self.version != DEFAULT_VERSION), bool(self.release)]) __nonzero__ = __bool__ @@ -102,9 +101,18 @@ def __init__(self, **kwargs): self.loaded = True self.cmd = None optional_attrs = [ - "content", "path", "hostname", "release", - "machine_id", "target", "last_client_run", "relative_path", - "args", "engine", "image", "container_id" + "content", + "path", + "hostname", + "release", + "machine_id", + "target", + "last_client_run", + "relative_path", + "args", + "engine", + "image", + "container_id", ] for k in optional_attrs: setattr(self, k, kwargs.pop(k, None)) @@ -168,7 +176,7 @@ def handles(cls, files): if m in f: i = f.find(m) if f.endswith(m) or f[i + len(m)] == sep: - root = os.path.dirname(f[:i + 1]) + root = os.path.dirname(f[: i + 1]) marker_root.add(root) if len(marker_root) == 1: return (marker_root.pop(), cls) @@ -182,11 +190,13 @@ def handles(cls, files): return (None, None) def check_output(self, cmd, timeout=None, keep_rc=False, env=None, signum=None): - """ Subclasses can override to provide special - environment setup, command prefixes, etc. """ - return subproc.call(cmd, timeout=timeout or self.timeout, signum=signum, - keep_rc=keep_rc, env=env) + Subclasses can override to provide special + environment setup, command prefixes, etc. + """ + return subproc.call( + cmd, timeout=timeout or self.timeout, signum=signum, keep_rc=keep_rc, env=env + ) def shell_out(self, cmd, split=True, timeout=None, keep_rc=False, env=None, signum=None): env = env or os.environ @@ -265,18 +275,6 @@ def locate_path(self, path): return super(JDRContext, self).locate_path(p) -@fs_root -class InsightsOperatorContext(ExecutionContext): - """Recognizes insights-operator archives""" - marker = "config/featuregate" - - -@fs_root -class MustGatherContext(ExecutionContext): - """Recognizes must-gather archives""" - marker = "cluster-scoped-resources" - - class OpenStackContext(ExecutionContext): def __init__(self, hostname): super(OpenStackContext, self).__init__() diff --git a/insights/ocp.py b/insights/ocp.py index 82a924cd96..a5770743de 100644 --- a/insights/ocp.py +++ b/insights/ocp.py @@ -4,19 +4,34 @@ The :py:func:`conf` component recognizes insights-operator and must-gather archives. """ + import logging import os import yaml from fnmatch import fnmatch -from insights.core.plugins import component, datasource -from insights.core.context import InsightsOperatorContext, MustGatherContext from insights.core.archives import extract +from insights.core.context import ExecutionContext, fs_root +from insights.core.plugins import component, datasource from insights.parsr.query import from_dict, Result from insights.util import content_type +@fs_root +class InsightsOperatorContext(ExecutionContext): + """Recognizes insights-operator archives""" + + marker = "config/featuregate" + + +@fs_root +class MustGatherContext(ExecutionContext): + """Recognizes must-gather archives""" + + marker = "cluster-scoped-resources" + + log = logging.getLogger(__name__) contexts = [InsightsOperatorContext, MustGatherContext]