Merge ~cjwatson/txpkgupload:fix-systemd-socket-activation into txpkgupload:master

Proposed by Colin Watson
Status: Merged
Approved by: Colin Watson
Approved revision: fab943402b1f88cf01458116d870891aff7586e7
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~cjwatson/txpkgupload:fix-systemd-socket-activation
Merge into: txpkgupload:master
Diff against target: 132 lines (+25/-14)
7 files modified
charm/txpkgupload/charmcraft.yaml (+1/-1)
charm/txpkgupload/templates/txpkgupload.service.j2 (+1/-0)
charm/txpkgupload/templates/txpkgupload.socket.j2 (+4/-2)
charm/txpkgupload/templates/txpkgupload_config.yaml.j2 (+2/-2)
src/txpkgupload/plugin.py (+4/-2)
src/txpkgupload/tests/test_plugin.py (+9/-6)
src/txpkgupload/twistedftp.py (+4/-1)
Reviewer Review Type Date Requested Status
Simone Pelosi Approve
Review via email: mp+450808@code.launchpad.net

Commit message

Fix systemd socket activation

Description of the change

We noticed that the application didn't start up in the new charmed deployment on qastaging. I found that this was because socket activation wasn't set up quite right.

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/txpkgupload/charmcraft.yaml b/charm/txpkgupload/charmcraft.yaml
2index 98f3499..6462c4e 100644
3--- a/charm/txpkgupload/charmcraft.yaml
4+++ b/charm/txpkgupload/charmcraft.yaml
5@@ -35,7 +35,7 @@ parts:
6 after:
7 - ols-layers
8 source: https://git.launchpad.net/launchpad-layers
9- source-commit: "300b0d9fd332c055395fe209512335cea03c7af3"
10+ source-commit: "06169f9fa1548bd6abf9be39edf8b81c411595be"
11 source-submodules: []
12 source-type: git
13 plugin: dump
14diff --git a/charm/txpkgupload/templates/txpkgupload.service.j2 b/charm/txpkgupload/templates/txpkgupload.service.j2
15index efd5b4e..ef44de4 100644
16--- a/charm/txpkgupload/templates/txpkgupload.service.j2
17+++ b/charm/txpkgupload/templates/txpkgupload.service.j2
18@@ -1,6 +1,7 @@
19 [Unit]
20 Description=Launchpad FTP/SFTP package upload service
21 After=network.target
22+Requires=txpkgupload.socket
23 ConditionPathExists=!{{ code_dir }}/maintenance.txt
24
25 [Service]
26diff --git a/charm/txpkgupload/templates/txpkgupload.socket.j2 b/charm/txpkgupload/templates/txpkgupload.socket.j2
27index 2bdfdf9..435a710 100644
28--- a/charm/txpkgupload/templates/txpkgupload.socket.j2
29+++ b/charm/txpkgupload/templates/txpkgupload.socket.j2
30@@ -1,9 +1,11 @@
31 [Unit]
32-Description=Twisted package uploader service
33+Description=Twisted package uploader socket
34
35 [Socket]
36-ListenStream={{ sftp_port }}
37+{# The order here must match the index= parameters in
38+ txpkgupload_config.yaml.j2. -#}
39 ListenStream={{ ftp_port }}
40+ListenStream={{ sftp_port }}
41
42 [Install]
43 WantedBy=sockets.target
44diff --git a/charm/txpkgupload/templates/txpkgupload_config.yaml.j2 b/charm/txpkgupload/templates/txpkgupload_config.yaml.j2
45index 78b1edb..ea1368c 100644
46--- a/charm/txpkgupload/templates/txpkgupload_config.yaml.j2
47+++ b/charm/txpkgupload/templates/txpkgupload_config.yaml.j2
48@@ -1,11 +1,11 @@
49 ftp:
50- port: {{ ftp_port }}
51+ port: "systemd:domain=INET6:index=0"
52
53 sftp:
54 authentication_endpoint: "{{ sftp_authentication_endpoint }}"
55 host_key_private: "{{ sftp_host_key_private_path }}"
56 host_key_public: "{{ sftp_host_key_public_path }}"
57- port: "tcp6:{{ sftp_port }}"
58+ port: "systemd:domain=INET6:index=1"
59
60 oops:
61 directory: "{{ oopses_dir }}"
62diff --git a/src/txpkgupload/plugin.py b/src/txpkgupload/plugin.py
63index 9cf30ec..b78923c 100644
64--- a/src/txpkgupload/plugin.py
65+++ b/src/txpkgupload/plugin.py
66@@ -72,8 +72,10 @@ class ConfigFtp(Schema):
67
68 if_key_missing = None
69
70- # The port to run the FTP server on.
71- port = Int(if_missing=2121)
72+ # The port to run the FTP server on. This may be a plain integer (in
73+ # which case it is prefixed with "tcp6:"), or it may be expressed in
74+ # Twisted's "strports" mini-language.
75+ port = String(if_missing="2121")
76
77
78 class ConfigSftp(Schema):
79diff --git a/src/txpkgupload/tests/test_plugin.py b/src/txpkgupload/tests/test_plugin.py
80index 183de40..bb5ee29 100644
81--- a/src/txpkgupload/tests/test_plugin.py
82+++ b/src/txpkgupload/tests/test_plugin.py
83@@ -108,7 +108,7 @@ class TestConfig(TestCase):
84 "debug": False,
85 "fsroot": None,
86 "ftp": {
87- "port": 2121,
88+ "port": "2121",
89 },
90 "idle_timeout": 3600,
91 "oops": {
92@@ -148,17 +148,20 @@ class TestConfig(TestCase):
93 "etc", "txpkgupload.yaml")
94 Config.load(filename)
95
96+ def test_load_ftp_integer(self):
97+ observed = Config.parse("ftp:\n port: 21")
98+ self.assertEqual("21", observed["ftp"]["port"])
99+
100+ def test_load_ftp_strports(self):
101+ observed = Config.parse("ftp:\n port: tcp6:21")
102+ self.assertEqual("tcp6:21", observed["ftp"]["port"])
103+
104 def check_exception(self, config, message):
105 # Check that a UsageError is raised when parsing options.
106 self.assertThat(
107 partial(Config.to_python, config),
108 Raises(MatchesException(Invalid, message)))
109
110- def test_option_ftp_port_integer(self):
111- self.check_exception(
112- {"ftp": {"port": "bob"}},
113- "ftp: port: Please enter an integer value")
114-
115 def test_option_idle_timeout_integer(self):
116 self.check_exception(
117 {"idle_timeout": "bob"},
118diff --git a/src/txpkgupload/twistedftp.py b/src/txpkgupload/twistedftp.py
119index 37deffb..995fa08 100644
120--- a/src/txpkgupload/twistedftp.py
121+++ b/src/txpkgupload/twistedftp.py
122@@ -376,6 +376,9 @@ class FTPServiceFactory(service.Service):
123
124 @staticmethod
125 def makeFTPService(port, root, temp_dir, idle_timeout):
126- strport = "tcp6:%s" % port
127+ if port.isdigit():
128+ strport = "tcp6:%s" % port
129+ else:
130+ strport = port
131 factory = FTPServiceFactory(port, root, temp_dir, idle_timeout)
132 return strports.service(strport, factory.ftpfactory)

Subscribers

People subscribed via source and target branches

to all changes: