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 (community) 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
=== modified file 'charmhelpers/contrib/openstack/context.py'
--- charmhelpers/contrib/openstack/context.py 2015-12-08 15:58:48 +0000
+++ charmhelpers/contrib/openstack/context.py 2016-01-06 22:04:29 +0000
@@ -57,6 +57,7 @@
57 get_nic_hwaddr,57 get_nic_hwaddr,
58 mkdir,58 mkdir,
59 write_file,59 write_file,
60 pwgen,
60)61)
61from charmhelpers.contrib.hahelpers.cluster import (62from charmhelpers.contrib.hahelpers.cluster import (
62 determine_apache_port,63 determine_apache_port,
@@ -87,6 +88,8 @@
87 is_bridge_member,88 is_bridge_member,
88)89)
89from charmhelpers.contrib.openstack.utils import get_host_ip90from charmhelpers.contrib.openstack.utils import get_host_ip
91from charmhelpers.core.unitdata import kv
92
90CA_CERT_PATH = '/usr/local/share/ca-certificates/keystone_juju_ca_cert.crt'93CA_CERT_PATH = '/usr/local/share/ca-certificates/keystone_juju_ca_cert.crt'
91ADDRESS_TYPES = ['admin', 'internal', 'public']94ADDRESS_TYPES = ['admin', 'internal', 'public']
9295
@@ -636,11 +639,18 @@
636 ctxt['ipv6'] = True639 ctxt['ipv6'] = True
637 ctxt['local_host'] = 'ip6-localhost'640 ctxt['local_host'] = 'ip6-localhost'
638 ctxt['haproxy_host'] = '::'641 ctxt['haproxy_host'] = '::'
639 ctxt['stat_port'] = ':::8888'
640 else:642 else:
641 ctxt['local_host'] = '127.0.0.1'643 ctxt['local_host'] = '127.0.0.1'
642 ctxt['haproxy_host'] = '0.0.0.0'644 ctxt['haproxy_host'] = '0.0.0.0'
643 ctxt['stat_port'] = ':8888'645
646 ctxt['stat_port'] = '8888'
647
648 db = kv()
649 ctxt['stat_password'] = db.get('stat-password')
650 if not ctxt['stat_password']:
651 ctxt['stat_password'] = db.set('stat-password',
652 pwgen(32))
653 db.flush()
644654
645 for frontend in cluster_hosts:655 for frontend in cluster_hosts:
646 if (len(cluster_hosts[frontend]['backends']) > 1 or656 if (len(cluster_hosts[frontend]['backends']) > 1 or
647657
=== modified file 'charmhelpers/contrib/openstack/templates/haproxy.cfg'
--- charmhelpers/contrib/openstack/templates/haproxy.cfg 2015-12-08 15:58:48 +0000
+++ charmhelpers/contrib/openstack/templates/haproxy.cfg 2016-01-06 22:04:29 +0000
@@ -33,13 +33,14 @@
33 timeout server 3000033 timeout server 30000
34{%- endif %}34{%- endif %}
3535
36listen stats {{ stat_port }}36listen stats
37 bind {{ local_host }}:{{ stat_port }}
37 mode http38 mode http
38 stats enable39 stats enable
39 stats hide-version40 stats hide-version
40 stats realm Haproxy\ Statistics41 stats realm Haproxy\ Statistics
41 stats uri /42 stats uri /
42 stats auth admin:password43 stats auth admin:{{ stat_password }}
4344
44{% if frontends -%}45{% if frontends -%}
45{% for service, ports in service_ports.items() -%}46{% for service, ports in service_ports.items() -%}
4647
=== modified file 'tests/contrib/openstack/test_os_contexts.py'
--- tests/contrib/openstack/test_os_contexts.py 2015-11-19 17:33:29 +0000
+++ tests/contrib/openstack/test_os_contexts.py 2016-01-06 22:04:29 +0000
@@ -476,6 +476,8 @@
476 'get_host_ip',476 'get_host_ip',
477 'charm_name',477 'charm_name',
478 'sysctl_create',478 'sysctl_create',
479 'kv',
480 'pwgen',
479]481]
480482
481483
@@ -498,6 +500,23 @@
498 return self.relations[relation]500 return self.relations[relation]
499501
500502
503class TestDB(object):
504 '''Test KV store for unitdata testing'''
505 def __init__(self):
506 self.data = {}
507 self.flushed = False
508
509 def get(self, key, default=None):
510 return self.data.get(key, default)
511
512 def set(self, key, value):
513 self.data[key] = value
514 return value
515
516 def flush(self):
517 self.flushed = True
518
519
501class ContextTests(unittest.TestCase):520class ContextTests(unittest.TestCase):
502521
503 def setUp(self):522 def setUp(self):
@@ -509,6 +528,8 @@
509 self.local_unit.return_value = 'localunit'528 self.local_unit.return_value = 'localunit'
510 self.format_ipv6_addr.return_value = None529 self.format_ipv6_addr.return_value = None
511 self.get_host_ip.side_effect = lambda hostname: hostname530 self.get_host_ip.side_effect = lambda hostname: hostname
531 self.kv.side_effect = TestDB
532 self.pwgen.return_value = 'testpassword'
512533
513 def _patch(self, method):534 def _patch(self, method):
514 _m = patch('charmhelpers.contrib.openstack.context.' + method)535 _m = patch('charmhelpers.contrib.openstack.context.' + method)
@@ -1293,7 +1314,8 @@
1293 'default_backend': 'cluster-peer0.localnet',1314 'default_backend': 'cluster-peer0.localnet',
1294 'local_host': '127.0.0.1',1315 'local_host': '127.0.0.1',
1295 'haproxy_host': '0.0.0.0',1316 'haproxy_host': '0.0.0.0',
1296 'stat_port': ':8888',1317 'stat_password': 'testpassword',
1318 'stat_port': '8888',
1297 }1319 }
1298 # the context gets generated.1320 # the context gets generated.
1299 self.assertEquals(ex, result)1321 self.assertEquals(ex, result)
@@ -1345,7 +1367,8 @@
1345 'default_backend': 'cluster-peer0.localnet',1367 'default_backend': 'cluster-peer0.localnet',
1346 'local_host': '127.0.0.1',1368 'local_host': '127.0.0.1',
1347 'haproxy_host': '0.0.0.0',1369 'haproxy_host': '0.0.0.0',
1348 'stat_port': ':8888',1370 'stat_password': 'testpassword',
1371 'stat_port': '8888',
1349 'haproxy_client_timeout': 50000,1372 'haproxy_client_timeout': 50000,
1350 'haproxy_server_timeout': 50000,1373 'haproxy_server_timeout': 50000,
1351 }1374 }
@@ -1430,7 +1453,8 @@
1430 'default_backend': 'cluster-peer0.localnet',1453 'default_backend': 'cluster-peer0.localnet',
1431 'local_host': '127.0.0.1',1454 'local_host': '127.0.0.1',
1432 'haproxy_host': '0.0.0.0',1455 'haproxy_host': '0.0.0.0',
1433 'stat_port': ':8888',1456 'stat_password': 'testpassword',
1457 'stat_port': '8888',
1434 }1458 }
1435 # the context gets generated.1459 # the context gets generated.
1436 self.assertEquals(ex, result)1460 self.assertEquals(ex, result)
@@ -1487,7 +1511,8 @@
1487 'haproxy_server_timeout': 50000,1511 'haproxy_server_timeout': 50000,
1488 'haproxy_client_timeout': 50000,1512 'haproxy_client_timeout': 50000,
1489 'haproxy_host': '::',1513 'haproxy_host': '::',
1490 'stat_port': ':::8888',1514 'stat_password': 'testpassword',
1515 'stat_port': '8888',
1491 'ipv6': True1516 'ipv6': True
1492 }1517 }
1493 # the context gets generated.1518 # the context gets generated.
@@ -1561,7 +1586,8 @@
1561 'default_backend': 'lonely.clusterpeer.howsad',1586 'default_backend': 'lonely.clusterpeer.howsad',
1562 'haproxy_host': '0.0.0.0',1587 'haproxy_host': '0.0.0.0',
1563 'local_host': '127.0.0.1',1588 'local_host': '127.0.0.1',
1564 'stat_port': ':8888'1589 'stat_port': '8888',
1590 'stat_password': 'testpassword',
1565 }1591 }
1566 self.assertEquals(ex, result)1592 self.assertEquals(ex, result)
1567 # and /etc/default/haproxy is updated.1593 # and /etc/default/haproxy is updated.

Subscribers

People subscribed via source and target branches