Example #1
0
def connect(host, cookie, cmd, idir, status=''):
    # set communication channel to our Erlang node, user must specify host, node
    # name, cookie.
    addr = socket.gethostbyaddr(host)
    hostname, aliaslist, addresslist = socket.gethostbyaddr(host)
    addr = addresslist[0]
    name = "mynode"
    node = name + "@" + hostname
    # initialize the erl_connect module, see http://www.erlang.org/doc/man/erl_connect.html
    ret  = pyerl.connect_xinit(host, name, node, addr, cookie, 1)
    sock = pyerl.xconnect(addr, name)
    if  sock < 0: # fail to connect
        print "Fail to connect to Erlang node"
        sys.exit(0)
#    print "connect to node=%s, addr=%s, sock=%s" % (node, addr, sock)

    # call test code
    server = "bapp_server"
    if  status:
        eterm = get_status(sock, server, name, status)
    else:
        eterm = test_black_box(sock, server, cmd, idir)
    print "server reply:", eterm

    # close connection to our server
    pyerl.close_connection(sock)
 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 #3
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")