Merge changes for new etcd branch.

This commit is contained in:
Cory Benfield 2015-08-21 08:16:13 +01:00
commit 340c5fb4a1
9 changed files with 16 additions and 22 deletions

View File

@ -237,27 +237,22 @@ class HAProxyContext(context.HAProxyContext):
class EtcdContext(context.OSContextGenerator):
interfaces = ['etcd-peer']
interfaces = ['etcd-proxy']
def __call__(self):
peers = []
ctxt = {'cluster': ''}
cluster_string = ''
if not config('neutron-plugin') == 'Calico':
return ctxt
for rid in relation_ids('etcd-peer'):
for rid in relation_ids('etcd-proxy'):
for unit in related_units(rid):
rdata = relation_get(rid=rid, unit=unit)
peers.append({
'ip': rdata.get('ip'),
'port': rdata.get('port'),
'name': rdata.get('name'),
})
cluster_string = rdata.get('cluster')
if cluster_string:
break
cluster_string = ','.join(
'{name}=http://{ip}:{port}'.format(**p) for p in peers
)
ctxt['cluster'] = cluster_string
return ctxt

View File

@ -510,16 +510,18 @@ def update_nrpe_config():
nrpe_setup.write()
@hooks.hook('etcd-peer-relation-joined')
@hooks.hook('etcd-peer-relation-changed')
def etcd_peer_force_restart(relation_id=None):
@hooks.hook('etcd-proxy-relation-joined')
@hooks.hook('etcd-proxy-relation-changed')
def etcd_proxy_force_restart(relation_id=None):
# note(cory.benfield): Mostly etcd does not require active management,
# but occasionally it does require a full config nuking. This does not
# play well with the standard neutron-api config management, so we
# treat etcd like the special snowflake it insists on being.
CONFIGS.register('/etc/init/etcd.conf', [EtcdContext()])
CONFIGS.write('/etc/init/etcd.conf')
force_etcd_restart()
if 'etcd-proxy' in CONFIGS.complete_contexts():
force_etcd_restart()
def main():

View File

@ -37,8 +37,8 @@ requires:
zeromq-configuration:
interface: zeromq-configuration
scope: container
etcd-peer:
interface: http
etcd-proxy:
interface: etcd-proxy
peers:
cluster:
interface: neutron-api-ha

View File

@ -455,13 +455,11 @@ class EtcdContextTest(CharmTestCase):
def test_some_related_units(self):
self.related_units.return_value = ['unit1']
self.relation_ids.return_value = ['rid2', 'rid3']
self.test_relation.set({'ip': '172.18.18.18',
'port': 8888,
'name': 'testname'})
result = (
'testname=http://172.18.18.18:8888,'
'testname=http://172.18.18.18:8888'
)
self.test_relation.set({'cluster': result})
ctxt = context.EtcdContext()()
expect = {'cluster': result}

View File

@ -731,7 +731,6 @@ class NeutronAPIHooksTests(CharmTestCase):
)
def test_etcd_peer_joined(self):
self._call_hook('etcd-peer-relation-joined')
self._call_hook('etcd-proxy-relation-joined')
self.assertTrue(self.CONFIGS.register.called)
self.CONFIGS.write.assert_called_with('/etc/init/etcd.conf')
self.force_etcd_restart.assert_called_once_with()