Merge lp:~hloeung/charms/trusty/apache2/open-the-ports-please into lp:charms/trusty/apache2

Proposed by Haw Loeung
Status: Merged
Merged at revision: 73
Proposed branch: lp:~hloeung/charms/trusty/apache2/open-the-ports-please
Merge into: lp:charms/trusty/apache2
Diff against target: 16 lines (+2/-3)
1 file modified
hooks/hooks.py (+2/-3)
To merge this branch: bzr merge lp:~hloeung/charms/trusty/apache2/open-the-ports-please
Reviewer Review Type Date Requested Status
Stuart Bishop (community) Approve
Robert Bruce Park (community) Approve
Review via email: mp+306419@code.launchpad.net

Description of the change

As seen on a production service:

| apache2/0 unknown idle 1.25.6 1 80/tcp 162.213.33.139

Digging into it, it seems that ports.yaml had stale/incorrect information on what ports are open. We should just call open_ports to ensure all are open.

Here's what I did to figure it out and fix it. Excuse my print statements hehe.

Modified:

def ensure_ports(ports):
    """Ensure that only the desired ports are open."""
    print("here {}".format(ports))
    open_ports = set(get_open_ports())
    print("here open {}".format(open_ports))
    ports = set(ports)
    wanted_closed = ports.difference(open_ports)
    print("here closed {}".format(wanted_closed))
    for port in sorted(wanted_closed):
        print("here opening {}".format(port))
        open_port(port)
    unwanted_open = open_ports.difference(ports)
    print("here unwanted {}".format(unwanted_open))
    for port in sorted(unwanted_open):
        print("here closing {}".format(port))
        close_port(port)
    set_open_ports(list(sorted(ports)))

2016-09-22 06:12:02 INFO config-changed here set([80, 443])
2016-09-22 06:12:02 INFO config-changed here open set([80, 443])
2016-09-22 06:12:02 INFO config-changed here closed set([])
2016-09-22 06:12:02 INFO config-changed here unwanted set([])

Deleted ports.yaml:

2016-09-22 06:19:00 INFO config-changed here set([80, 443])
2016-09-22 06:19:00 INFO config-changed here open set([])
2016-09-22 06:19:00 INFO config-changed here closed set([80, 443])
2016-09-22 06:19:00 INFO config-changed here opening 80
2016-09-22 06:19:00 INFO config-changed here opening 443
2016-09-22 06:19:00 INFO config-changed here unwanted set([])

From juju status:

| apache2/0 unknown idle 1.25.6 1 80/tcp,443/tcp 162.213.33.139

To post a comment you must log in.
Revision history for this message
Robert Bruce Park (robru) wrote :

lgtm

review: Approve
Revision history for this message
Stuart Bishop (stub) wrote :

Yup

review: Approve

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 2016-02-25 20:46:58 +0000
3+++ hooks/hooks.py 2016-09-22 06:29:17 +0000
4@@ -957,12 +957,11 @@
5 """Ensure that only the desired ports are open."""
6 open_ports = set(get_open_ports())
7 ports = set(ports)
8- wanted_closed = ports.difference(open_ports)
9- for port in sorted(wanted_closed):
10- open_port(port)
11 unwanted_open = open_ports.difference(ports)
12 for port in sorted(unwanted_open):
13 close_port(port)
14+ for port in ports:
15+ open_port(port)
16 set_open_ports(list(sorted(ports)))
17
18

Subscribers

People subscribed via source and target branches

to all changes: