def _test_server_close(cache): server_ctl = server.SSHUserPassController(username=getpass.getuser(), password="******") port = None LAST_INDEX = 40000 + 5000 for port in range(40000, LAST_INDEX + 1): try: logger.info("Create server on port %d", port) ns = server.SSHServer(server_ctl, port=port, host_key="tests/host_key", debug=SERVER_DEBUG) break except socket.error as error: logger.info("Got exception: %s %d %d", str(error), error.errno, errno.EADDRINUSE) if error.errno != errno.EADDRINUSE or port == LAST_INDEX: raise logger.info("Connect to server on port %d", port) session = conn.SSHSession("127.0.0.1", password="******", port=port, debug=CLIENT_DEBUG) session.close() # force closing of cached client sessions cache.flush() logger.debug("Closing") ns.close() logger.debug("Joining") ns.join() # import time # time.sleep(.1) for i in range(0, 10): logger.debug("Starting %d iteration", i) ns = server.SSHServer(server_ctl, port=port, host_key="tests/host_key", debug=SERVER_DEBUG) logger.info("Connect to server on port %d", port) session = conn.SSHSession("127.0.0.1", password="******", port=port, debug=CLIENT_DEBUG) session.close() # force closing of cached client sessions cache.flush() logger.debug("Closing") ns.close() logger.debug("Joining") ns.join() logger.debug("Test Complete")
def _test_multi_open(client_cache): logger.info("Create Server") server_ctl = server.SSHUserPassController(username=getpass.getuser(), password="******") ns = server.SSHServer(server_ctl, port=NC_PORT, host_key="tests/host_key", debug=SERVER_DEBUG) port = ns.port logger.info("Open sessions") sessions = [ conn.SSHSession( "127.0.0.1", password="******", port=port, debug=CLIENT_DEBUG, cache=client_cache) for unused in range(0, 25) ] logger.info("Close sessions") for session in sessions: session.close() session = conn.SSHSession("127.0.0.1", password="******", port=port, debug=CLIENT_DEBUG) # These should be cached logger.info("Re-opening") sessions = [ conn.SSHSession("127.0.0.1", password="******", port=port, debug=CLIENT_DEBUG) for unused in range(0, 25) ] logger.info("Re-closeing") for session in sessions: session.close() logger.info("Flushing socket cache") client_cache.flush() # These should be cached logger.info("Re-re-opening") sessions = [ conn.SSHSession("127.0.0.1", password="******", port=port, debug=CLIENT_DEBUG) for unused in range(0, 25) ] logger.info("Re-re-closing") for session in sessions: session.close() # force closing of cached client sessions logger.info("Flushing socket cache") client_cache.flush() # Close down the server and join it to make sure it's closed logger.info("Closing server") ns.close() logger.info("Joining server") ns.join() # Delete the server so that we don't end up with a bunch of logging going on on exit. del ns del server_ctl
def setup_module(module): del module # unused global ssh_server logging.basicConfig(level=logging.DEBUG) if ssh_server is not None: logger.error("XXX Called setup_module multiple times") else: server_ctl = server.SSHUserPassController(username=getpass.getuser(), password="******") ssh_server = server.SSHServer(server_ctl, host_key="tests/host_key", debug=SERVER_DEBUG) setup_module.init = True