Commit 95f7b6ea authored by Michal 'vorner' Vaner's avatar Michal 'vorner' Vaner

[trac472] Throw when the initial config is bad

For one, because we can, it's synchronous call, for second, ignoring
error is bad no matter what, for third, this makes us use default config
if it's bad, which is potentially even worse. Killing the app is safe.
parent e402f8d4
......@@ -329,10 +329,18 @@ class ModuleCCSession(ConfigData):
if answer:
rcode, value = parse_answer(answer)
if rcode == 0:
if value != None and self.get_module_spec().validate_config(False, value):
self.set_local_config(value);
if self._config_handler:
self._config_handler(value)
if value != None:
errors = []
if self.get_module_spec().validate_config(False,
value,
errors):
self.set_local_config(value);
if self._config_handler:
self._config_handler(value)
else:
raise ModuleCCSessionError(
"Wrong data in configuration: " +
" ".join(errors))
else:
# log error
print("[" + self._module_name + "] Error requesting configuration: " + value)
......
......@@ -220,6 +220,31 @@ class TestModuleCCSession(unittest.TestCase):
self.assertEqual({'command': ['get_config', {'module_name': 'Spec2'}]},
fake_session.get_message('ConfigManager', None))
def test_start5(self):
fake_session = FakeModuleCCSession()
mccs = self.create_session("spec2.spec", None, None, fake_session)
mccs.set_config_handler(self.my_config_handler_ok)
self.assertEqual(len(fake_session.message_queue), 0)
fake_session.group_sendmsg(None, 'Spec2')
fake_session.group_sendmsg(None, 'Spec2')
self.assertRaises(ModuleCCSessionError, mccs.start)
self.assertEqual(len(fake_session.message_queue), 2)
self.assertEqual({'command': ['module_spec', mccs.specification._module_spec]},
fake_session.get_message('ConfigManager', None))
self.assertEqual({'command': ['get_config', {'module_name': 'Spec2'}]},
fake_session.get_message('ConfigManager', None))
self.assertEqual(len(fake_session.message_queue), 0)
fake_session.group_sendmsg({'result': [ 0 ]}, "Spec2")
fake_session.group_sendmsg({'result': [ 0, {"Wrong": True} ]}, "Spec2")
self.assertRaises(ModuleCCSessionError, mccs.start)
self.assertEqual(len(fake_session.message_queue), 2)
self.assertEqual({'command': ['module_spec', mccs.specification._module_spec]},
fake_session.get_message('ConfigManager', None))
self.assertEqual({'command': ['get_config', {'module_name': 'Spec2'}]},
fake_session.get_message('ConfigManager', None))
def test_get_socket(self):
fake_session = FakeModuleCCSession()
mccs = self.create_session("spec1.spec", None, None, fake_session)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment