Merge ~cjwatson/launchpad:charm-codehosting-sync-branches-action into launchpad:master

Proposed by Colin Watson
Status: Merged
Approved by: Colin Watson
Approved revision: 5177987b2aa5f906064fc21c44cb0138558b7a6c
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~cjwatson/launchpad:charm-codehosting-sync-branches-action
Merge into: launchpad:master
Diff against target: 69 lines (+29/-0)
3 files modified
charm/launchpad-codehosting/actions.yaml (+9/-0)
charm/launchpad-codehosting/actions/actions.py (+19/-0)
charm/launchpad-codehosting/actions/sync-branches (+1/-0)
Reviewer Review Type Date Requested Status
Simone Pelosi Approve
Review via email: mp+455646@code.launchpad.net

Commit message

charm: Add a sync-branches action to launchpad-codehosting

Description of the change

Since this needs to be used by the staging-restore script, it's neater to wrap it up in an action.

To post a comment you must log in.
Revision history for this message
Simone Pelosi (pelpsi) wrote :

LGTM!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/charm/launchpad-codehosting/actions.yaml b/charm/launchpad-codehosting/actions.yaml
2index 86aae0a..bca43bd 100644
3--- a/charm/launchpad-codehosting/actions.yaml
4+++ b/charm/launchpad-codehosting/actions.yaml
5@@ -9,3 +9,12 @@ stop-services:
6 will persist across a reboot. It also doesn't disable cron jobs, since
7 those are handled by the cron-control mechanism instead; see
8 lp.services.scripts.base.cronscript_enabled.)
9+sync-branches:
10+ description: |
11+ Sync branch data from production to a non-production environment.
12+ params:
13+ branches:
14+ type: string
15+ description: A space-separated list of branches to sync.
16+ required:
17+ - branches
18diff --git a/charm/launchpad-codehosting/actions/actions.py b/charm/launchpad-codehosting/actions/actions.py
19index cbac43e..a424399 100755
20--- a/charm/launchpad-codehosting/actions/actions.py
21+++ b/charm/launchpad-codehosting/actions/actions.py
22@@ -15,6 +15,7 @@ basic.bootstrap_charm_deps()
23 basic.init_config_states()
24
25 from charmhelpers.core import hookenv # noqa: E402
26+from ols import base # noqa: E402
27
28
29 def start_services():
30@@ -31,6 +32,22 @@ def stop_services():
31 hookenv.action_set({"result": "Services stopped"})
32
33
34+def sync_branches():
35+ params = hookenv.action_get()
36+ script = Path(base.code_dir(), "scripts", "sync-branches.py")
37+ command = [
38+ "sudo",
39+ "-H",
40+ "-u",
41+ base.user(),
42+ "LPCONFIG=launchpad-codehosting",
43+ "--",
44+ script,
45+ ] + params["branches"].split()
46+ subprocess.run(command, check=True)
47+ hookenv.action_set({"result": "Branches synced"})
48+
49+
50 def main(argv):
51 action = Path(argv[0]).name
52 try:
53@@ -38,6 +55,8 @@ def main(argv):
54 start_services()
55 elif action == "stop-services":
56 stop_services()
57+ elif action == "sync-branches":
58+ sync_branches()
59 else:
60 hookenv.action_fail(f"Action {action} not implemented.")
61 except Exception:
62diff --git a/charm/launchpad-codehosting/actions/sync-branches b/charm/launchpad-codehosting/actions/sync-branches
63new file mode 120000
64index 0000000..405a394
65--- /dev/null
66+++ b/charm/launchpad-codehosting/actions/sync-branches
67@@ -0,0 +1 @@
68+actions.py
69\ No newline at end of file

Subscribers

People subscribed via source and target branches

to status/vote changes: