Merge lp:~james-page/charm-helpers/lp.1391784 into lp:charm-helpers

Proposed by James Page on 2014-11-20
Status: Merged
Merged at revision: 285
Proposed branch: lp:~james-page/charm-helpers/lp.1391784
Merge into: lp:charm-helpers
Diff against target: 112 lines (+34/-15)
3 files modified
charmhelpers/contrib/openstack/context.py (+18/-14)
charmhelpers/contrib/openstack/templates/haproxy.cfg (+3/-1)
tests/contrib/openstack/test_os_contexts.py (+13/-0)
To merge this branch: bzr merge lp:~james-page/charm-helpers/lp.1391784
Reviewer Review Type Date Requested Status
Liam Young 2014-11-20 Approve on 2015-01-13
Review via email: mp+242422@code.launchpad.net

Commit Message

Add support for a default backend based on the private addresses of the unit.

This backend is used if none of the frontend subnet acl's match, supporting deployments where is expected that access over any configured network interface on the server should just work.

To post a comment you must log in.
251. By James Page on 2014-11-20

Rebase

252. By James Page on 2015-01-13

Rebase

253. By James Page on 2015-01-13

Fixup broken test

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-01-12 11:20:03 +0000
3+++ charmhelpers/contrib/openstack/context.py 2015-01-13 11:56:59 +0000
4@@ -468,21 +468,25 @@
5 _unit = unit.replace('/', '-')
6 cluster_hosts[laddr]['backends'][_unit] = _laddr
7
8- # NOTE(jamespage) no split configurations found, just use
9- # private addresses
10- if not cluster_hosts:
11- netmask = get_netmask_for_address(addr)
12- cluster_hosts[addr] = {'network': "{}/{}".format(addr, netmask),
13- 'backends': {l_unit: addr}}
14- for rid in relation_ids('cluster'):
15- for unit in related_units(rid):
16- _laddr = relation_get('private-address',
17- rid=rid, unit=unit)
18- if _laddr:
19- _unit = unit.replace('/', '-')
20- cluster_hosts[addr]['backends'][_unit] = _laddr
21+ # NOTE(jamespage) add backend based on private address - this
22+ # with either be the only backend or the fallback if no acls
23+ # match in the frontend
24+ cluster_hosts[addr] = {}
25+ netmask = get_netmask_for_address(addr)
26+ cluster_hosts[addr] = {'network': "{}/{}".format(addr, netmask),
27+ 'backends': {l_unit: addr}}
28+ for rid in relation_ids('cluster'):
29+ for unit in related_units(rid):
30+ _laddr = relation_get('private-address',
31+ rid=rid, unit=unit)
32+ if _laddr:
33+ _unit = unit.replace('/', '-')
34+ cluster_hosts[addr]['backends'][_unit] = _laddr
35
36- ctxt = {'frontends': cluster_hosts}
37+ ctxt = {
38+ 'frontends': cluster_hosts,
39+ 'default_backend': addr
40+ }
41
42 if config('haproxy-server-timeout'):
43 ctxt['haproxy_server_timeout'] = config('haproxy-server-timeout')
44
45=== modified file 'charmhelpers/contrib/openstack/templates/haproxy.cfg'
46--- charmhelpers/contrib/openstack/templates/haproxy.cfg 2014-12-19 17:05:07 +0000
47+++ charmhelpers/contrib/openstack/templates/haproxy.cfg 2015-01-13 11:56:59 +0000
48@@ -44,7 +44,9 @@
49 {% for frontend in frontends -%}
50 acl net_{{ frontend }} dst {{ frontends[frontend]['network'] }}
51 use_backend {{ service }}_{{ frontend }} if net_{{ frontend }}
52- {% endfor %}
53+ {% endfor -%}
54+ default_backend {{ service }}_{{ default_backend }}
55+
56 {% for frontend in frontends -%}
57 backend {{ service }}_{{ frontend }}
58 balance leastconn
59
60=== modified file 'tests/contrib/openstack/test_os_contexts.py'
61--- tests/contrib/openstack/test_os_contexts.py 2014-12-19 13:47:43 +0000
62+++ tests/contrib/openstack/test_os_contexts.py 2015-01-13 11:56:59 +0000
63@@ -1019,6 +1019,7 @@
64 }
65 }
66 },
67+ 'default_backend': 'cluster-peer0.localnet',
68 'local_host': '127.0.0.1',
69 'haproxy_host': '0.0.0.0',
70 'stat_port': ':8888',
71@@ -1070,6 +1071,7 @@
72 }
73 }
74 },
75+ 'default_backend': 'cluster-peer0.localnet',
76 'local_host': '127.0.0.1',
77 'haproxy_host': '0.0.0.0',
78 'stat_port': ':8888',
79@@ -1144,8 +1146,17 @@
80 'peer-1': 'cluster-peer1.public',
81 'peer-2': 'cluster-peer2.public',
82 }
83+ },
84+ 'cluster-peer0.localnet': {
85+ 'network': 'cluster-peer0.localnet/255.255.0.0',
86+ 'backends': {
87+ 'peer-0': 'cluster-peer0.localnet',
88+ 'peer-1': 'cluster-peer1.localnet',
89+ 'peer-2': 'cluster-peer2.localnet',
90+ }
91 }
92 },
93+ 'default_backend': 'cluster-peer0.localnet',
94 'local_host': '127.0.0.1',
95 'haproxy_host': '0.0.0.0',
96 'stat_port': ':8888',
97@@ -1200,6 +1211,7 @@
98 }
99 }
100 },
101+ 'default_backend': 'cluster-peer0.localnet',
102 'local_host': 'ip6-localhost',
103 'haproxy_server_timeout': 50000,
104 'haproxy_client_timeout': 50000,
105@@ -1275,6 +1287,7 @@
106 'network': 'lonely.clusterpeer.howsad/255.255.0.0'
107 },
108 },
109+ 'default_backend': 'lonely.clusterpeer.howsad',
110 'haproxy_host': '0.0.0.0',
111 'local_host': '127.0.0.1',
112 'stat_port': ':8888'

Subscribers

People subscribed via source and target branches