def generate(guid=None): ret = guid or msg.Guid() ret.a = random.randint(0, 0xffffffff) ret.b = random.randint(0, 0xffffffff) ret.c = random.randint(0, 0xffffffff) ret.d = random.randint(0, 0xffffffff) return ret
def fromTuple(x): ret = msg.Guid() ret.a = x[0] ret.b = x[1] ret.c = x[2] ret.d = x[3] return ret
def fromStr(s): ret = msg.Guid() s = s.split('-') ret.a = int(s[0], 16) ret.b = int(s[1], 16) ret.c = int(s[2], 16) ret.d = int(s[3], 16) return ret
def test(): global PARAM logging.basicConfig(level=logging.DEBUG) socket = gevent.socket.socket() socket.connect((PARAM.MDS_IP, int(PARAM.MDS_PORT))) guid = msg.Guid() guid.a = 10 guid.b = 22 guid.c = 30 guid.d = 40 stub = rpc.RpcStub(guid, socket, mds.MDS) arg = msg.GetChunkServers_Request() ret = stub.callMethod('GetChunkServers', arg) s2 = gevent.socket.socket() s2.connect((ret.random[0].ServiceAddress, ret.random[0].ServicePort)) stub2 = rpc.RpcStub(guid, s2, ChunkServer.ChunkServer) if raw_input('you want to NewChunk ? ') == 'y': arg2 = msg.NewChunk_Request() arg2.size = 32 arg2.count = 2 ret2 = stub2.callMethod('NewChunk', arg2) print ret2.guids if raw_input('you want to assembleVolume ? ') == 'y': req_assemble = msg.AssembleVolume_Request() req_assemble.volume.size = 32 Guid.assign(req_assemble.volume.guid, ret2.guids[-1]) res_assemble = stub2.callMethod('AssembleVolume', req_assemble) print 'access_point:', res_assemble.access_point if raw_input('you want to DisassembleVolume ? ') == 'y': req_disassemble = msg.DisassembleVolume_Request() req_disassemble.access_point = res_assemble.access_point print 'req_disassemble.access_point:', req_disassemble.access_point stub2.callMethod('DisassembleVolume', req_disassemble) if raw_input('you want to DeleteChunk ? ') == 'y': arg3 = msg.DeleteChunk_Request() t = arg3.guids.add() Guid.assign(t, ret2.guids[0]) t = arg3.guids.add() Guid.assign(t, ret2.guids[1]) ret_Del = stub2.callMethod('DeleteChunk', arg3)
import rpc, logging import messages_pb2 as msg import client_messages_pb2 as clmsg import mds, ChkSvr_mock import gevent.socket from Client_test import Client import guid as Guid import scandev import block.dm as dm logging.basicConfig(level=logging.DEBUG) socket = gevent.socket.socket() socket.connect(('192.168.0.12', 6767)) guid = msg.Guid() guid.a = 10 guid.b = 22 guid.c = 30 guid.d = 40 MI = {} req = getattr(clmsg, 'NewVolume_Request', None) res = getattr(clmsg, 'NewVolume_Response', type(None)) MI['NewVolume'] = (req, res) req = getattr(clmsg, 'DeleteVolume_Request', None) res = getattr(clmsg, 'DeleteVolume_Response', type(None)) MI['DeleteVolume'] = (req, res) print MI stub = rpc.RpcStub(guid, socket, Client, MI) arg = clmsg.NewVolume_Request() arg.volume_name = 'ssVolume2'