def test_unix_server(self): sockpath = os.path.join(os.getcwd(), 'test.{0}.sock'.format(os.getpid())) sockurl = 'unix://' + sockpath context = RpcContext() context.register_service('test', TestService) server = Server() server.rpc = context server.start(sockurl) threading.Thread(target=server.serve_forever, daemon=True).start() # Spin until server is ready while not os.path.exists(sockpath): time.sleep(0.1) client = Client() client.connect(sockurl) self.assertTrue(client.connected) self.assertEqual(client.call_sync('test.hello', 'freenas'), 'Hello World, freenas') client.disconnect() server.close() os.unlink(sockpath)
def init_server(self, address): self.server = Server(self) self.server.rpc = self.rpc self.server.streaming = True self.server.start(address, transport_options={'permissions': 0o777}) thread = Thread(target=self.server.serve_forever) thread.name = 'ServerThread' thread.daemon = True thread.start()
def init_rpc_server(self): self.server = Server(self) self.server.rpc = self.rpc self.rpc.streaming_enabled = True self.rpc.streaming_burst = 16 self.server.streaming = True self.server.start(DEFAULT_SOCKET_ADDRESS, transport_options={'permissions': 0o666}) thread = threading.Thread(target=self.server.serve_forever, name='RPC server thread', daemon=True) thread.start()
def __init__(self): self.logger = logging.getLogger(self.__class__.__name__) self.msock = msock.client.Client() self.msock.on_closed = self.on_msock_close self.rpc_fd = -1 self.connection_id = None self.jobs = [] self.state = ConnectionState.OFFLINE self.config = None self.keepalive = None self.connected_at = None self.cv = Condition() self.rpc = RpcContext() self.client = Client() self.server = Server() self.middleware_endpoint = None
def __init__(self): self.store = collections.deque() self.lock = threading.Lock() self.seqno = 0 self.rpc_server = Server(self) self.boot_id = str(uuid.uuid4()) self.exiting = False self.server = None self.servers = [] self.klog_reader = None self.flush = False self.flush_thread = None self.datastore = None self.started_at = datetime.utcnow() self.rpc = RpcContext() self.rpc.register_service_instance('logd.logging', LoggingService(self)) self.rpc.register_service_instance('logd.debug', DebugService()) self.cv = threading.Condition()