github.com/swiftstack/proxyfs@v0.0.0-20201223034610-5434d919416e/jrpcfs/test/client_test.py (about)

     1  import json
     2  import requests
     3  import socket
     4  
     5  # This version works as well, leaving here as a reference
     6  #def main():
     7  #    args = {'VolumeName' : "CommonVolume", 'MountOptions': 0, 'AuthUser': "balajirao"}
     8  #
     9  #    payload = {
    10  #        "method": "Server.RpcMount",
    11  #        "params": [args],
    12  #        "id": 1,
    13  #    }
    14  #
    15  #    s = socket.create_connection(("localhost", 12345))
    16  #    s.sendall(json.dumps((payload)))
    17  #    rdata = s.recv(1024)
    18  #
    19  #    print "received data:", rdata
    20  #    print "decoded received data:", json.loads(rdata)
    21  #
    22  #    s.close
    23  
    24  def main():
    25      args = {'VolumeName' : "CommonVolume", 'MountOptions': 0, 'AuthUser': "balajirao"}
    26  
    27      id = 0
    28      payload = {
    29          "method": "Server.RpcMount",
    30          "params": [args],
    31          "jsonrpc": "2.0",
    32          "id": id,
    33      }
    34  
    35      s = socket.create_connection(("localhost", 12345))
    36      data = json.dumps((payload))
    37      print "sending data:", data
    38      s.sendall(data)
    39  
    40      # This will actually have to loop if resp is bigger
    41      rdata = s.recv(1024)
    42  
    43      #print "received data:", rdata
    44      resp = json.loads(rdata)
    45      #print "decoded received data:", resp
    46  
    47      if resp["id"] != id:
    48          raise Exception("expected id=%s, received id=%s: %s" %(id, resp["id"], resp["error"]))
    49  
    50      if resp["error"] is not None:
    51          raise Exception(resp["error"])
    52  
    53  
    54      print "Returned MountID:", resp["result"]["MountID"]
    55  
    56      s.close
    57  
    58  
    59  if __name__ == "__main__":
    60      main()