Change in vdsm[master]: add a jsonrpcSeverClient for jsonRPC Server functional test
shaohef at linux.vnet.ibm.com
shaohef at linux.vnet.ibm.com
Thu Jan 24 18:45:43 UTC 2013
ShaoHe Feng has posted comments on this change.
Change subject: add a jsonrpcSeverClient for jsonRPC Server functional test
......................................................................
Patch Set 2: (6 inline comments)
....................................................
File tests/functional/jsonrpcSeverClient.py
Line 1: #
Line 2: # Copyright 2012 Red Hat, Inc.
IBM Corporation
Line 3: #
Line 4: # This program is free software; you can redistribute it and/or modify
Line 5: # it under the terms of the GNU General Public License as published by
Line 6: # the Free Software Foundation; either version 2 of the License, or
Line 43:
Line 44:
Line 45: class jsonRpcServerClient(object):
Line 46:
Line 47: #TODO: spport ssl
Yes, I will remove it.
Line 48: def __init__(self, ip, port, certReq=False, tsPath=None):
Line 49: self._ip = ip
Line 50: self._port = port
Line 51: self._tsPath = tsPath
Line 59: msg = json.dumps(data)
Line 60: msg = msg.encode('utf-8')
Line 61: msize = self._Size.pack(len(msg))
Line 62: resp = msize + msg
Line 63: return resp
agree.
Line 64:
Line 65: def _createRequest(self, method, reqId=None, params=()):
Line 66: return {'jsonrpc': '2.0', "id": reqId, "method": method,
Line 67: "params": params}
Line 78: sock = ssl.wrap_socket(tcp_sock,
Line 79: keyfile=KEYFILE,
Line 80: certfile=CERTFILE,
Line 81: ca_certs=CACERT,
Line 82: cert_reqs=self._cert_reqs)
I'm not sure the RPC server support support long connection. so I used short connection.
I will improve it in future. Now I'm focusing on json RPC functional test.
Line 83: else:
Line 84: sock = tcp_sock
Line 85: sock.settimeout(3) # TBD timeout
Line 86: try:
Line 108:
Line 109: def call(self, method, params=(), reqId=None):
Line 110: if reqId is None:
Line 111: rId = self._reqCounter
Line 112: self._reqCounter += 1
Yes, it is not thread-safe. I will give it a fix value.
And about the sting, I will fix it after server fix it.
Line 113: else:
Line 114: rId = reqId
Line 115: msg = self.buildMessage(self._createRequest(method, rId, params))
Line 116: reply = self.sendMessage(msg)
Line 115: msg = self.buildMessage(self._createRequest(method, rId, params))
Line 116: reply = self.sendMessage(msg)
Line 117: if rId != reply['id']:
Line 118: raise ResIdResponseError("error reqId:%s response, expect %s" %
Line 119: (reply['id'], rId))
yes, it will raise an exception.
just return reply. Let the caller to check the field is 'error' or 'result'
Line 120: return reply['result']
Line 121:
Line 122: def _dynamicAttribute(self, schema):
Line 123: self.dynamicAttr = {}
--
To view, visit http://gerrit.ovirt.org/11283
To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: comment
Gerrit-Change-Id: Ib081e26203638114d7d632489432a50eeea45dd4
Gerrit-PatchSet: 2
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: ShaoHe Feng <shaohef at linux.vnet.ibm.com>
Gerrit-Reviewer: Adam Litke <agl at us.ibm.com>
Gerrit-Reviewer: Antoni Segura Puimedon <asegurap at redhat.com>
Gerrit-Reviewer: Dan Kenigsberg <danken at redhat.com>
Gerrit-Reviewer: Deepak C Shetty <deepakcs at linux.vnet.ibm.com>
Gerrit-Reviewer: Mark Wu <wudxw at linux.vnet.ibm.com>
Gerrit-Reviewer: Royce Lv <lvroyce at linux.vnet.ibm.com>
Gerrit-Reviewer: Saggi Mizrahi <smizrahi at redhat.com>
Gerrit-Reviewer: ShaoHe Feng <shaohef at linux.vnet.ibm.com>
Gerrit-Reviewer: Shu Ming <shuming at linux.vnet.ibm.com>
Gerrit-Reviewer: Vinzenz Feenstra <vfeenstr at redhat.com>
Gerrit-Reviewer: Zhou Zheng Sheng <zhshzhou at linux.vnet.ibm.com>
Gerrit-Reviewer: oVirt Jenkins CI Server
More information about the vdsm-patches
mailing list