def test_backdoor_port(self): # backdoor port should get passed to the service being launched self.config(backdoor_port=1234) svc = service.Service() launcher = service.launch(svc) self.assertEqual(1234, svc.backdoor_port) launcher.stop()
def _spawn_service(self, workers=1, *args, **kwargs): self.workers = workers pid = os.fork() if pid == 0: os.setsid() # NOTE(johannes): We can't let the child processes exit back # into the unit test framework since then we'll have multiple # processes running the same tests (and possibly forking more # processes that end up in the same situation). So we need # to catch all exceptions and make sure nothing leaks out, in # particular SystemExit, which is raised by sys.exit(). We use # os._exit() which doesn't have this problem. status = 0 try: serv = ServiceWithTimer() launcher = service.launch(serv, workers=workers) launcher.wait(*args, **kwargs) except SystemExit as exc: status = exc.code except BaseException: # We need to be defensive here too try: traceback.print_exc() except BaseException: print("Couldn't print traceback") status = 2 # Really exit os._exit(status) return pid
def test_graceful_shutdown(self): # test that services are given a chance to clean up: svc = _Service() launcher = service.launch(svc) # wait on 'init' so we know the service had time to start: svc.init.wait() launcher.stop() self.assertTrue(svc.cleaned_up) self.assertTrue(svc._done.ready())
def test_graceful_shutdown(self): # test that services are given a chance to clean up: svc = _Service() launcher = service.launch(svc) # wait on 'init' so we know the service had time to start: svc.init.wait() launcher.stop() self.assertTrue(svc.cleaned_up) self.assertTrue(svc._done.ready()) # make sure stop can be called more than once. (i.e. play nice with # unit test fixtures in nova bug #1199315) launcher.stop()
def test_backdoor_port(self): self.config(backdoor_port="1234") sock = self.mox.CreateMockAnything() self.mox.StubOutWithMock(eventlet, "listen") self.mox.StubOutWithMock(eventlet, "spawn_n") eventlet.listen(("localhost", 1234)).AndReturn(sock) sock.getsockname().AndReturn(("127.0.0.1", 1234)) eventlet.spawn_n(eventlet.backdoor.backdoor_server, sock, locals=mox.IsA(dict)) self.mox.ReplayAll() svc = service.Service() launcher = service.launch(svc) self.assertEqual(svc.backdoor_port, 1234) launcher.stop()
def test_backdoor_port_range_one_inuse(self): self.config(backdoor_port="8800:8900") sock = self.mox.CreateMockAnything() self.mox.StubOutWithMock(eventlet, "listen") self.mox.StubOutWithMock(eventlet, "spawn_n") eventlet.listen(("localhost", 8800)).AndRaise(socket.error(errno.EADDRINUSE, "")) eventlet.listen(("localhost", 8801)).AndReturn(sock) sock.getsockname().AndReturn(("127.0.0.1", 8801)) eventlet.spawn_n(eventlet.backdoor.backdoor_server, sock, locals=mox.IsA(dict)) self.mox.ReplayAll() svc = service.Service() launcher = service.launch(svc) self.assertEqual(svc.backdoor_port, 8801) launcher.stop()
def test_backdoor_port(self): self.config(backdoor_port='1234') sock = self.mox.CreateMockAnything() self.mox.StubOutWithMock(eventlet, 'listen') self.mox.StubOutWithMock(eventlet, 'spawn_n') eventlet.listen(('localhost', 1234)).AndReturn(sock) sock.getsockname().AndReturn(('127.0.0.1', 1234)) eventlet.spawn_n(eventlet.backdoor.backdoor_server, sock, locals=mox.IsA(dict)) self.mox.ReplayAll() svc = service.Service() launcher = service.launch(svc) self.assertEqual(svc.backdoor_port, 1234) launcher.stop()
def test_backdoor_port_range_one_inuse(self): self.config(backdoor_port='8800:8900') sock = self.mox.CreateMockAnything() self.mox.StubOutWithMock(eventlet, 'listen') self.mox.StubOutWithMock(eventlet, 'spawn_n') eventlet.listen( ('localhost', 8800)).AndRaise(socket.error(errno.EADDRINUSE, '')) eventlet.listen(('localhost', 8801)).AndReturn(sock) sock.getsockname().AndReturn(('127.0.0.1', 8801)) eventlet.spawn_n(eventlet.backdoor.backdoor_server, sock, locals=mox.IsA(dict)) self.mox.ReplayAll() svc = service.Service() launcher = service.launch(svc) self.assertEqual(svc.backdoor_port, 8801) launcher.stop()
def test_multiple_worker(self, mock_launch): svc = service.Service() service.launch(svc, workers=3) mock_launch.assert_called_with(svc, workers=3)
def _test_launch_single(self, workers, mock_launch): svc = service.Service() service.launch(svc, workers=workers) mock_launch.assert_called_with(svc)