Don't register the group if there is no daemon
Partial-bug: #1519130 Change-Id: Ic7657ea34c7e1e8968715259c755e24771fe2706
This commit is contained in:
@@ -111,6 +111,7 @@ def register_group_and_hostvars(zk):
|
||||
zk.retry(zk.ensure_path, path)
|
||||
node_id = get_new_node_id(zk, path)
|
||||
data = "-".join([host, 'node', str(node_id)])
|
||||
LOG.info('%s (%s) joining the %s party' % (host, node_id, GROUP))
|
||||
party.Party(zk, path, data).join()
|
||||
|
||||
|
||||
@@ -318,10 +319,19 @@ def run_commands(zk, conf):
|
||||
def main():
|
||||
LOG.info('starting')
|
||||
with zk_connection(ZK_HOSTS) as zk:
|
||||
register_group_and_hostvars(zk)
|
||||
service_conf_raw, stat = zk.get(os.path.join('kolla', 'config',
|
||||
GROUP, GROUP))
|
||||
service_conf = json.loads(service_conf_raw)
|
||||
|
||||
# don't join a Party if this container is not running a daemon
|
||||
# process.
|
||||
register_group = False
|
||||
for cmd in service_conf['commands'][GROUP][ROLE].values():
|
||||
if cmd.get('daemon', False):
|
||||
register_group = True
|
||||
if register_group:
|
||||
register_group_and_hostvars(zk)
|
||||
|
||||
generate_config(zk, service_conf['config'][GROUP][ROLE])
|
||||
run_commands(zk, service_conf['commands'][GROUP][ROLE])
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ import os.path
|
||||
import sys
|
||||
|
||||
import fixtures
|
||||
import json
|
||||
import mock
|
||||
from oslotest import base
|
||||
from zake import fake_client
|
||||
@@ -182,3 +183,64 @@ class GenerateConfigTest(base.BaseTestCase):
|
||||
makepath=True)
|
||||
start.generate_config(self.client, conf)
|
||||
m_wf.assert_called_once_with(conf['afile'], '')
|
||||
|
||||
|
||||
@mock.patch.object(start, 'run_commands')
|
||||
@mock.patch.object(start, 'generate_config')
|
||||
@mock.patch.object(start, 'register_group_and_hostvars')
|
||||
class MainTest(base.BaseTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(MainTest, self).setUp()
|
||||
self.client = fake_client.FakeClient()
|
||||
self.client.start()
|
||||
self.addCleanup(self.client.stop)
|
||||
self.addCleanup(self.client.close)
|
||||
start.GROUP = 'testg'
|
||||
start.ROLE = 'testr'
|
||||
|
||||
def test_no_register_if_no_daemon(self, m_rgah, m_gc, m_rc):
|
||||
afile = {'source': 'bla/a.cnf.j2',
|
||||
'dest': '/etc/somewhere.foo',
|
||||
'owner': 'appy',
|
||||
'perm': '0600'}
|
||||
acmd = {'command': 'true'}
|
||||
tconf = {'config': {'testg': {'testr': {'afile': afile}}},
|
||||
'commands': {'testg': {'testr': {'thing': acmd}}}}
|
||||
|
||||
self.client.create('/kolla/config/testg/testg', json.dumps(tconf),
|
||||
makepath=True)
|
||||
|
||||
m_zk_c = mock.MagicMock()
|
||||
with mock.patch.object(start, 'zk_connection', m_zk_c):
|
||||
m_zk_c.return_value.__enter__.return_value = self.client
|
||||
|
||||
start.main()
|
||||
m_gc.assert_called_once_with(self.client,
|
||||
tconf['config']['testg']['testr'])
|
||||
m_rc.assert_called_once_with(self.client,
|
||||
tconf['commands']['testg']['testr'])
|
||||
self.assertEqual([], m_rgah.mock_calls)
|
||||
|
||||
def test_register_if_daemon(self, m_rgah, m_gc, m_rc):
|
||||
afile = {'source': 'bla/a.cnf.j2',
|
||||
'dest': '/etc/somewhere.foo',
|
||||
'owner': 'appy',
|
||||
'perm': '0600'}
|
||||
acmd = {'command': 'true', 'daemon': True}
|
||||
tconf = {'config': {'testg': {'testr': {'afile': afile}}},
|
||||
'commands': {'testg': {'testr': {'thing': acmd}}}}
|
||||
|
||||
self.client.create('/kolla/config/testg/testg', json.dumps(tconf),
|
||||
makepath=True)
|
||||
|
||||
m_zk_c = mock.MagicMock()
|
||||
with mock.patch.object(start, 'zk_connection', m_zk_c):
|
||||
m_zk_c.return_value.__enter__.return_value = self.client
|
||||
|
||||
start.main()
|
||||
m_gc.assert_called_once_with(self.client,
|
||||
tconf['config']['testg']['testr'])
|
||||
m_rc.assert_called_once_with(self.client,
|
||||
tconf['commands']['testg']['testr'])
|
||||
self.assertEqual([mock.call(self.client)], m_rgah.mock_calls)
|
||||
|
||||
Reference in New Issue
Block a user