Browse Source

[213] Mark the internal methods as protected

Michal 'vorner' Vaner 13 years ago
parent
commit
c929811342

+ 11 - 11
src/lib/python/isc/bind10/component.py

@@ -122,7 +122,7 @@ class Component:
         """
         """
         Start the component for the first time or restart it. If you need to
         Start the component for the first time or restart it. If you need to
         modify the way a component is started, do not replace this method,
         modify the way a component is started, do not replace this method,
-        but start_internal. This one does some more bookkeeping around.
+        but _start_internal. This one does some more bookkeeping around.
 
 
         If you try to start an already running component, it raises ValueError.
         If you try to start an already running component, it raises ValueError.
         """
         """
@@ -134,13 +134,13 @@ class Component:
         self.__state = STATE_RUNNING
         self.__state = STATE_RUNNING
         self.__start_time = time.time()
         self.__start_time = time.time()
         try:
         try:
-            self.start_internal()
+            self._start_internal()
         except Exception as e:
         except Exception as e:
             logger.error(BIND10_COMPONENT_START_EXCEPTION, self.name(), e)
             logger.error(BIND10_COMPONENT_START_EXCEPTION, self.name(), e)
             self.failed()
             self.failed()
             raise
             raise
 
 
-    def start_internal(self):
+    def _start_internal(self):
         """
         """
         This method does the actual starting of a process. If you need to
         This method does the actual starting of a process. If you need to
         change the way the component is started, replace this method.
         change the way the component is started, replace this method.
@@ -153,7 +153,7 @@ class Component:
         boss.start_simple is performed.
         boss.start_simple is performed.
 
 
         If you override the method completely, you should consider overriding
         If you override the method completely, you should consider overriding
-        pid and stop_internal (and possibly failed_internal and name) as well.
+        pid and _stop_internal (and possibly _failed_internal and name) as well.
         You should also register any processes started within boss.
         You should also register any processes started within boss.
         """
         """
         # This one is not tested. For one, it starts a real process
         # This one is not tested. For one, it starts a real process
@@ -172,7 +172,7 @@ class Component:
     def stop(self):
     def stop(self):
         """
         """
         Stop the component. If you need to modify the way a component is
         Stop the component. If you need to modify the way a component is
-        stopped, do not replace this method, but stop_internal. This one
+        stopped, do not replace this method, but _stop_internal. This one
         does some more bookkeeping.
         does some more bookkeeping.
 
 
         If you try to stop a component that is not running, it raises
         If you try to stop a component that is not running, it raises
@@ -184,15 +184,15 @@ class Component:
             raise ValueError("Can't stop a component which is not running")
             raise ValueError("Can't stop a component which is not running")
         logger.info(BIND10_COMPONENT_STOP, self.name())
         logger.info(BIND10_COMPONENT_STOP, self.name())
         self.__state = STATE_STOPPED
         self.__state = STATE_STOPPED
-        self.stop_internal()
+        self._stop_internal()
 
 
-    def stop_internal(self):
+    def _stop_internal(self):
         """
         """
         This is the method that does the actual stopping of a component.
         This is the method that does the actual stopping of a component.
         You can replace this method if you want a different way to do it.
         You can replace this method if you want a different way to do it.
 
 
         If you're overriding this one, you probably want to replace the
         If you're overriding this one, you probably want to replace the
-        start_internal and pid methods (and maybe failed_internal and
+        _start_internal and pid methods (and maybe _failed_internal and
         name as well).
         name as well).
         """
         """
         self._boss.stop_process(self._process, self._address)
         self._boss.stop_process(self._process, self._address)
@@ -213,7 +213,7 @@ class Component:
         if not self.running():
         if not self.running():
             raise ValueError("Can't fail component that isn't running")
             raise ValueError("Can't fail component that isn't running")
         self.__state = STATE_STOPPED
         self.__state = STATE_STOPPED
-        self.failed_internal()
+        self._failed_internal()
         # If it is a core component or the needed component failed to start
         # If it is a core component or the needed component failed to start
         # (including it stopped really soon)
         # (including it stopped really soon)
         if self._kind == 'core' or \
         if self._kind == 'core' or \
@@ -227,7 +227,7 @@ class Component:
             logger.warn(BIND10_COMPONENT_RESTART, self.name())
             logger.warn(BIND10_COMPONENT_RESTART, self.name())
             self.start()
             self.start()
 
 
-    def failed_internal(self):
+    def _failed_internal(self):
         """
         """
         This method is called from failed. You can replace it if you need
         This method is called from failed. You can replace it if you need
         some specific behaviour when the component crashes. The default
         some specific behaviour when the component crashes. The default
@@ -265,7 +265,7 @@ class Component:
         This returns None in case it is not yet running.
         This returns None in case it is not yet running.
 
 
         You probably want to override this method if you're providing custom
         You probably want to override this method if you're providing custom
-        start_internal.
+        _start_internal.
         """
         """
         return self._procinfo.pid if self._procinfo else None
         return self._procinfo.pid if self._procinfo else None
 
 

+ 3 - 3
src/lib/python/isc/bind10/special_component.py

@@ -27,13 +27,13 @@ class SockCreator(Component):
         Component.__init__(self, process, boss, kind)
         Component.__init__(self, process, boss, kind)
         self.__creator = None
         self.__creator = None
 
 
-    def start_internal(self):
+    def _start_internal(self):
         self._boss.curproc = 'b10-sockcreator'
         self._boss.curproc = 'b10-sockcreator'
         self.__creator = isc.bind10.sockcreator.Creator(LIBEXECDIR + ':' +
         self.__creator = isc.bind10.sockcreator.Creator(LIBEXECDIR + ':' +
                                                         os.environ['PATH'])
                                                         os.environ['PATH'])
         self._boss.register_process(self.pid(), self)
         self._boss.register_process(self.pid(), self)
 
 
-    def stop_internal(self):
+    def _stop_internal(self):
         if self.__creator is None:
         if self.__creator is None:
             return
             return
         self.__creator.terminate()
         self.__creator.terminate()
@@ -55,7 +55,7 @@ class Msgq(Component):
         Component.__init__(self, process, boss, kind)
         Component.__init__(self, process, boss, kind)
         self._start_func = boss.start_msgq
         self._start_func = boss.start_msgq
 
 
-    def stop_internal(self):
+    def _stop_internal(self):
         pass # Wait for the boss to actually kill it. There's no stop command.
         pass # Wait for the boss to actually kill it. There's no stop command.
 
 
 class CfgMgr(Component):
 class CfgMgr(Component):

+ 14 - 14
src/lib/python/isc/bind10/tests/component_test.py

@@ -103,28 +103,28 @@ class ComponentTests(BossUtils, unittest.TestCase):
 
 
     def __start(self):
     def __start(self):
         """
         """
-        Mock function, installed into the component into start_internal.
+        Mock function, installed into the component into _start_internal.
         This only notes the component was "started".
         This only notes the component was "started".
         """
         """
         self.__start_called = True
         self.__start_called = True
 
 
     def __stop(self):
     def __stop(self):
         """
         """
-        Mock function, installed into the component into stop_internal.
+        Mock function, installed into the component into _stop_internal.
         This only notes the component was "stopped".
         This only notes the component was "stopped".
         """
         """
         self.__stop_called = True
         self.__stop_called = True
 
 
     def __fail(self):
     def __fail(self):
         """
         """
-        Mock function, installed into the component into failed_internal.
+        Mock function, installed into the component into _failed_internal.
         This only notes the component called the method.
         This only notes the component called the method.
         """
         """
         self.__failed_called = True
         self.__failed_called = True
 
 
     def __fail_to_start(self):
     def __fail_to_start(self):
         """
         """
-        Mock function. It can be installed into the component's start_internal
+        Mock function. It can be installed into the component's _start_internal
         to simulate a component that fails to start by raising an exception.
         to simulate a component that fails to start by raising an exception.
         """
         """
         orig_started = self.__start_called
         orig_started = self.__start_called
@@ -144,9 +144,9 @@ class ComponentTests(BossUtils, unittest.TestCase):
         kind of tests and we pretend to be the boss.
         kind of tests and we pretend to be the boss.
         """
         """
         component = Component('No process', self, kind, 'homeless', [])
         component = Component('No process', self, kind, 'homeless', [])
-        component.start_internal = self.__start
-        component.stop_internal = self.__stop
-        component.failed_internal = self.__fail
+        component._start_internal = self.__start
+        component._stop_internal = self.__stop
+        component._failed_internal = self.__fail
         return component
         return component
 
 
     def test_name(self):
     def test_name(self):
@@ -373,7 +373,7 @@ class ComponentTests(BossUtils, unittest.TestCase):
         """
         """
         component = self.__create_component('core')
         component = self.__create_component('core')
         self.__check_startup(component)
         self.__check_startup(component)
-        component.start_internal = self.__fail_to_start
+        component._start_internal = self.__fail_to_start
         self.assertRaises(TestError, component.start)
         self.assertRaises(TestError, component.start)
         self.__check_dead(component)
         self.__check_dead(component)
 
 
@@ -384,7 +384,7 @@ class ComponentTests(BossUtils, unittest.TestCase):
         """
         """
         component = self.__create_component('needed')
         component = self.__create_component('needed')
         self.__check_startup(component)
         self.__check_startup(component)
-        component.start_internal = self.__fail_to_start
+        component._start_internal = self.__fail_to_start
         self.assertRaises(TestError, component.start)
         self.assertRaises(TestError, component.start)
         self.__check_dead(component)
         self.__check_dead(component)
 
 
@@ -395,7 +395,7 @@ class ComponentTests(BossUtils, unittest.TestCase):
         """
         """
         component = self.__create_component('dispensable')
         component = self.__create_component('dispensable')
         self.__check_startup(component)
         self.__check_startup(component)
-        component.start_internal = self.__fail_to_start
+        component._start_internal = self.__fail_to_start
         self.assertRaises(TestError, component.start)
         self.assertRaises(TestError, component.start)
         self.__check_restarted(component)
         self.__check_restarted(component)
 
 
@@ -447,20 +447,20 @@ class TestComponent(Component):
         """
         """
         self.__owner.log.append((self.__name, event))
         self.__owner.log.append((self.__name, event))
 
 
-    def start_internal(self):
+    def _start_internal(self):
         self.log('start')
         self.log('start')
 
 
-    def stop_internal(self):
+    def _stop_internal(self):
         self.log('stop')
         self.log('stop')
 
 
-    def failed_internal(self):
+    def _failed_internal(self):
         self.log('failed')
         self.log('failed')
 
 
 class FailComponent(Component):
 class FailComponent(Component):
     """
     """
     A mock component that fails whenever it is started.
     A mock component that fails whenever it is started.
     """
     """
-    def start_internal(self):
+    def _start_internal(self):
         raise TestError("test error")
         raise TestError("test error")
 
 
 class ConfiguratorTest(BossUtils, unittest.TestCase):
 class ConfiguratorTest(BossUtils, unittest.TestCase):