示例#1
0
文件: server.py 项目: nfvproject/nepi
 def test_server(self):
     s = server.Server(self.root_dir)
     s.run()
     c = server.Client(self.root_dir)
     c.send_msg("Hola")
     reply = c.read_reply()
     self.assertEqual(reply, "Reply to: Hola")
     c.send_stop()
     reply = c.read_reply()
     self.assertEqual(reply, "Stopping server")
示例#2
0
文件: server.py 项目: nfvproject/nepi
    def test_ssh_server_reconnect(self):
        env = test_util.test_environment()
        user = getpass.getuser()
        # launch server
        python_code = "from nepi.util import server;s=server.Server('%s');\
                s.run()" % self.root_dir
        server.popen_python(python_code,
                            communication=DC.ACCESS_SSH,
                            host="localhost",
                            port=env.port,
                            user=user,
                            agent=True)

        c = server.Client(self.root_dir,
                          communication=DC.ACCESS_SSH,
                          host="localhost",
                          port=env.port,
                          user=user,
                          agent=True)

        c.send_msg("Hola")
        reply = c.read_reply()
        self.assertEqual(reply, "Reply to: Hola")

        # disconnect
        del c

        # reconnect
        c = server.Client(self.root_dir,
                          communication=DC.ACCESS_SSH,
                          host="localhost",
                          port=env.port,
                          user=user,
                          agent=True)

        c.send_msg("Hola")
        reply = c.read_reply()
        self.assertEqual(reply, "Reply to: Hola")

        c.send_stop()
        reply = c.read_reply()
        self.assertEqual(reply, "Stopping server")
示例#3
0
文件: server.py 项目: nfvproject/nepi
 def test_server_long_message(self):
     s = server.Server(self.root_dir)
     s.run()
     c = server.Client(self.root_dir)
     msg = "1" * 1145
     c.send_msg(msg)
     reply = c.read_reply()
     self.assertEqual(reply, ("Reply to: " + msg))
     c.send_stop()
     reply = c.read_reply()
     self.assertEqual(reply, "Stopping server")
示例#4
0
文件: server.py 项目: nfvproject/nepi
 def test_sudo_server(self):
     env = test_util.test_environment()
     user = getpass.getuser()
     # launch server
     python_code = "from nepi.util import server;s=server.Server('%s');\
             s.run()" % self.root_dir
     server.popen_python(python_code, sudo=True)
     c = server.Client(self.root_dir, sudo=True)
     c.send_msg("Hola")
     reply = c.read_reply()
     self.assertEqual(reply, "Reply to: Hola")
     c.send_stop()
     reply = c.read_reply()
     self.assertEqual(reply, "Stopping server")
示例#5
0
文件: proxy.py 项目: nfvproject/nepi
 def __init__(self, ctor_args, root_dir, 
         launch = True, 
         communication = DC.ACCESS_LOCAL,
         host = None, 
         port = None, 
         user = None, 
         ident_key = None, 
         agent = None,
         sudo = False, 
         environment_setup = "",
         clean_root = False):
     if launch:
         python_code = (
                 "from %(classmodule)s import %(classname)s;"
                 "s = %(classname)s%(ctor_args)r;"
                 "s.run()" 
             % dict(
                 classname = self._ServerClass.__name__,
                 classmodule = self._ServerClassModule,
                 ctor_args = ctor_args
             ) )
         proc = server.popen_python(python_code,
                     communication = communication,
                     host = host,
                     port = port, 
                     user = user, 
                     agent = agent,
                     ident_key = ident_key, 
                     sudo = sudo,
                     environment_setup = environment_setup) 
         # Wait for the server to be ready, otherwise nobody
         # will be able to connect to it
         err = []
         helo = "nope"
         while helo:
             helo = proc.stderr.readline()
             if helo == 'SERVER_READY.\n':
                 break
             err.append(helo)
         else:
             raise AssertionError, "Expected 'SERVER_READY.', got: %s" % (''.join(err),)
     # connect client to server
     self._client = server.Client(root_dir, 
             communication = communication,
             host = host, 
             port = port, 
             user = user, 
             agent = agent, 
             sudo = sudo,
             environment_setup = environment_setup)
示例#6
0
文件: server.py 项目: nfvproject/nepi
    def test_server_auto_reconnect(self):
        s = server.Server(self.root_dir)
        s.run()
        c = server.Client(self.root_dir)

        c.send_msg("Hola")
        reply = c.read_reply()
        self.assertEqual(reply, "Reply to: Hola")

        # purposedly break the connection
        c._process.stdin.close()
        c._process.stdout.close()
        c._process.stderr.close()

        # assert that the communication works (possible with auto-reconnection)
        c.send_msg("Hola")
        reply = c.read_reply()
        self.assertEqual(reply, "Reply to: Hola")

        c.send_stop()
        reply = c.read_reply()
        self.assertEqual(reply, "Stopping server")
示例#7
0
文件: server.py 项目: nfvproject/nepi
    def test_ssh_server_auto_reconnect(self):
        env = test_util.test_environment()
        user = getpass.getuser()
        # launch server
        python_code = "from nepi.util import server;s=server.Server('%s');\
                s.run()" % self.root_dir
        server.popen_python(python_code,
                            communication=DC.ACCESS_SSH,
                            host="localhost",
                            port=env.port,
                            user=user,
                            agent=True)

        c = server.Client(self.root_dir,
                          communication=DC.ACCESS_SSH,
                          host="localhost",
                          port=env.port,
                          user=user,
                          agent=True)

        c.send_msg("Hola")
        reply = c.read_reply()
        self.assertEqual(reply, "Reply to: Hola")

        # purposedly break the connection
        c._process.stdin.close()
        c._process.stdout.close()
        c._process.stderr.close()

        # assert that the communication works (possible with auto-reconnection)
        c.send_msg("Hola")
        reply = c.read_reply()
        self.assertEqual(reply, "Reply to: Hola")

        c.send_stop()
        reply = c.read_reply()
        self.assertEqual(reply, "Stopping server")