From 358121d74c7371eafb724dc247ee620ce93cba81 Mon Sep 17 00:00:00 2001 From: Mauricio Faria de Oliveira Date: Mon, 5 Apr 2021 12:29:21 -0300 Subject: [PATCH] Ensure identical types for comparing port number/string Fix an oversight and regression in commit c97fced7947e ("Close previously opened ports on port config change"). The comparison between an integer and a string (returned by .split()) is always different and thus when upgrading the charm 'port 80' is closed. Make sure the types are set to str. Right now it should only be needed for port and not opened_port_number; but let's future proof both sides of the comparison. (Update: using str() vs int() as apparently int() might fail but str() should always work no matter what it got; thanks, Alex Kavanagh!) Before: $ juju run --unit ceph-radosgw/0 opened-ports 80/tcp $ juju upgrade-charm --path . ceph-radosgw $ juju run --unit ceph-radosgw/0 opened-ports $ @ log: 2021-04-05 15:08:04 INFO juju-log Closed port 80 in favor of port 80 $ python3 -q >>> x=80 >>> y='80/tcp' >>> z=y.split('/')[0] >>> z '80' >>> x 80 >>> x != z True >>> x=str(x) >>> x != z False After: $ juju run --unit ceph-radosgw/1 opened-ports 80/tcp $ juju upgrade-charm --path . ceph-radosgw $ juju run --unit ceph-radosgw/1 opened-ports 80/tcp Signed-off-by: Mauricio Faria de Oliveira Change-Id: I2bcdfec1459ea45d8f57b850b7fd935c360cc7c1 --- hooks/hooks.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hooks/hooks.py b/hooks/hooks.py index b4ebcc8b..040a71e2 100755 --- a/hooks/hooks.py +++ b/hooks/hooks.py @@ -253,7 +253,7 @@ def config_changed(): open_port(port) for opened_port in opened_ports(): opened_port_number = opened_port.split('/')[0] - if opened_port_number != port: + if str(opened_port_number) != str(port): close_port(opened_port_number) log('Closed port %s in favor of port %s' % (opened_port_number, port))