示例#1
0
 def test_component_kill(self):
     """
     Check the kill is propagated. The case when component wasn't started
     yet is already tested elsewhere.
     """
     class Process:
         def __init__(self):
             self.killed = False
             self.terminated = False
         def kill(self):
             self.killed = True
         def terminate(self):
             self.terminated = True
     process = Process()
     class ProcInfo:
         def __init__(self):
             self.process = process
             self.pid = 42
     component = Component('component', self, 'needed', 'Address',
                           [], ProcInfo)
     component.start()
     self.assertTrue(component.is_running())
     component.kill()
     self.assertTrue(process.terminated)
     self.assertFalse(process.killed)
     process.terminated = False
     component.kill(True)
     self.assertTrue(process.killed)
     self.assertFalse(process.terminated)
示例#2
0
    def __create_component(self, kind):
        """
        Convenience function that creates a component of given kind
        and installs the mock functions into it so we can hook up into
        its behaviour.

        The process used is some nonsense, as this isn't used in this
        kind of tests and we pretend to be the bundy-init.
        """
        component = Component('No process', self, kind, 'homeless', [])
        component._start_internal = self.__start
        component._stop_internal = self.__stop
        component._failed_internal = self.__fail
        return component
示例#3
0
 def test_component_start_stop_internal(self):
     """
     Test the behavior of _stop_internal and _start_internal.
     """
     component = Component('component', self, 'needed', 'Address')
     component.start()
     self.assertTrue(component.is_running())
     self.assertEqual('component', self.__start_simple_params)
     component.pid = lambda: 42
     component.stop()
     self.assertFalse(component.is_running())
     self.assertEqual(('component', 'Address', 42),
                      self.__stop_process_params)
示例#4
0
    def test_kill_unstarted(self):
        """
        Try to kill the component if it's not started. Should not fail.

        We do not try to kill a running component, as we should not start
        it during unit tests.
        """
        component = Component('component', self, 'needed')
        component.kill()
        component.kill(True)
示例#5
0
 def test_component_attributes(self):
     """
     Test the default attributes of Component (not BaseComponent) and
     some of the methods we might be allowed to call.
     """
     class TestProcInfo:
         def __init__(self):
             self.pid = 42
     component = Component('component', self, 'needed', 'Address',
                           ['hello'], TestProcInfo)
     self.assertEqual('component', component._process)
     self.assertEqual('component', component.name())
     self.assertIsNone(component._procinfo)
     self.assertIsNone(component.pid())
     self.assertEqual(['hello'], component._params)
     self.assertEqual('Address', component._address)
     self.assertFalse(component.is_running())
     self.assertEqual({}, self.__registered_processes)
     component.start()
     self.assertTrue(component.is_running())
     # Some versions of unittest miss assertIsInstance
     self.assertTrue(isinstance(component._procinfo, TestProcInfo))
     self.assertEqual(42, component.pid())
     self.assertEqual(component, self.__registered_processes.get(42))
示例#6
0
 def __init__(self, process, bundy_init, kind, address=None, params=None):
     Component.__init__(self, process, bundy_init, kind, 'Auth', None,
                        bundy_init.start_auth)
示例#7
0
 def __init__(self, process, bundy_init, kind, address=None, params=None):
     Component.__init__(self, process, bundy_init, kind, 'ConfigManager',
                        None, bundy_init.start_cfgmgr)
示例#8
0
 def __init__(self, process, bundy_init, kind, address=None, params=None):
     Component.__init__(self, process, bundy_init, kind, 'Cmdctl', None,
                        bundy_init.start_cmdctl)
示例#9
0
 def __init__(self, process, bundy_init, kind, address=None, params=None):
     Component.__init__(self, process, bundy_init, kind, 'Resolver', None,
                        bundy_init.start_resolver)
示例#10
0
 def __init__(self, process, bundy_init, kind, address=None, params=None):
     Component.__init__(self, process, bundy_init, kind, 'ConfigManager',
                        None, bundy_init.start_cfgmgr)
示例#11
0
 def __init__(self, process, bundy_init, kind, address=None, params=None):
     Component.__init__(self, process, bundy_init, kind, None, None,
                        bundy_init.start_msgq)
示例#12
0
 def __init__(self, process, bundy_init, kind, address=None, params=None):
     Component.__init__(self, process, bundy_init, kind, 'Cmdctl', None,
                        bundy_init.start_cmdctl)
示例#13
0
 def __init__(self, process, bundy_init, kind, address=None, params=None):
     Component.__init__(self, process, bundy_init, kind, 'Resolver', None,
                        bundy_init.start_resolver)