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
         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.
         """
@@ -134,13 +134,13 @@ class Component:
         self.__state = STATE_RUNNING
         self.__start_time = time.time()
         try:
-            self.start_internal()
+            self._start_internal()
         except Exception as e:
             logger.error(BIND10_COMPONENT_START_EXCEPTION, self.name(), e)
             self.failed()
             raise
 
-    def start_internal(self):
+    def _start_internal(self):
         """
         This method does the actual starting of a process. If you need to
         change the way the component is started, replace this method.
@@ -153,7 +153,7 @@ class Component:
         boss.start_simple is performed.
 
         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.
         """
         # This one is not tested. For one, it starts a real process
@@ -172,7 +172,7 @@ class Component:
     def stop(self):
         """
         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.
 
         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")
         logger.info(BIND10_COMPONENT_STOP, self.name())
         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.
         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
-        start_internal and pid methods (and maybe failed_internal and
+        _start_internal and pid methods (and maybe _failed_internal and
         name as well).
         """
         self._boss.stop_process(self._process, self._address)
@@ -213,7 +213,7 @@ class Component:
         if not self.running():
             raise ValueError("Can't fail component that isn't running")
         self.__state = STATE_STOPPED
-        self.failed_internal()
+        self._failed_internal()
         # If it is a core component or the needed component failed to start
         # (including it stopped really soon)
         if self._kind == 'core' or \
@@ -227,7 +227,7 @@ class Component:
             logger.warn(BIND10_COMPONENT_RESTART, self.name())
             self.start()
 
-    def failed_internal(self):
+    def _failed_internal(self):
         """
         This method is called from failed. You can replace it if you need
         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.
 
         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
 

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

@@ -27,13 +27,13 @@ class SockCreator(Component):
         Component.__init__(self, process, boss, kind)
         self.__creator = None
 
-    def start_internal(self):
+    def _start_internal(self):
         self._boss.curproc = 'b10-sockcreator'
         self.__creator = isc.bind10.sockcreator.Creator(LIBEXECDIR + ':' +
                                                         os.environ['PATH'])
         self._boss.register_process(self.pid(), self)
 
-    def stop_internal(self):
+    def _stop_internal(self):
         if self.__creator is None:
             return
         self.__creator.terminate()
@@ -55,7 +55,7 @@ class Msgq(Component):
         Component.__init__(self, process, boss, kind)
         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.
 
 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):
         """
-        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".
         """
         self.__start_called = True
 
     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".
         """
         self.__stop_called = True
 
     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.
         """
         self.__failed_called = True
 
     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.
         """
         orig_started = self.__start_called
@@ -144,9 +144,9 @@ class ComponentTests(BossUtils, unittest.TestCase):
         kind of tests and we pretend to be the boss.
         """
         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
 
     def test_name(self):
@@ -373,7 +373,7 @@ class ComponentTests(BossUtils, unittest.TestCase):
         """
         component = self.__create_component('core')
         self.__check_startup(component)
-        component.start_internal = self.__fail_to_start
+        component._start_internal = self.__fail_to_start
         self.assertRaises(TestError, component.start)
         self.__check_dead(component)
 
@@ -384,7 +384,7 @@ class ComponentTests(BossUtils, unittest.TestCase):
         """
         component = self.__create_component('needed')
         self.__check_startup(component)
-        component.start_internal = self.__fail_to_start
+        component._start_internal = self.__fail_to_start
         self.assertRaises(TestError, component.start)
         self.__check_dead(component)
 
@@ -395,7 +395,7 @@ class ComponentTests(BossUtils, unittest.TestCase):
         """
         component = self.__create_component('dispensable')
         self.__check_startup(component)
-        component.start_internal = self.__fail_to_start
+        component._start_internal = self.__fail_to_start
         self.assertRaises(TestError, component.start)
         self.__check_restarted(component)
 
@@ -447,20 +447,20 @@ class TestComponent(Component):
         """
         self.__owner.log.append((self.__name, event))
 
-    def start_internal(self):
+    def _start_internal(self):
         self.log('start')
 
-    def stop_internal(self):
+    def _stop_internal(self):
         self.log('stop')
 
-    def failed_internal(self):
+    def _failed_internal(self):
         self.log('failed')
 
 class FailComponent(Component):
     """
     A mock component that fails whenever it is started.
     """
-    def start_internal(self):
+    def _start_internal(self):
         raise TestError("test error")
 
 class ConfiguratorTest(BossUtils, unittest.TestCase):