예제 #1
0
    def test_dict_to_protobuf(self):
        pb = bess_msg.CreatePortResponse()
        pb.error.err = 1
        pb.error.errmsg = 'bar'
        pb.error.details = ''
        pb.name = 'foo'

        msg_dict = {
            'error': {
                'err': 1,
                'errmsg': 'bar',
            },
            'name': 'foo'
        }

        msg = proto_conv.dict_to_protobuf(msg_dict,
                                          bess_msg.CreatePortResponse)
        self.assertEqual(msg, pb)

        pb = bess_msg.CreateModuleRequest()
        pb.name = 'm1'
        pb.mclass = 'bpf'

        kv = {
            'name': 'm1',
            'mclass': 'bpf',
        }
        msg = proto_conv.dict_to_protobuf(kv, bess_msg.CreateModuleRequest)
        self.assertEqual(msg, pb)
예제 #2
0
    def test_protobuf_to_dict(self):
        pb = bess_msg.CreatePortResponse()
        pb.error.code = 1
        pb.error.errmsg = 'bar'
        pb.name = 'foo'

        true_result = {
            'error': {
                'code': 1,
                'errmsg': 'bar',
            },
            'name': 'foo'
        }
        result = pb_conv.protobuf_to_dict(pb)
        self.assertEqual(true_result, result)
예제 #3
0
파일: bess_test.py 프로젝트: vivi/bess
 def CreatePort(self, request, context):
     response = bess_msg.CreatePortResponse()
     response.name = request.name
     return response