Merge ~cjwatson/launchpad:charm-frontend-extras-librarian-rsync into launchpad:master

Proposed by Colin Watson
Status: Merged
Approved by: Colin Watson
Approved revision: c4ebe030f0578e92fc13acc6debcc148cac95721
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~cjwatson/launchpad:charm-frontend-extras-librarian-rsync
Merge into: launchpad:master
Diff against target: 112 lines (+57/-2)
6 files modified
charm/launchpad-frontend-extras/README.md (+8/-2)
charm/launchpad-frontend-extras/config.yaml (+6/-0)
charm/launchpad-frontend-extras/layer.yaml (+1/-0)
charm/launchpad-frontend-extras/metadata.yaml (+3/-0)
charm/launchpad-frontend-extras/reactive/launchpad-frontend-extras.py (+25/-0)
charm/launchpad-frontend-extras/templates/librarian-logs-rsync.conf.j2 (+14/-0)
Reviewer Review Type Date Requested Status
Guruprasad Approve
Review via email: mp+450385@code.launchpad.net

Commit message

charm: Add librarian-logs rsync module to librarian frontend

Description of the change

The `launchpad-scripts` charm needs to be able to rsync librarian logs from the appropriate frontends so that it can parse them and update download counts. On the legacy frontends this is configured manually; on charmed frontends we need to configure it in code somewhere.

To avoid having to fork the `apache2` charm, we add a custom `librarian-logs` subordinate to `launchpad-frontend-extras`. This can be related to the librarian frontend application to configure an rsync module there.

To post a comment you must log in.
Revision history for this message
Guruprasad (lgp171188) wrote :

LGTM 👍

review: Approve
Revision history for this message
Colin Watson (cjwatson) :
Revision history for this message
Guruprasad (lgp171188) :

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/charm/launchpad-frontend-extras/README.md b/charm/launchpad-frontend-extras/README.md
2index 06636de..9ef4805 100644
3--- a/charm/launchpad-frontend-extras/README.md
4+++ b/charm/launchpad-frontend-extras/README.md
5@@ -5,8 +5,14 @@ fit in anywhere else.
6
7 Assuming that the `haproxy` charm has been deployed as the `services-lb`
8 application and that the `apache2` charm has been deployed as the
9-`main-frontend` application, as in lp:launchpad-mojo-specs, the following
10+`frontend-main` application, as in lp:launchpad-mojo-specs, the following
11 relations are useful:
12
13 juju relate launchpad-frontend-extras:juju-info services-lb:juju-info
14- juju relate launchpad-frontend-extras:apache-website main-frontend:apache-website
15+ juju relate launchpad-frontend-extras:apache-website frontend-main:apache-website
16+
17+This charm can also be related to the `frontend-librarian` application
18+(presumed to be an instance of the `apache2` charm) to publish librarian
19+logs over rsync for use by the `launchpad-scripts` charm:
20+
21+ juju relate launchpad-frontend-extras:librarian-logs frontend-librarian:juju-info
22diff --git a/charm/launchpad-frontend-extras/config.yaml b/charm/launchpad-frontend-extras/config.yaml
23index 648af60..cbe841d 100644
24--- a/charm/launchpad-frontend-extras/config.yaml
25+++ b/charm/launchpad-frontend-extras/config.yaml
26@@ -11,6 +11,12 @@ options:
27 type: boolean
28 description: Whether to enable the "media" domain.
29 default: false
30+ librarian_log_hosts_allow:
31+ type: string
32+ description: >
33+ Space-separated list of hosts that should be allowed to rsync
34+ librarian logs.
35+ default: ""
36 offline_mode:
37 type: string
38 description: >
39diff --git a/charm/launchpad-frontend-extras/layer.yaml b/charm/launchpad-frontend-extras/layer.yaml
40index e3f44d9..56f9014 100644
41--- a/charm/launchpad-frontend-extras/layer.yaml
42+++ b/charm/launchpad-frontend-extras/layer.yaml
43@@ -1,4 +1,5 @@
44 includes:
45 - layer:basic
46 - interface:apache-website
47+ - interface:juju-info
48 repo: https://git.launchpad.net/launchpad
49diff --git a/charm/launchpad-frontend-extras/metadata.yaml b/charm/launchpad-frontend-extras/metadata.yaml
50index f77ae61..daeda2d 100644
51--- a/charm/launchpad-frontend-extras/metadata.yaml
52+++ b/charm/launchpad-frontend-extras/metadata.yaml
53@@ -21,3 +21,6 @@ requires:
54 juju-info:
55 interface: juju-info
56 scope: container
57+ librarian-logs:
58+ interface: juju-info
59+ scope: container
60diff --git a/charm/launchpad-frontend-extras/reactive/launchpad-frontend-extras.py b/charm/launchpad-frontend-extras/reactive/launchpad-frontend-extras.py
61index 2d69b31..2d4e312 100644
62--- a/charm/launchpad-frontend-extras/reactive/launchpad-frontend-extras.py
63+++ b/charm/launchpad-frontend-extras/reactive/launchpad-frontend-extras.py
64@@ -132,3 +132,28 @@ def configure_apache_website():
65 @when_not_all("apache-website.available", "service.configured")
66 def deconfigure_apache_website():
67 clear_flag("service.apache-website.configured")
68+
69+
70+_rsync_path = "/etc/rsync-juju.d/020-librarian-logs.conf"
71+
72+
73+@when("librarian-logs.connected", "service.configured")
74+@when_not("service.librarian-logs.configured")
75+def configure_librarian_logs():
76+ config = dict(hookenv.config())
77+ if config["librarian_log_hosts_allow"]:
78+ hookenv.log("Writing librarian-logs rsync configuration.")
79+ templating.render(
80+ "librarian-logs-rsync.conf.j2", _rsync_path, config, perms=0o644
81+ )
82+ elif os.path.exists(_rsync_path):
83+ os.unlink(_rsync_path)
84+ set_flag("service.librarian-logs.configured")
85+
86+
87+@when("service.librarian-logs.configured")
88+@when_not_all("librarian-logs.connected", "service.configured")
89+def deconfigure_librarian_logs():
90+ if os.path.exists(_rsync_path):
91+ os.unlink(_rsync_path)
92+ clear_flag("service.librarian-logs.configured")
93diff --git a/charm/launchpad-frontend-extras/templates/librarian-logs-rsync.conf.j2 b/charm/launchpad-frontend-extras/templates/librarian-logs-rsync.conf.j2
94new file mode 100644
95index 0000000..54090f2
96--- /dev/null
97+++ b/charm/launchpad-frontend-extras/templates/librarian-logs-rsync.conf.j2
98@@ -0,0 +1,14 @@
99+
100+[librarian-logs]
101+ # /var/log/apache2/ is root:adm 0640, so we can't drop privileges to read
102+ # it.
103+ uid = root
104+ gid = *
105+ path = /var/log/apache2/
106+ comment = LP Librarian Logs
107+ list = false
108+ read only = true
109+ hosts allow = {{ librarian_log_hosts_allow }}
110+ exclude = *
111+ include = {{ domain_librarian }}-access*
112+

Subscribers

People subscribed via source and target branches

to status/vote changes: