Example #1
0
def get_status(sock, server, node, uinput):
    what  = uinput[0]
    api   = "handle_call"
    status= pyerl.mk_atom("status")
    if  what == 'node':
        value = uinput[-1]
        val = pyerl.mk_atom(value)
    elif what == 'guid':
        value = uinput[-1]
        val = pyerl.mk_int(int(value))
    elif what == 'pid':
        rnode = uinput[1] # remote node
        pid   = uinput[2] # remote pid
        nodename = pyerl.mk_atom(rnode)
        ppid = pyerl.mk_string(pid)
        val   = pyerl.mk_tuple((nodename, ppid))
    else:
        raise Exception('Unknown message: %s' %  what)
    what  = pyerl.mk_atom(what)
    pid   = pyerl.mk_pid("node", 1, 2, 3)
    state = pyerl.mk_atom("atom") # passed state to server is irrelevant in this call
    tup   = pyerl.mk_tuple((status, what, val))
    args  = pyerl.mk_list([tup, pid, state])
    eterm = pyerl.rpc(sock, server, api, args)
    return eterm
Example #2
0
def test_black_box(sock, server, icmd, idir):
    api = "handle_call"
    atom = pyerl.mk_atom("process")
    cmd  = pyerl.mk_string(icmd)
    name = pyerl.mk_string(idir)
    tup = pyerl.mk_tuple((atom, cmd, name))
    pid = pyerl.mk_pid("node", 1, 2, 3)
    state = pyerl.mk_atom("atom") # passed state to server is irrelevant in this call
    args = pyerl.mk_list([tup, pid, state])
    eterm = pyerl.rpc(sock, server, api, args)
    return eterm
 def test_rpc(self):
     host = "localhost"
     name = "test"
     node = name + "@" + host
     cookie = "TESTCOOKIE"
     ret = pyerl.connect_xinit(host, name, node, "127.0.0.1", cookie, 1)
     self.assertEqual(ret, 1);
     retry = 0
     while True:
         time.sleep(1)
         sock = pyerl.xconnect("127.0.0.1", "node1")
         if sock > 0: break
         if retry > 3: self.fail()
         retry += 1
     self.assertEqual(sock > 0, True)
     atom = pyerl.mk_atom("ping")
     args = pyerl.mk_list([atom]);
     eterm = pyerl.rpc(sock, "pingpong", "ping", args);
     ret = pyerl.close_connection(sock);
     self.assertEqual(ret, 0);
     self.assertEqual(eterm.type, pyerl.ATOM);
     self.assertEqual(eterm.is_atom(), True);
     self.assertEqual(str(eterm), "pong");
Example #4
0
 def test_rpc(self):
     host = "localhost"
     name = "test"
     node = name + "@" + host
     cookie = "TESTCOOKIE"
     ret = pyerl.connect_xinit(host, name, node, "127.0.0.1", cookie, 1)
     self.assertEqual(ret, 1)
     retry = 0
     while True:
         time.sleep(1)
         sock = pyerl.xconnect("127.0.0.1", "node1")
         if sock > 0: break
         if retry > 3: self.fail()
         retry += 1
     self.assertEqual(sock > 0, True)
     atom = pyerl.mk_atom("ping")
     args = pyerl.mk_list([atom])
     eterm = pyerl.rpc(sock, "pingpong", "ping", args)
     ret = pyerl.close_connection(sock)
     self.assertEqual(ret, 0)
     self.assertEqual(eterm.type, pyerl.ATOM)
     self.assertEqual(eterm.is_atom(), True)
     self.assertEqual(str(eterm), "pong")