Merge ~ines-almeida/txpkgupload:allow-setting-passive-port-range into txpkgupload:master

Proposed by Ines Almeida
Status: Merged
Approved by: Ines Almeida
Approved revision: 7f74fecd50c9c9918247d0337c33b99b81d510ba
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~ines-almeida/txpkgupload:allow-setting-passive-port-range
Merge into: txpkgupload:master
Diff against target: 152 lines (+51/-10)
5 files modified
charm/txpkgupload/config.yaml (+16/-2)
charm/txpkgupload/reactive/txpkgupload.py (+27/-8)
charm/txpkgupload/templates/txpkgupload_config.yaml.j2 (+2/-0)
src/txpkgupload/plugin.py (+4/-0)
src/txpkgupload/tests/test_plugin.py (+2/-0)
Reviewer Review Type Date Requested Status
Colin Watson (community) Approve
Review via email: mp+453441@code.launchpad.net

Commit message

Add port range config to txpkgupload charm

Description of the change

Also added a small fix to the txpkgupload code that was missing in the last MP.

To post a comment you must log in.
Revision history for this message
Ines Almeida (ines-almeida) wrote :
Revision history for this message
Colin Watson (cjwatson) wrote :

Just bear in mind that if you're changing the charm and the payload at the same time, it's usually worth making sure that the payload is rolled out first in any existing environments so that you don't run into upgrade problems.

review: Approve
Revision history for this message
Ines Almeida (ines-almeida) :
Revision history for this message
Otto Co-Pilot (otto-copilot) wrote :
7f74fec... by Ines Almeida

Update unit tests

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/charm/txpkgupload/config.yaml b/charm/txpkgupload/config.yaml
index 4fa1ef3..b53064e 100644
--- a/charm/txpkgupload/config.yaml
+++ b/charm/txpkgupload/config.yaml
@@ -5,8 +5,10 @@ options:
5 description: The port to run the FTP server on.5 description: The port to run the FTP server on.
6 haproxy_server_options:6 haproxy_server_options:
7 type: string7 type: string
8 description: Options to add to HAProxy "server" lines.8 description: >
9 default: check inter 5000 rise 2 fall 5 maxconn 169 Options to add to HAProxy "server" lines. If "{port}" is part of the
10 value, it will be replaced by the 'ftp_port'/'sftp_port'.
11 default: check port {port} inter 5000 rise 2 fall 5 maxconn 16
10 haproxy_service_options_ftp:12 haproxy_service_options_ftp:
11 type: string13 type: string
12 description: HAProxy options for the FTP port.14 description: HAProxy options for the FTP port.
@@ -27,6 +29,18 @@ options:
27 Hosts that should be allowed to rsync logs. Note that this relies on29 Hosts that should be allowed to rsync logs. Note that this relies on
28 the nrpe subordinate charm to set up /etc/rsyncd.conf properly.30 the nrpe subordinate charm to set up /etc/rsyncd.conf properly.
29 default: ""31 default: ""
32 min_passive_port:
33 type: int
34 default:
35 description: >
36 The minimum port number possible to use for passive FTP. This config will
37 only take effect if `max_passive_port` is also set.
38 max_passive_port:
39 type: int
40 default:
41 description: >
42 The maximum port number possible to use for passive FTP. This config will
43 only take effect if `min_passive_port` is also set.
30 oops_prefix:44 oops_prefix:
31 type: string45 type: string
32 default: local46 default: local
diff --git a/charm/txpkgupload/reactive/txpkgupload.py b/charm/txpkgupload/reactive/txpkgupload.py
index 3789135..962ff92 100644
--- a/charm/txpkgupload/reactive/txpkgupload.py
+++ b/charm/txpkgupload/reactive/txpkgupload.py
@@ -196,6 +196,7 @@ def configure_loadbalancer():
196 service_options_ftp = yaml.safe_load(196 service_options_ftp = yaml.safe_load(
197 config["haproxy_service_options_ftp"]197 config["haproxy_service_options_ftp"]
198 )198 )
199 service_options_ftp = list(service_options_ftp)
199 except yaml.YAMLError:200 except yaml.YAMLError:
200 hookenv.log("Could not parse haproxy_service_options_ftp YAML")201 hookenv.log("Could not parse haproxy_service_options_ftp YAML")
201 hookenv.status_set(202 hookenv.status_set(
@@ -206,6 +207,7 @@ def configure_loadbalancer():
206 service_options_sftp = yaml.safe_load(207 service_options_sftp = yaml.safe_load(
207 config["haproxy_service_options_sftp"]208 config["haproxy_service_options_sftp"]
208 )209 )
210 service_options_sftp = list(service_options_sftp)
209 except yaml.YAMLError:211 except yaml.YAMLError:
210 hookenv.log("Could not parse haproxy_service_options_sftp YAML")212 hookenv.log("Could not parse haproxy_service_options_sftp YAML")
211 hookenv.status_set(213 hookenv.status_set(
@@ -216,32 +218,49 @@ def configure_loadbalancer():
216218
217 unit_name = hookenv.local_unit().replace("/", "-")219 unit_name = hookenv.local_unit().replace("/", "-")
218 unit_ip = hookenv.unit_private_ip()220 unit_ip = hookenv.unit_private_ip()
221
222 # For passive FTP transfer, we want our haproxy to bind to not only the
223 # usual FTP/SFTP ports but also to higher ports
224 if config.get("min_passive_port") and config.get("max_passive_port"):
225 extra_ports = (
226 f"bind 0.0.0.0:"
227 f"{config['min_passive_port']}-{config['max_passive_port']}"
228 )
229 service_options_ftp.append(extra_ports)
230 service_options_sftp.append(extra_ports)
231
232 ftp_port = config["ftp_port"]
233 sftp_port = config["sftp_port"]
234
235 # Note that we don't send specific ports for the services.servers list.
236 # Not setting a port makes the haproxy use the same port used in the
237 # client's request.
219 services = [238 services = [
220 {239 {
221 "service_name": "txpkgupload-ftp",240 "service_name": "txpkgupload-ftp",
222 "service_port": config["ftp_port"],241 "service_port": ftp_port,
223 "service_host": "0.0.0.0",242 "service_host": "0.0.0.0",
224 "service_options": list(service_options_ftp),243 "service_options": service_options_ftp,
225 "servers": [244 "servers": [
226 [245 [
227 f"ftp_{unit_name}",246 f"ftp_{unit_name}",
228 unit_ip,247 unit_ip,
229 config["ftp_port"],248 "",
230 server_options,249 server_options.replace("{port}", str(ftp_port)),
231 ]250 ]
232 ],251 ],
233 },252 },
234 {253 {
235 "service_name": "txpkgupload-sftp",254 "service_name": "txpkgupload-sftp",
236 "service_port": config["sftp_port"],255 "service_port": sftp_port,
237 "service_host": "0.0.0.0",256 "service_host": "0.0.0.0",
238 "service_options": list(service_options_sftp),257 "service_options": service_options_sftp,
239 "servers": [258 "servers": [
240 [259 [
241 f"sftp_{unit_name}",260 f"sftp_{unit_name}",
242 unit_ip,261 unit_ip,
243 config["sftp_port"],262 "",
244 server_options,263 server_options.replace("{port}", str(sftp_port)),
245 ]264 ]
246 ],265 ],
247 },266 },
diff --git a/charm/txpkgupload/templates/txpkgupload_config.yaml.j2 b/charm/txpkgupload/templates/txpkgupload_config.yaml.j2
index ea1368c..eb5b224 100644
--- a/charm/txpkgupload/templates/txpkgupload_config.yaml.j2
+++ b/charm/txpkgupload/templates/txpkgupload_config.yaml.j2
@@ -17,3 +17,5 @@ fsroot: "{{ fsroot }}"
1717
18temp_dir: "{{ base_dir }}/tmp-incoming"18temp_dir: "{{ base_dir }}/tmp-incoming"
1919
20min_passive_port: {{ min_passive_port }}
21max_passive_port: {{ max_passive_port }}
diff --git a/src/txpkgupload/plugin.py b/src/txpkgupload/plugin.py
index 32ede15..dbacac5 100644
--- a/src/txpkgupload/plugin.py
+++ b/src/txpkgupload/plugin.py
@@ -132,6 +132,10 @@ class Config(Schema):
132 # same filesystem as fsroot.132 # same filesystem as fsroot.
133 temp_dir = String(if_missing=None)133 temp_dir = String(if_missing=None)
134134
135 # Range of ports for Passive FTP
136 min_passive_port = Int(if_missing=None)
137 max_passive_port = Int(if_missing=None)
138
135 @classmethod139 @classmethod
136 def parse(cls, stream):140 def parse(cls, stream):
137 """Load a YAML configuration from `stream` and validate."""141 """Load a YAML configuration from `stream` and validate."""
diff --git a/src/txpkgupload/tests/test_plugin.py b/src/txpkgupload/tests/test_plugin.py
index bb5ee29..ac07566 100644
--- a/src/txpkgupload/tests/test_plugin.py
+++ b/src/txpkgupload/tests/test_plugin.py
@@ -111,6 +111,8 @@ class TestConfig(TestCase):
111 "port": "2121",111 "port": "2121",
112 },112 },
113 "idle_timeout": 3600,113 "idle_timeout": 3600,
114 "max_passive_port": None,
115 "min_passive_port": None,
114 "oops": {116 "oops": {
115 "directory": "",117 "directory": "",
116 "reporter": "PKGUPLOAD",118 "reporter": "PKGUPLOAD",

Subscribers

People subscribed via source and target branches

to all changes: