Parcourir la source

[213] Check the kind passed to the component

And raise if it makes no sense.
Michal 'vorner' Vaner il y a 13 ans
Parent
commit
26841bf1f0

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

@@ -56,6 +56,8 @@ class Component:
             doesn't start or crashes for some reason, the system simply tries
             to restart it and keeps running.
         """
+        if kind not in ['core', 'needed', 'dispensable']:
+            raise ValueError('Component kind can not be ' + kind)
         self.__running = False
         # Dead like really dead. No resurrection possible.
         self.__dead = False

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

@@ -340,6 +340,14 @@ class ComponentTests(unittest.TestCase):
         self.assertRaises(TestError, component.start)
         self.__check_restarted(component)
 
+    def test_bad_kind(self):
+        """
+        Test the component rejects nonsensual kinds. This includes bad
+        capitalization.
+        """
+        for kind in ['Core', 'CORE', 'nonsense', 'need ed', 'required']:
+            self.assertRaises(ValueError, Component, 'No process', self, kind)
+
 if __name__ == '__main__':
     isc.log.init("bind10") # FIXME Should this be needed?
     isc.log.resetUnitTestRootLogger()