Merge lp:~gtrkiller/charm-haproxy/update_port_fix into lp:charm-haproxy

Proposed by Franco Luciano Forneron Buschiazzo
Status: Merged
Approved by: Tom Haddon
Approved revision: 160
Merged at revision: 158
Proposed branch: lp:~gtrkiller/charm-haproxy/update_port_fix
Merge into: lp:charm-haproxy
Diff against target: 60 lines (+18/-11)
1 file modified
hooks/hooks.py (+18/-11)
To merge this branch: bzr merge lp:~gtrkiller/charm-haproxy/update_port_fix
Reviewer Review Type Date Requested Status
Tom Haddon Approve
Canonical IS Reviewers Pending
Review via email: mp+447439@code.launchpad.net

Commit message

Fix port update

Description of the change

Fix port update

To post a comment you must log in.
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

This merge proposal is being monitored by mergebot. Change the status to Approved to merge.

Revision history for this message
Tom Haddon (mthaddon) wrote :

LGTM, thx

review: Approve
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

Change successfully merged at revision 158

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'hooks/hooks.py'
2--- hooks/hooks.py 2023-07-20 14:32:18 +0000
3+++ hooks/hooks.py 2023-07-21 14:41:16 +0000
4@@ -963,6 +963,22 @@
5 return return_value == 0
6
7
8+# -----------------------------------------------------------------------------
9+# get_old_service_ports: Convenience function to get old service ports.
10+# -----------------------------------------------------------------------------
11+def get_old_service_ports():
12+ old_service_ports = []
13+ for port_plus_proto in opened_ports():
14+ # opened_ports returns e.g. ['22/tcp', '53/udp']
15+ # but we just want the port numbers, as ints
16+ if port_plus_proto.endswith('/tcp') or port_plus_proto.endswith('/udp'):
17+ port_only = int(port_plus_proto[:-4])
18+ old_service_ports.append(port_only)
19+ else:
20+ raise ValueError('{} is not a valid port/proto value'.format(port_plus_proto))
21+ return old_service_ports
22+
23+
24 # #############################################################################
25 # Hook functions
26 # #############################################################################
27@@ -998,16 +1014,6 @@
28 ensure_package_status(service_affecting_packages,
29 config_data['package_status'])
30
31- old_service_ports = []
32- for port_plus_proto in opened_ports():
33- # opened_ports returns e.g. ['22/tcp', '53/udp']
34- # but we just want the port numbers, as ints
35- if port_plus_proto.endswith('/tcp') or port_plus_proto.endswith('/udp'):
36- port_only = int(port_plus_proto[:-4])
37- old_service_ports.append(port_only)
38- else:
39- raise ValueError('{} is not a valid port/proto value'.format(port_plus_proto))
40-
41 configure_logrotate(config_data.get('logrotate_config'))
42
43 old_stanzas = get_listen_stanzas()
44@@ -1039,7 +1045,7 @@
45
46 return_code, stderr = service_haproxy("check")
47 if return_code == 0:
48- update_service_ports(old_service_ports, get_service_ports())
49+ update_service_ports(get_old_service_ports(), get_service_ports())
50 service_haproxy("reload")
51 if not (get_listen_stanzas() == old_stanzas):
52 notify_website()
53@@ -1500,6 +1506,7 @@
54 return
55 charm_status, message = status_get()
56 if charm_status == "blocked" and check_status == 0:
57+ update_service_ports(get_old_service_ports(), get_service_ports())
58 service_haproxy("restart")
59 if(service_haproxy("status")):
60 status_set('active', 'Unit is ready')

Subscribers

People subscribed via source and target branches