Commit ab3d01d8 authored by Jelte Jansen's avatar Jelte Jansen
Browse files

merging trac ticket #242 (remote_config functions aren't fully cleaned up in CCSession)


git-svn-id: svn://bind10.isc.org/svn/bind10/trunk@2369 e5f2f494-b856-4b98-b285-d166d9295462
parent 13d08243
......@@ -150,6 +150,11 @@ class ModuleCCSession(ConfigData):
self._remote_module_configs = {}
def __del__(self):
self._session.group_unsubscribe(self._module_name, "*")
for module_name in self._remote_module_configs:
self._session.group_unsubscribe(module_name)
def start(self):
"""Send the specification for this module to the configuration
manager, and request the current non-default configuration.
......@@ -244,7 +249,7 @@ class ModuleCCSession(ConfigData):
self._session.group_subscribe(module_name);
# Get the current config for that module now
seq = self._session.group_sendmsg({ "command": [ "get_config", { "module_name": module_name } ] }, "ConfigManager")
seq = self._session.group_sendmsg(create_command(COMMAND_GET_CONFIG, { "module_name": module_name }), "ConfigManager")
answer, env = self._session.group_recvmsg(False, seq)
if answer:
rcode, value = parse_answer(answer)
......@@ -259,6 +264,7 @@ class ModuleCCSession(ConfigData):
def remove_remote_config(self, module_name):
"""Removes the remote configuration access for this module"""
if module_name in self._remote_module_configs:
self._session.group_unsubscribe(module_name)
del self._remote_module_configs[module_name]
def get_remote_config_value(self, module_name, identifier):
......@@ -280,7 +286,7 @@ class ModuleCCSession(ConfigData):
def __request_config(self):
"""Asks the configuration manager for the current configuration, and call the config handler if set.
Raises a ModuleCCSessionError if there is no answer from the configuration manager"""
seq = self._session.group_sendmsg({ "command": [ "get_config", { "module_name": self._module_name } ] }, "ConfigManager")
seq = self._session.group_sendmsg(create_command(COMMAND_GET_CONFIG, { "module_name": self._module_name }), "ConfigManager")
answer, env = self._session.group_recvmsg(False, seq)
if answer:
rcode, value = parse_answer(answer)
......
......@@ -119,7 +119,10 @@ class TestModuleCCSession(unittest.TestCase):
def test_start1(self):
fake_session = FakeModuleCCSession()
self.assertFalse("Spec1" in fake_session.subscriptions)
mccs = self.create_session("spec1.spec", None, None, fake_session)
self.assertTrue("Spec1" in fake_session.subscriptions)
self.assertEqual(len(fake_session.message_queue), 0)
self.assertRaises(ModuleCCSessionError, mccs.start)
self.assertEqual(len(fake_session.message_queue), 2)
......@@ -139,6 +142,9 @@ class TestModuleCCSession(unittest.TestCase):
self.assertEqual({'command': ['get_config', {'module_name': 'Spec1'}]},
fake_session.get_message('ConfigManager', None))
mccs = None
self.assertFalse("Spec1" in fake_session.subscriptions)
def test_start2(self):
fake_session = FakeModuleCCSession()
mccs = self.create_session("spec2.spec", None, None, fake_session)
......@@ -352,7 +358,9 @@ class TestModuleCCSession(unittest.TestCase):
self.assertRaises(ModuleCCSessionError, mccs.get_remote_config_value, "Spec2", "item1")
self.assertFalse("Spec2" in fake_session.subscriptions)
rmodname = mccs.add_remote_config(self.spec_file("spec2.spec"))
self.assertTrue("Spec2" in fake_session.subscriptions)
self.assertEqual("Spec2", rmodname)
self.assertRaises(isc.cc.data.DataNotFoundError, mccs.get_remote_config_value, rmodname, "asdf")
value, default = mccs.get_remote_config_value(rmodname, "item1")
......@@ -360,7 +368,15 @@ class TestModuleCCSession(unittest.TestCase):
self.assertEqual(True, default)
mccs.remove_remote_config(rmodname)
self.assertFalse("Spec2" in fake_session.subscriptions)
self.assertRaises(ModuleCCSessionError, mccs.get_remote_config_value, "Spec2", "item1")
# test if unsubscription is alse sent when object is deleted
rmodname = mccs.add_remote_config(self.spec_file("spec2.spec"))
self.assertTrue("Spec2" in fake_session.subscriptions)
mccs = None
self.assertFalse("Spec2" in fake_session.subscriptions)
class fakeUIConn():
def __init__(self):
......
......@@ -16,6 +16,16 @@ class FakeModuleCCSession:
if instance_name:
self.subscriptions[group_name].append(instance_name)
def group_unsubscribe(self, group_name, instance_name = None):
if group_name in self.subscriptions:
if instance_name:
if len(self.subscriptions[group_name]) > 1:
del self.subscriptions[group_name][instance_name]
else:
del self.subscriptions[group_name]
else:
del self.subscriptions[group_name]
def has_subscription(self, group_name, instance_name = None):
if group_name in self.subscriptions:
......
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