Blame SOURCES/sos-bz1956673-pulpcore-plugin.patch

ba407d
From 808d9f35ac504a58c337ffed14b39119a591808f Mon Sep 17 00:00:00 2001
ba407d
From: Pavel Moravec <pmoravec@redhat.com>
ba407d
Date: Tue, 27 Apr 2021 22:16:08 +0200
ba407d
Subject: [PATCH] [pulpcore] add plugin for pulp-3
ba407d
ba407d
Pulp-3 / pulpcore as a revolution from pulp-2 needs a separate
ba407d
plugin, since both plugins have nothing in common and there might
ba407d
be deployments where is active both pulp-2 and pulp-3.
ba407d
ba407d
Resolves: #2278
ba407d
ba407d
Signed-off-by: Pavel Moravec <pmoravec@redhat.com>
ba407d
Signed-off-by: Jake Hunsaker <jhunsake@redhat.com>
ba407d
---
ba407d
 sos/report/plugins/pulpcore.py | 120 +++++++++++++++++++++++++++++++++
ba407d
 1 file changed, 120 insertions(+)
ba407d
 create mode 100644 sos/report/plugins/pulpcore.py
ba407d
ba407d
diff --git a/sos/report/plugins/pulpcore.py b/sos/report/plugins/pulpcore.py
ba407d
new file mode 100644
ba407d
index 00000000..20403814
ba407d
--- /dev/null
ba407d
+++ b/sos/report/plugins/pulpcore.py
ba407d
@@ -0,0 +1,120 @@
ba407d
+# Copyright (C) 2021 Red Hat, Inc., Pavel Moravec <pmoravec@redhat.com>
ba407d
+
ba407d
+# This file is part of the sos project: https://github.com/sosreport/sos
ba407d
+#
ba407d
+# This copyrighted material is made available to anyone wishing to use,
ba407d
+# modify, copy, or redistribute it subject to the terms and conditions of
ba407d
+# version 2 of the GNU General Public License.
ba407d
+#
ba407d
+# See the LICENSE file in the source distribution for further information.
ba407d
+
ba407d
+from sos.report.plugins import Plugin, IndependentPlugin
ba407d
+from pipes import quote
ba407d
+from re import match
ba407d
+
ba407d
+
ba407d
+class PulpCore(Plugin, IndependentPlugin):
ba407d
+
ba407d
+    short_desc = 'Pulp-3 aka pulpcore'
ba407d
+
ba407d
+    plugin_name = "pulpcore"
ba407d
+    commands = ("pulpcore-manager",)
ba407d
+    files = ("/etc/pulp/settings.py",)
ba407d
+    option_list = [
ba407d
+        ('task-days', 'days of tasks history', 'fast', 7)
ba407d
+    ]
ba407d
+
ba407d
+    def parse_settings_config(self):
ba407d
+        databases_scope = False
ba407d
+        self.dbhost = "localhost"
ba407d
+        self.dbport = 5432
ba407d
+        self.dbpasswd = ""
ba407d
+        # TODO: read also redis config (we dont expect much customisations)
ba407d
+        # TODO: read also db user (pulp) and database name (pulpcore)
ba407d
+        self.staticroot = "/var/lib/pulp/assets"
ba407d
+        self.uploaddir = "/var/lib/pulp/media/upload"
ba407d
+
ba407d
+        def separate_value(line, sep=':'):
ba407d
+            # an auxiliary method to parse values from lines like:
ba407d
+            #       'HOST': 'localhost',
ba407d
+            val = line.split(sep)[1].lstrip().rstrip(',')
ba407d
+            if (val.startswith('"') and val.endswith('"')) or \
ba407d
+               (val.startswith('\'') and val.endswith('\'')):
ba407d
+                val = val[1:-1]
ba407d
+            return val
ba407d
+
ba407d
+        try:
ba407d
+            for line in open("/etc/pulp/settings.py").read().splitlines():
ba407d
+                # skip empty lines and lines with comments
ba407d
+                if not line or line[0] == '#':
ba407d
+                    continue
ba407d
+                if line.startswith("DATABASES"):
ba407d
+                    databases_scope = True
ba407d
+                    continue
ba407d
+                # example HOST line to parse:
ba407d
+                #         'HOST': 'localhost',
ba407d
+                if databases_scope and match(r"\s+'HOST'\s*:\s+\S+", line):
ba407d
+                    self.dbhost = separate_value(line)
ba407d
+                if databases_scope and match(r"\s+'PORT'\s*:\s+\S+", line):
ba407d
+                    self.dbport = separate_value(line)
ba407d
+                if databases_scope and match(r"\s+'PASSWORD'\s*:\s+\S+", line):
ba407d
+                    self.dbpasswd = separate_value(line)
ba407d
+                # if line contains closing '}' database_scope end
ba407d
+                if databases_scope and '}' in line:
ba407d
+                    databases_scope = False
ba407d
+                if line.startswith("STATIC_ROOT = "):
ba407d
+                    self.staticroot = separate_value(line, sep='=')
ba407d
+                if line.startswith("CHUNKED_UPLOAD_DIR = "):
ba407d
+                    self.uploaddir = separate_value(line, sep='=')
ba407d
+        except IOError:
ba407d
+            # fallback when the cfg file is not accessible
ba407d
+            pass
ba407d
+        # set the password to os.environ when calling psql commands to prevent
ba407d
+        # printing it in sos logs
ba407d
+        # we can't set os.environ directly now: other plugins can overwrite it
ba407d
+        self.env = {"PGPASSWORD": self.dbpasswd}
ba407d
+
ba407d
+    def setup(self):
ba407d
+        self.parse_settings_config()
ba407d
+
ba407d
+        self.add_copy_spec("/etc/pulp/settings.py")
ba407d
+
ba407d
+        self.add_cmd_output("rq info -u redis://localhost:6379/8",
ba407d
+                            env={"LC_ALL": "en_US.UTF-8"},
ba407d
+                            suggest_filename="rq_info")
ba407d
+        self.add_cmd_output("curl -ks https://localhost/pulp/api/v3/status/",
ba407d
+                            suggest_filename="pulp_status")
ba407d
+        dynaconf_env = {"LC_ALL": "en_US.UTF-8",
ba407d
+                        "PULP_SETTINGS": "/etc/pulp/settings.py",
ba407d
+                        "DJANGO_SETTINGS_MODULE": "pulpcore.app.settings"}
ba407d
+        self.add_cmd_output("dynaconf list", env=dynaconf_env)
ba407d
+        for _dir in [self.staticroot, self.uploaddir]:
ba407d
+            self.add_cmd_output("ls -l %s" % _dir)
ba407d
+
ba407d
+        task_days = self.get_option('task-days')
ba407d
+        for table in ['core_task', 'core_taskgroup',
ba407d
+                      'core_reservedresourcerecord',
ba407d
+                      'core_taskreservedresourcerecord',
ba407d
+                      'core_groupprogressreport', 'core_progressreport']:
ba407d
+            _query = "select * from %s where pulp_last_updated > NOW() - " \
ba407d
+                     "interval '%s days' order by pulp_last_updated" % \
ba407d
+                     (table, task_days)
ba407d
+            _cmd = "psql -h %s -p %s -U pulp -d pulpcore -c %s" % \
ba407d
+                   (self.dbhost, self.dbport, quote(_query))
ba407d
+            self.add_cmd_output(_cmd, env=self.env, suggest_filename=table)
ba407d
+
ba407d
+    def postproc(self):
ba407d
+        # TODO obfuscate from /etc/pulp/settings.py :
ba407d
+        # SECRET_KEY = "eKfeDkTnvss7p5WFqYdGPWxXfHnsbDBx"
ba407d
+        # 'PASSWORD': 'tGrag2DmtLqKLTWTQ6U68f6MAhbqZVQj',
ba407d
+        self.do_path_regex_sub(
ba407d
+            "/etc/pulp/settings.py",
ba407d
+            r"(SECRET_KEY\s*=\s*)(.*)",
ba407d
+            r"\1********")
ba407d
+        self.do_path_regex_sub(
ba407d
+            "/etc/pulp/settings.py",
ba407d
+            r"(PASSWORD\S*\s*:\s*)(.*)",
ba407d
+            r"\1********")
ba407d
+
ba407d
+
ba407d
+# vim: set et ts=4 sw=4 :
ba407d
-- 
ba407d
2.26.3
ba407d