Browse Source

[213] Don't fail component which isn't running

Michal 'vorner' Vaner 13 years ago
parent
commit
eaa56b3d00

+ 2 - 0
src/lib/python/isc/bind10/component.py

@@ -113,6 +113,8 @@ class Component:
         If you try to call failed on a component that is not running,
         If you try to call failed on a component that is not running,
         a ValueError is raised.
         a ValueError is raised.
         """
         """
+        if not self.running():
+            raise ValueError("Can't fail component that isn't running")
         self.failed_internal()
         self.failed_internal()
         self.__running = False
         self.__running = False
         # 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

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

@@ -102,6 +102,9 @@ class ComponentTests(unittest.TestCase):
         self.assertFalse(self.__stop_called)
         self.assertFalse(self.__stop_called)
         self.assertFalse(self.__failed_called)
         self.assertFalse(self.__failed_called)
         self.assertFalse(component.running())
         self.assertFalse(component.running())
+        # We can't stop or fail the component yet
+        self.assertRaises(ValueError, component.stop)
+        self.assertRaises(ValueError, component.failed)
 
 
     def check_started(self, component):
     def check_started(self, component):
         """
         """
@@ -173,6 +176,8 @@ class ComponentTests(unittest.TestCase):
         self.assertFalse(component.running())
         self.assertFalse(component.running())
         # Check it can't be stopped twice
         # Check it can't be stopped twice
         self.assertRaises(ValueError, component.stop)
         self.assertRaises(ValueError, component.stop)
+        # Or failed
+        self.assertRaises(ValueError, component.failed)
         # But it can be started again if it is stopped
         # But it can be started again if it is stopped
         # (no more checking here, just it doesn't crash)
         # (no more checking here, just it doesn't crash)
         component.start()
         component.start()