Merge changes for new etcd branch.
This commit is contained in:
commit
340c5fb4a1
@ -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
|
||||
|
@ -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():
|
||||
|
@ -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
|
||||
|
@ -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}
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user