def _request(self, name, request=None): if not self.is_connected(): raise self.APIError('BESS daemon not connected') req_fn = getattr(self.stub, name) if request is None: request = bess_msg.EmptyRequest() response = req_fn(request) if response.error.err != 0: err = response.error.err errmsg = response.error.errmsg if errmsg == '': errmsg = '(error message is not given)' details = response.error.details if details == '': details = None raise self.Error(err, errmsg, details) if self.debug: req = proto_conv.protobuf_to_dict(request) res = proto_conv.protobuf_to_dict(response) print '====', req_fn._method print '--->', type(request).__name__ if req: pprint.pprint(req) print '<---', type(response).__name__ if res: pprint.pprint(res) return response
def _request(self, name, request=None): if not self.is_connected(): if self.is_connection_broken(): # The channel got abnormally (and asynchronously) disconnected, # but RPCError has not been raised yet? raise self.RPCError('Broken RPC channel') else: raise self.APIError('BESS daemon not connected') req_fn = getattr(self.stub, name) if request is None: request = bess_msg.EmptyRequest() if self.debug: print '====', req_fn._method req = proto_conv.protobuf_to_dict(request) print '--->', type(request).__name__ if req: pprint.pprint(req) try: response = req_fn(request) except grpc._channel._Rendezvous as e: raise self.RPCError(str(e)) if self.debug: print '<---', type(response).__name__ res = proto_conv.protobuf_to_dict(response) if res: pprint.pprint(res) if response.error.err != 0: err = response.error.err errmsg = response.error.errmsg if errmsg == '': errmsg = '(error message is not given)' details = response.error.details if details == '': details = None raise self.Error(err, errmsg, details) return response
def test_protobuf_to_dict(self): pb = bess_msg.CreatePortResponse() pb.error.err = 1 pb.error.errmsg = 'bar' pb.error.details = '' pb.name = 'foo' true_result = { 'error': { 'err': 1, 'errmsg': 'bar', }, 'name': 'foo' } result = proto_conv.protobuf_to_dict(pb) self.assertEqual(true_result, result)
def get_link_status(self, name): request = bess_msg.GetLinkStatusRequest() request.name = name return proto_conv.protobuf_to_dict( self._request('GetLinkStatus', request))