Ticket #242: bind10_trac242_2.patch

File bind10_trac242_2.patch, 5.4 KB (added by jelte, 9 years ago)
  • src/lib/python/isc/config/ccsession.py

     
    150150
    151151        self._remote_module_configs = {}
    152152
     153    def __del__(self):
     154        self._session.group_unsubscribe(self._module_name, "*")
     155        for module_name in self._remote_module_configs:
     156            self._session.group_unsubscribe(module_name)
     157
    153158    def start(self):
    154159        """Send the specification for this module to the configuration
    155160           manager, and request the current non-default configuration.
     
    244249        self._session.group_subscribe(module_name);
    245250
    246251        # Get the current config for that module now
    247         seq = self._session.group_sendmsg({ "command": [ "get_config", { "module_name": module_name } ] }, "ConfigManager")
     252        seq = self._session.group_sendmsg(create_command(COMMAND_GET_CONFIG, { "module_name": module_name }), "ConfigManager")
    248253        answer, env = self._session.group_recvmsg(False, seq)
    249254        if answer:
    250255            rcode, value = parse_answer(answer)
     
    259264    def remove_remote_config(self, module_name):
    260265        """Removes the remote configuration access for this module"""
    261266        if module_name in self._remote_module_configs:
     267            self._session.group_unsubscribe(module_name)
    262268            del self._remote_module_configs[module_name]
    263269
    264270    def get_remote_config_value(self, module_name, identifier):
     
    280286    def __request_config(self):
    281287        """Asks the configuration manager for the current configuration, and call the config handler if set.
    282288           Raises a ModuleCCSessionError if there is no answer from the configuration manager"""
    283         seq = self._session.group_sendmsg({ "command": [ "get_config", { "module_name": self._module_name } ] }, "ConfigManager")
     289        seq = self._session.group_sendmsg(create_command(COMMAND_GET_CONFIG, { "module_name": self._module_name }), "ConfigManager")
    284290        answer, env = self._session.group_recvmsg(False, seq)
    285291        if answer:
    286292            rcode, value = parse_answer(answer)
  • src/lib/python/isc/config/tests/ccsession_test.py

     
    119119
    120120    def test_start1(self):
    121121        fake_session = FakeModuleCCSession()
     122        self.assertFalse("Spec1" in fake_session.subscriptions)
    122123        mccs = self.create_session("spec1.spec", None, None, fake_session)
     124        self.assertTrue("Spec1" in fake_session.subscriptions)
     125
    123126        self.assertEqual(len(fake_session.message_queue), 0)
    124127        self.assertRaises(ModuleCCSessionError, mccs.start)
    125128        self.assertEqual(len(fake_session.message_queue), 2)
     
    139142        self.assertEqual({'command': ['get_config', {'module_name': 'Spec1'}]},
    140143                         fake_session.get_message('ConfigManager', None))
    141144
     145        mccs = None
     146        self.assertFalse("Spec1" in fake_session.subscriptions)
     147
    142148    def test_start2(self):
    143149        fake_session = FakeModuleCCSession()
    144150        mccs = self.create_session("spec2.spec", None, None, fake_session)
     
    352358
    353359        self.assertRaises(ModuleCCSessionError, mccs.get_remote_config_value, "Spec2", "item1")
    354360
     361        self.assertFalse("Spec2" in fake_session.subscriptions)
    355362        rmodname = mccs.add_remote_config(self.spec_file("spec2.spec"))
     363        self.assertTrue("Spec2" in fake_session.subscriptions)
    356364        self.assertEqual("Spec2", rmodname)
    357365        self.assertRaises(isc.cc.data.DataNotFoundError, mccs.get_remote_config_value, rmodname, "asdf")
    358366        value, default = mccs.get_remote_config_value(rmodname, "item1")
     
    360368        self.assertEqual(True, default)
    361369
    362370        mccs.remove_remote_config(rmodname)
     371        self.assertFalse("Spec2" in fake_session.subscriptions)
    363372        self.assertRaises(ModuleCCSessionError, mccs.get_remote_config_value, "Spec2", "item1")
     373
     374        # test if unsubscription is alse sent when object is deleted
     375        rmodname = mccs.add_remote_config(self.spec_file("spec2.spec"))
     376        self.assertTrue("Spec2" in fake_session.subscriptions)
     377        mccs = None
     378        self.assertFalse("Spec2" in fake_session.subscriptions)
     379       
    364380   
    365381class fakeUIConn():
    366382    def __init__(self):
  • src/lib/python/isc/config/tests/unittest_fakesession.py

     
    1616        if instance_name:
    1717            self.subscriptions[group_name].append(instance_name)
    1818           
     19    def group_unsubscribe(self, group_name, instance_name = None):
     20        if group_name in self.subscriptions:
     21            if instance_name:
     22                if len(self.subscriptions[group_name]) > 1:
     23                    del self.subscriptions[group_name][instance_name]
     24                else:
     25                    del self.subscriptions[group_name]
     26            else:
     27                del self.subscriptions[group_name]
     28           
    1929
    2030    def has_subscription(self, group_name, instance_name = None):
    2131        if group_name in self.subscriptions: