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
1diff --git a/charm/txpkgupload/config.yaml b/charm/txpkgupload/config.yaml
2index 4fa1ef3..b53064e 100644
3--- a/charm/txpkgupload/config.yaml
4+++ b/charm/txpkgupload/config.yaml
5@@ -5,8 +5,10 @@ options:
6 description: The port to run the FTP server on.
7 haproxy_server_options:
8 type: string
9- description: Options to add to HAProxy "server" lines.
10- default: check inter 5000 rise 2 fall 5 maxconn 16
11+ description: >
12+ Options to add to HAProxy "server" lines. If "{port}" is part of the
13+ value, it will be replaced by the 'ftp_port'/'sftp_port'.
14+ default: check port {port} inter 5000 rise 2 fall 5 maxconn 16
15 haproxy_service_options_ftp:
16 type: string
17 description: HAProxy options for the FTP port.
18@@ -27,6 +29,18 @@ options:
19 Hosts that should be allowed to rsync logs. Note that this relies on
20 the nrpe subordinate charm to set up /etc/rsyncd.conf properly.
21 default: ""
22+ min_passive_port:
23+ type: int
24+ default:
25+ description: >
26+ The minimum port number possible to use for passive FTP. This config will
27+ only take effect if `max_passive_port` is also set.
28+ max_passive_port:
29+ type: int
30+ default:
31+ description: >
32+ The maximum port number possible to use for passive FTP. This config will
33+ only take effect if `min_passive_port` is also set.
34 oops_prefix:
35 type: string
36 default: local
37diff --git a/charm/txpkgupload/reactive/txpkgupload.py b/charm/txpkgupload/reactive/txpkgupload.py
38index 3789135..962ff92 100644
39--- a/charm/txpkgupload/reactive/txpkgupload.py
40+++ b/charm/txpkgupload/reactive/txpkgupload.py
41@@ -196,6 +196,7 @@ def configure_loadbalancer():
42 service_options_ftp = yaml.safe_load(
43 config["haproxy_service_options_ftp"]
44 )
45+ service_options_ftp = list(service_options_ftp)
46 except yaml.YAMLError:
47 hookenv.log("Could not parse haproxy_service_options_ftp YAML")
48 hookenv.status_set(
49@@ -206,6 +207,7 @@ def configure_loadbalancer():
50 service_options_sftp = yaml.safe_load(
51 config["haproxy_service_options_sftp"]
52 )
53+ service_options_sftp = list(service_options_sftp)
54 except yaml.YAMLError:
55 hookenv.log("Could not parse haproxy_service_options_sftp YAML")
56 hookenv.status_set(
57@@ -216,32 +218,49 @@ def configure_loadbalancer():
58
59 unit_name = hookenv.local_unit().replace("/", "-")
60 unit_ip = hookenv.unit_private_ip()
61+
62+ # For passive FTP transfer, we want our haproxy to bind to not only the
63+ # usual FTP/SFTP ports but also to higher ports
64+ if config.get("min_passive_port") and config.get("max_passive_port"):
65+ extra_ports = (
66+ f"bind 0.0.0.0:"
67+ f"{config['min_passive_port']}-{config['max_passive_port']}"
68+ )
69+ service_options_ftp.append(extra_ports)
70+ service_options_sftp.append(extra_ports)
71+
72+ ftp_port = config["ftp_port"]
73+ sftp_port = config["sftp_port"]
74+
75+ # Note that we don't send specific ports for the services.servers list.
76+ # Not setting a port makes the haproxy use the same port used in the
77+ # client's request.
78 services = [
79 {
80 "service_name": "txpkgupload-ftp",
81- "service_port": config["ftp_port"],
82+ "service_port": ftp_port,
83 "service_host": "0.0.0.0",
84- "service_options": list(service_options_ftp),
85+ "service_options": service_options_ftp,
86 "servers": [
87 [
88 f"ftp_{unit_name}",
89 unit_ip,
90- config["ftp_port"],
91- server_options,
92+ "",
93+ server_options.replace("{port}", str(ftp_port)),
94 ]
95 ],
96 },
97 {
98 "service_name": "txpkgupload-sftp",
99- "service_port": config["sftp_port"],
100+ "service_port": sftp_port,
101 "service_host": "0.0.0.0",
102- "service_options": list(service_options_sftp),
103+ "service_options": service_options_sftp,
104 "servers": [
105 [
106 f"sftp_{unit_name}",
107 unit_ip,
108- config["sftp_port"],
109- server_options,
110+ "",
111+ server_options.replace("{port}", str(sftp_port)),
112 ]
113 ],
114 },
115diff --git a/charm/txpkgupload/templates/txpkgupload_config.yaml.j2 b/charm/txpkgupload/templates/txpkgupload_config.yaml.j2
116index ea1368c..eb5b224 100644
117--- a/charm/txpkgupload/templates/txpkgupload_config.yaml.j2
118+++ b/charm/txpkgupload/templates/txpkgupload_config.yaml.j2
119@@ -17,3 +17,5 @@ fsroot: "{{ fsroot }}"
120
121 temp_dir: "{{ base_dir }}/tmp-incoming"
122
123+min_passive_port: {{ min_passive_port }}
124+max_passive_port: {{ max_passive_port }}
125diff --git a/src/txpkgupload/plugin.py b/src/txpkgupload/plugin.py
126index 32ede15..dbacac5 100644
127--- a/src/txpkgupload/plugin.py
128+++ b/src/txpkgupload/plugin.py
129@@ -132,6 +132,10 @@ class Config(Schema):
130 # same filesystem as fsroot.
131 temp_dir = String(if_missing=None)
132
133+ # Range of ports for Passive FTP
134+ min_passive_port = Int(if_missing=None)
135+ max_passive_port = Int(if_missing=None)
136+
137 @classmethod
138 def parse(cls, stream):
139 """Load a YAML configuration from `stream` and validate."""
140diff --git a/src/txpkgupload/tests/test_plugin.py b/src/txpkgupload/tests/test_plugin.py
141index bb5ee29..ac07566 100644
142--- a/src/txpkgupload/tests/test_plugin.py
143+++ b/src/txpkgupload/tests/test_plugin.py
144@@ -111,6 +111,8 @@ class TestConfig(TestCase):
145 "port": "2121",
146 },
147 "idle_timeout": 3600,
148+ "max_passive_port": None,
149+ "min_passive_port": None,
150 "oops": {
151 "directory": "",
152 "reporter": "PKGUPLOAD",

Subscribers

People subscribed via source and target branches

to all changes: