← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~cjwatson/launchpad:charm-scripts-bugsummary-rebuild-action into launchpad:master

 

Colin Watson has proposed merging ~cjwatson/launchpad:charm-scripts-bugsummary-rebuild-action into launchpad:master.

Commit message:
charm/launchpad-scripts: Add a bugsummary-rebuild action

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/448258

As shown on https://wiki.canonical.com/InformationInfrastructure/IS/LaunchpadScripts#general, this is something that's occasionally needed to resolve operational issues.  We should package these sorts of things up as actions rather than having operators SSH into units and run them directly.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:charm-scripts-bugsummary-rebuild-action into launchpad:master.
diff --git a/charm/launchpad-scripts/actions.yaml b/charm/launchpad-scripts/actions.yaml
index aa1c55c..038e8e8 100644
--- a/charm/launchpad-scripts/actions.yaml
+++ b/charm/launchpad-scripts/actions.yaml
@@ -1,3 +1,8 @@
+bugsummary-rebuild:
+  description: >
+    Rebuild the CombinedBugSummary table from its input tables.  This is
+    occasionally needed if the table has become corrupt and starts causing
+    errors in garbo-frequently.
 start-services:
   description: Start services.  Usually run after maintenance.
 stop-services:
diff --git a/charm/launchpad-scripts/actions/actions.py b/charm/launchpad-scripts/actions/actions.py
index 67d862c..25c5d5e 100755
--- a/charm/launchpad-scripts/actions/actions.py
+++ b/charm/launchpad-scripts/actions/actions.py
@@ -2,6 +2,7 @@
 # Copyright 2023 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
+import os
 import subprocess
 import sys
 import traceback
@@ -15,6 +16,7 @@ basic.bootstrap_charm_deps()
 basic.init_config_states()
 
 from charmhelpers.core import hookenv  # noqa: E402
+from ols import base  # noqa: E402
 
 services = (
     "celerybeat_launchpad.service",
@@ -24,6 +26,15 @@ services = (
 )
 
 
+def bugsummary_rebuild():
+    hookenv.log("Rebuilding CombinedBugSummary table.")
+    script = Path(base.code_dir(), "scripts", "bugsummary-rebuild.py")
+    env = dict(os.environ)
+    env["LPCONFIG"] = "launchpad-scripts"
+    subprocess.run(["sudo", "-H", "-u", base.user(), script], check=True)
+    hookenv.action_set({"result": "Rebuild complete"})
+
+
 def start_services():
     for service in services:
         hookenv.log(f"Starting {service}.")
@@ -41,7 +52,9 @@ def stop_services():
 def main(argv):
     action = Path(argv[0]).name
     try:
-        if action == "start-services":
+        if action == "bugsummary-rebuild":
+            bugsummary_rebuild()
+        elif action == "start-services":
             start_services()
         elif action == "stop-services":
             stop_services()
diff --git a/charm/launchpad-scripts/actions/bugsummary-rebuild b/charm/launchpad-scripts/actions/bugsummary-rebuild
new file mode 120000
index 0000000..405a394
--- /dev/null
+++ b/charm/launchpad-scripts/actions/bugsummary-rebuild
@@ -0,0 +1 @@
+actions.py
\ No newline at end of file
diff --git a/charm/launchpad-scripts/layer.yaml b/charm/launchpad-scripts/layer.yaml
index aee1bd5..226ad84 100644
--- a/charm/launchpad-scripts/layer.yaml
+++ b/charm/launchpad-scripts/layer.yaml
@@ -14,6 +14,7 @@ options:
           - answertracker
           - branchscanner
           - bugnotification
+          - bugsummaryrebuild
           - charm-build-job
           - checkwatches
           - copy_packages