Merge lp:~james-page/charm-helpers/haproxy-stats-1.6 into lp:charm-helpers

Proposed by James Page
Status: Merged
Merged at revision: 514
Proposed branch: lp:~james-page/charm-helpers/haproxy-stats-1.6
Merge into: lp:charm-helpers
Diff against target: 158 lines (+46/-9)
3 files modified
charmhelpers/contrib/openstack/context.py (+12/-2)
charmhelpers/contrib/openstack/templates/haproxy.cfg (+3/-2)
tests/contrib/openstack/test_os_contexts.py (+31/-5)
To merge this branch: bzr merge lp:~james-page/charm-helpers/haproxy-stats-1.6
Reviewer Review Type Date Requested Status
Liam Young Approve
Review via email: mp+281747@code.launchpad.net

Description of the change

Fixup template for haproxy to support 1.6.

Tested with precise/icehouse as earlier haproxy we have in a supported release combo.

To post a comment you must log in.
Revision history for this message
James Page (james-page) wrote :

Tested OK with precise/icehouse.

515. By James Page

Bind stats to localhost only, ensure that random, persistent password is used for access

Revision history for this message
Liam Young (gnuoy) wrote :

approve

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'charmhelpers/contrib/openstack/context.py'
2--- charmhelpers/contrib/openstack/context.py 2015-12-08 15:58:48 +0000
3+++ charmhelpers/contrib/openstack/context.py 2016-01-06 22:04:29 +0000
4@@ -57,6 +57,7 @@
5 get_nic_hwaddr,
6 mkdir,
7 write_file,
8+ pwgen,
9 )
10 from charmhelpers.contrib.hahelpers.cluster import (
11 determine_apache_port,
12@@ -87,6 +88,8 @@
13 is_bridge_member,
14 )
15 from charmhelpers.contrib.openstack.utils import get_host_ip
16+from charmhelpers.core.unitdata import kv
17+
18 CA_CERT_PATH = '/usr/local/share/ca-certificates/keystone_juju_ca_cert.crt'
19 ADDRESS_TYPES = ['admin', 'internal', 'public']
20
21@@ -636,11 +639,18 @@
22 ctxt['ipv6'] = True
23 ctxt['local_host'] = 'ip6-localhost'
24 ctxt['haproxy_host'] = '::'
25- ctxt['stat_port'] = ':::8888'
26 else:
27 ctxt['local_host'] = '127.0.0.1'
28 ctxt['haproxy_host'] = '0.0.0.0'
29- ctxt['stat_port'] = ':8888'
30+
31+ ctxt['stat_port'] = '8888'
32+
33+ db = kv()
34+ ctxt['stat_password'] = db.get('stat-password')
35+ if not ctxt['stat_password']:
36+ ctxt['stat_password'] = db.set('stat-password',
37+ pwgen(32))
38+ db.flush()
39
40 for frontend in cluster_hosts:
41 if (len(cluster_hosts[frontend]['backends']) > 1 or
42
43=== modified file 'charmhelpers/contrib/openstack/templates/haproxy.cfg'
44--- charmhelpers/contrib/openstack/templates/haproxy.cfg 2015-12-08 15:58:48 +0000
45+++ charmhelpers/contrib/openstack/templates/haproxy.cfg 2016-01-06 22:04:29 +0000
46@@ -33,13 +33,14 @@
47 timeout server 30000
48 {%- endif %}
49
50-listen stats {{ stat_port }}
51+listen stats
52+ bind {{ local_host }}:{{ stat_port }}
53 mode http
54 stats enable
55 stats hide-version
56 stats realm Haproxy\ Statistics
57 stats uri /
58- stats auth admin:password
59+ stats auth admin:{{ stat_password }}
60
61 {% if frontends -%}
62 {% for service, ports in service_ports.items() -%}
63
64=== modified file 'tests/contrib/openstack/test_os_contexts.py'
65--- tests/contrib/openstack/test_os_contexts.py 2015-11-19 17:33:29 +0000
66+++ tests/contrib/openstack/test_os_contexts.py 2016-01-06 22:04:29 +0000
67@@ -476,6 +476,8 @@
68 'get_host_ip',
69 'charm_name',
70 'sysctl_create',
71+ 'kv',
72+ 'pwgen',
73 ]
74
75
76@@ -498,6 +500,23 @@
77 return self.relations[relation]
78
79
80+class TestDB(object):
81+ '''Test KV store for unitdata testing'''
82+ def __init__(self):
83+ self.data = {}
84+ self.flushed = False
85+
86+ def get(self, key, default=None):
87+ return self.data.get(key, default)
88+
89+ def set(self, key, value):
90+ self.data[key] = value
91+ return value
92+
93+ def flush(self):
94+ self.flushed = True
95+
96+
97 class ContextTests(unittest.TestCase):
98
99 def setUp(self):
100@@ -509,6 +528,8 @@
101 self.local_unit.return_value = 'localunit'
102 self.format_ipv6_addr.return_value = None
103 self.get_host_ip.side_effect = lambda hostname: hostname
104+ self.kv.side_effect = TestDB
105+ self.pwgen.return_value = 'testpassword'
106
107 def _patch(self, method):
108 _m = patch('charmhelpers.contrib.openstack.context.' + method)
109@@ -1293,7 +1314,8 @@
110 'default_backend': 'cluster-peer0.localnet',
111 'local_host': '127.0.0.1',
112 'haproxy_host': '0.0.0.0',
113- 'stat_port': ':8888',
114+ 'stat_password': 'testpassword',
115+ 'stat_port': '8888',
116 }
117 # the context gets generated.
118 self.assertEquals(ex, result)
119@@ -1345,7 +1367,8 @@
120 'default_backend': 'cluster-peer0.localnet',
121 'local_host': '127.0.0.1',
122 'haproxy_host': '0.0.0.0',
123- 'stat_port': ':8888',
124+ 'stat_password': 'testpassword',
125+ 'stat_port': '8888',
126 'haproxy_client_timeout': 50000,
127 'haproxy_server_timeout': 50000,
128 }
129@@ -1430,7 +1453,8 @@
130 'default_backend': 'cluster-peer0.localnet',
131 'local_host': '127.0.0.1',
132 'haproxy_host': '0.0.0.0',
133- 'stat_port': ':8888',
134+ 'stat_password': 'testpassword',
135+ 'stat_port': '8888',
136 }
137 # the context gets generated.
138 self.assertEquals(ex, result)
139@@ -1487,7 +1511,8 @@
140 'haproxy_server_timeout': 50000,
141 'haproxy_client_timeout': 50000,
142 'haproxy_host': '::',
143- 'stat_port': ':::8888',
144+ 'stat_password': 'testpassword',
145+ 'stat_port': '8888',
146 'ipv6': True
147 }
148 # the context gets generated.
149@@ -1561,7 +1586,8 @@
150 'default_backend': 'lonely.clusterpeer.howsad',
151 'haproxy_host': '0.0.0.0',
152 'local_host': '127.0.0.1',
153- 'stat_port': ':8888'
154+ 'stat_port': '8888',
155+ 'stat_password': 'testpassword',
156 }
157 self.assertEquals(ex, result)
158 # and /etc/default/haproxy is updated.

Subscribers

People subscribed via source and target branches