Commit 137e70ef authored by Michal 'vorner' Vaner's avatar Michal 'vorner' Vaner

Merge branch 'work/badconf'

parents db21e8ab a9a606dd
......@@ -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)
errors = []
if value != None:
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)
......
......@@ -87,7 +87,7 @@ class ModuleSpec:
validate only a part of a configuration tree (like a list of
non-default values)"""
data_def = self.get_config_spec()
if data_def:
if data_def is not None:
return _validate_spec_list(data_def, full, data, errors)
else:
# no spec, always bad
......@@ -345,7 +345,7 @@ def _validate_spec_list(module_spec, full, data, errors):
for spec_item in module_spec:
if spec_item["item_name"] == item_name:
found = True
if not found:
if not found and item_name != "version":
if errors != None:
errors.append("unknown item " + item_name)
validated = False
......
......@@ -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