[svn] commit: r970 - in /trunk/src/lib/config: python/isc/config/ccsession.py python/isc/config/cfgmgr.py python/isc/config/cfgmgr_test.py testdata/b10-config.db
BIND 10 source code commits
bind10-changes at lists.isc.org
Thu Feb 25 22:13:06 UTC 2010
Author: jelte
Date: Thu Feb 25 22:13:05 2010
New Revision: 970
Log:
oh no more unittests
Modified:
trunk/src/lib/config/python/isc/config/ccsession.py
trunk/src/lib/config/python/isc/config/cfgmgr.py
trunk/src/lib/config/python/isc/config/cfgmgr_test.py
trunk/src/lib/config/testdata/b10-config.db
Modified: trunk/src/lib/config/python/isc/config/ccsession.py
==============================================================================
--- trunk/src/lib/config/python/isc/config/ccsession.py (original)
+++ trunk/src/lib/config/python/isc/config/ccsession.py Thu Feb 25 22:13:05 2010
@@ -46,6 +46,8 @@
"""Returns a tuple (rcode, value), where value depends on the
command that was called. If rcode != 0, value is a string
containing an error message"""
+ if type(msg) != dict:
+ raise ModuleCCSessionError("Answer message is not a dict: " + str(msg))
if 'result' not in msg:
raise ModuleCCSessionError("answer message does not contain 'result' element")
elif type(msg['result']) != list:
Modified: trunk/src/lib/config/python/isc/config/cfgmgr.py
==============================================================================
--- trunk/src/lib/config/python/isc/config/cfgmgr.py (original)
+++ trunk/src/lib/config/python/isc/config/cfgmgr.py Thu Feb 25 22:13:05 2010
@@ -91,9 +91,16 @@
file.write(s)
file.write("\n")
file.close()
- os.rename(tmp_filename, self.db_filename)
+ if output_file_name:
+ os.rename(tmp_filename, output_file_name)
+ else:
+ os.rename(tmp_filename, self.db_filename)
except IOError as ioe:
- print("Unable to write config file; configuration not stored")
+ # TODO: log this (level critical)
+ print("[b10-cfgmgr] Unable to write config file; configuration not stored: " + str(ioe))
+ except OSError as ose:
+ # TODO: log this (level critical)
+ print("[b10-cfgmgr] Unable to write config file; configuration not stored: " + str(ose))
def __eq__(self, other):
"""Returns True if the data contained is equal. data_path and
@@ -153,7 +160,7 @@
config_data = {}
if name:
if name in self.module_specs:
- config_data[name] = self.module_specs[name].get_data
+ config_data[name] = self.module_specs[name].get_config_spec()
else:
for module_name in self.module_specs.keys():
config_data[module_name] = self.module_specs[module_name].get_config_spec()
@@ -166,7 +173,7 @@
commands = {}
if name:
if name in self.module_specs:
- commands[name] = self.module_specs[name].get_commands_spec
+ commands[name] = self.module_specs[name].get_commands_spec()
else:
for module_name in self.module_specs.keys():
commands[module_name] = self.module_specs[module_name].get_commands_spec()
@@ -243,9 +250,10 @@
self.cc.group_sendmsg({ "config_update": conf_part[module_name] }, module_name)
# replace 'our' answer with that of the module
answer, env = self.cc.group_recvmsg(False)
- rcode, val = isc.config.ccsession.parse_answer(answer)
- if rcode == 0:
- self.write_config()
+ if answer:
+ rcode, val = isc.config.ccsession.parse_answer(answer)
+ if rcode == 0:
+ self.write_config()
elif len(cmd) == 1:
# todo: use api (and check the data against the definition?)
old_data = self.config.data.copy()
@@ -257,10 +265,14 @@
if module != "version":
self.cc.group_sendmsg({ "config_update": self.config.data[module] }, module)
answer, env = self.cc.group_recvmsg(False)
- rcode, val = isc.config.ccsession.parse_answer(answer)
- if rcode != 0:
+ if answer == None:
got_error = True
- err_list.append(val)
+ err_list.append("No answer message from " + module)
+ else:
+ rcode, val = isc.config.ccsession.parse_answer(answer)
+ if rcode != 0:
+ got_error = True
+ err_list.append(val)
if not got_error:
self.write_config()
answer = isc.config.ccsession.create_answer(0)
@@ -272,7 +284,7 @@
print(cmd)
answer = isc.config.ccsession.create_answer(1, "Wrong number of arguments")
if not answer:
- answer = isc.config.ccsession.create_answer(1, "Error handling set_config command")
+ answer = isc.config.ccsession.create_answer(1, "No answer message from " + cmd[0])
return answer
@@ -312,6 +324,7 @@
elif cmd == isc.config.ccsession.COMMAND_SET_CONFIG:
answer = self._handle_set_config(arg)
elif cmd == "shutdown":
+ # TODO: logging
print("[b10-cfgmgr] Received shutdown command")
self.running = False
answer = isc.config.ccsession.create_answer(0)
Modified: trunk/src/lib/config/python/isc/config/cfgmgr_test.py
==============================================================================
--- trunk/src/lib/config/python/isc/config/cfgmgr_test.py (original)
+++ trunk/src/lib/config/python/isc/config/cfgmgr_test.py Thu Feb 25 22:13:05 2010
@@ -99,6 +99,9 @@
def group_sendmsg(self, msg, channel, target = None):
self.message_queue.append([ channel, target, msg ])
+ def group_reply(self, env, msg):
+ pass
+
def group_recvmsg(self, blocking):
for qm in self.message_queue:
if qm[0] in self.subscriptions and (qm[1] == None or qm[1] in self.subscriptions[qm[0]]):
@@ -176,6 +179,9 @@
self.assert_(module_spec.get_module_name() in self.cm.module_specs)
config_spec = self.cm.get_config_spec()
self.assertEqual(config_spec['Spec2'], module_spec.get_config_spec())
+ config_spec = self.cm.get_config_spec('Spec2')
+ self.assertEqual(config_spec['Spec2'], module_spec.get_config_spec())
+
def test_get_commands_spec(self):
commands_spec = self.cm.get_commands_spec()
@@ -193,11 +199,17 @@
self.assert_(module_spec.get_module_name() in self.cm.module_specs)
commands_spec = self.cm.get_commands_spec()
self.assertEqual(commands_spec['Spec2'], module_spec.get_commands_spec())
+ commands_spec = self.cm.get_commands_spec('Spec2')
+ self.assertEqual(commands_spec['Spec2'], module_spec.get_commands_spec())
def test_read_config(self):
self.assertEqual(self.cm.config.data, {'version': 1})
self.cm.read_config()
- self.assertEqual(self.cm.config.data, {'TestModule': {'test': 124}, 'version': 1})
+ # due to what get written, the value here is what the last set_config command in test_handle_msg does
+ self.assertEqual(self.cm.config.data, {'TestModule': {'test': 125}, 'version': 1})
+ self.cm.data_path = "/no_such_path"
+ self.cm.read_config()
+ self.assertEqual(self.cm.config.data, {'version': 1})
def test_write_config(self):
# tested in ConfigManagerData tests
@@ -213,6 +225,7 @@
self._handle_msg_helper({ "command": [ "badcommand" ] }, { 'result': [ 1, "Unknown command: badcommand"]})
self._handle_msg_helper({ "command": [ "get_commands_spec" ] }, { 'result': [ 0, {} ]})
self._handle_msg_helper({ "command": [ "get_module_spec" ] }, { 'result': [ 0, {} ]})
+ self._handle_msg_helper({ "command": [ "get_module_spec", { "module_name": "Spec2" } ] }, { 'result': [ 0, {} ]})
#self._handle_msg_helper({ "command": [ "get_module_spec", { "module_name": "nosuchmodule" } ] },
# {'result': [1, 'No specification for module nosuchmodule']})
self._handle_msg_helper({ "command": [ "get_module_spec", 1 ] },
@@ -236,21 +249,77 @@
# those in our fake msgq first.
my_ok_answer = { 'result': [ 0 ] }
+
+ # Send the 'ok' that cfgmgr expects back to the fake queue first
self.fake_session.group_sendmsg(my_ok_answer, "ConfigManager")
+ # then send the command
self._handle_msg_helper({ "command": [ "set_config", [self.name, { "test": 123 }] ] },
my_ok_answer)
- self.assertEqual(len(self.fake_session.message_queue), 1)
+ # The cfgmgr should have eaten the ok message, and sent out an update again
+ self.assertEqual(len(self.fake_session.message_queue), 1)
+ self.assertEqual({'config_update': {'test': 123}},
+ self.fake_session.get_message(self.name, None))
+ # and the queue should now be empty again
+ self.assertEqual(len(self.fake_session.message_queue), 0)
+
+ # below are variations of the theme above
self.fake_session.group_sendmsg(my_ok_answer, "ConfigManager")
- self.assertEqual({'config_update': {'test': 123}},
- self.fake_session.get_message(self.name, None))
self._handle_msg_helper({ "command": [ "set_config", [self.name, { "test": 124 }] ] },
- {'result': [0]})
-
- #print(self.fake_session.message_queue)
+ my_ok_answer)
self.assertEqual(len(self.fake_session.message_queue), 1)
self.assertEqual({'config_update': {'test': 124}},
self.fake_session.get_message(self.name, None))
- self.assertEqual({'version': 1, 'TestModule': {'test': 124}}, self.cm.config.data)
+ self.assertEqual(len(self.fake_session.message_queue), 0)
+
+
+ # This is the last 'succes' one, the value set here is what test_read_config expects
+ self.fake_session.group_sendmsg(my_ok_answer, "ConfigManager")
+ self._handle_msg_helper({ "command": [ "set_config", [ { self.name: { "test": 125 } }] ] },
+ my_ok_answer )
+ self.assertEqual(len(self.fake_session.message_queue), 1)
+ self.assertEqual({'config_update': {'test': 125}},
+ self.fake_session.get_message(self.name, None))
+ self.assertEqual(len(self.fake_session.message_queue), 0)
+
+ self.fake_session.group_sendmsg({ 'result': "bad_answer" }, "ConfigManager")
+ self.assertRaises(isc.config.ccsession.ModuleCCSessionError,
+ self.cm.handle_msg,
+ { "command": [ "set_config", [ { self.name: { "test": 125 } }] ] } )
+ self.assertEqual(len(self.fake_session.message_queue), 1)
+ self.assertEqual({'config_update': {'test': 125}},
+ self.fake_session.get_message(self.name, None))
+ self.assertEqual(len(self.fake_session.message_queue), 0)
+
+ my_bad_answer = { 'result': [1, "bad_answer"] }
+ self.fake_session.group_sendmsg(my_bad_answer, "ConfigManager")
+ self._handle_msg_helper({ "command": [ "set_config", [ { self.name: { "test": 125 } }] ] },
+ my_bad_answer )
+ self.assertEqual(len(self.fake_session.message_queue), 1)
+ self.assertEqual({'config_update': {'test': 125}},
+ self.fake_session.get_message(self.name, None))
+ self.assertEqual(len(self.fake_session.message_queue), 0)
+
+ my_bad_answer = { 'result': [1, "bad_answer"] }
+ self.fake_session.group_sendmsg(my_bad_answer, "ConfigManager")
+ self._handle_msg_helper({ "command": [ "set_config", [ self.name, { "test": 125 }] ] },
+ my_bad_answer )
+ self.assertEqual(len(self.fake_session.message_queue), 1)
+ self.assertEqual({'config_update': {'test': 125}},
+ self.fake_session.get_message(self.name, None))
+ self.assertEqual(len(self.fake_session.message_queue), 0)
+
+ self._handle_msg_helper({ "command": [ "set_config", [ ] ] },
+ {'result': [1, 'Wrong number of arguments']} )
+ self._handle_msg_helper({ "command": [ "set_config", [ { self.name: { "test": 125 } }] ] },
+ { 'result': [1, 'No answer message from TestModule']} )
+ self._handle_msg_helper({ "command": [ "set_config", [ self.name, { "test": 125 }] ] },
+ { 'result': [1, 'No answer message from TestModule']} )
+
+ #self.assertEqual(len(self.fake_session.message_queue), 1)
+ #self.assertEqual({'config_update': {'test': 124}},
+ # self.fake_session.get_message(self.name, None))
+ #self.assertEqual({'version': 1, 'TestModule': {'test': 124}}, self.cm.config.data)
+ #
self._handle_msg_helper({ "command":
["module_spec", self.spec.get_full_spec()]
},
@@ -267,10 +336,15 @@
# self.fake_session.get_message("Cmd-Ctrld", None))
#self.assertEqual({'commands_update': [ self.name, self.commands ] },
# self.fake_session.get_message("Cmd-Ctrld", None))
-
-
+
+ self._handle_msg_helper({ "command":
+ ["shutdown"]
+ },
+ {'result': [0]})
def test_run(self):
+ self.fake_session.group_sendmsg({ "command": [ "get_commands_spec" ] }, "ConfigManager")
+ self.cm.run()
pass
Modified: trunk/src/lib/config/testdata/b10-config.db
==============================================================================
--- trunk/src/lib/config/testdata/b10-config.db (original)
+++ trunk/src/lib/config/testdata/b10-config.db Thu Feb 25 22:13:05 2010
@@ -1,1 +1,1 @@
-{'version': 1}
+{'TestModule': {'test': 125}, 'version': 1}
More information about the bind10-changes
mailing list