Esempio n. 1
0
    def test_z_simple_ssh(
            self):  # _z_ cause we want it last - it messes up the process :(
        # Recreate environment
        environ = ' ; '.join(
            map("export %s=%r".__mod__, os.environ.iteritems()))

        env = test_util.test_environment()

        access_config = proxy.AccessConfiguration({
            DC.DEPLOYMENT_MODE:
            DC.MODE_DAEMON,
            DC.ROOT_DIRECTORY:
            self.root_dir,
            DC.LOG_LEVEL:
            DC.DEBUG_LEVEL,
            DC.DEPLOYMENT_COMMUNICATION:
            DC.ACCESS_SSH,
            DC.DEPLOYMENT_PORT:
            env.port,
            DC.USE_AGENT:
            True,
            DC.DEPLOYMENT_ENVIRONMENT_SETUP:
            environ,
        })

        self._test_simple(daemonize_testbed=False,
                          controller_access_configuration=access_config,
                          environ=environ)
Esempio n. 2
0
    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")
Esempio n. 3
0
    def test_ssh_daemonized_all(self):
        env = test_util.test_environment()

        controller_access_config = proxy.AccessConfiguration()
        controller_access_config.set_attribute_value(DC.DEPLOYMENT_MODE, DC.MODE_DAEMON)
        controller_access_config.set_attribute_value(DC.ROOT_DIRECTORY, self.root_dir)
        controller_access_config.set_attribute_value(DC.LOG_LEVEL, DC.DEBUG_LEVEL)
        controller_access_config.set_attribute_value(DC.DEPLOYMENT_COMMUNICATION, DC.ACCESS_SSH)
        controller_access_config.set_attribute_value(DC.DEPLOYMENT_PORT, env.port)
        controller_access_config.set_attribute_value(DC.USE_AGENT, True)

        testbed_access_config = proxy.AccessConfiguration()
        testbed_access_config.set_attribute_value(DC.DEPLOYMENT_MODE, DC.MODE_DAEMON)
        testbed_access_config.set_attribute_value(DC.LOG_LEVEL, DC.DEBUG_LEVEL)
        # BUG! IT DOESN'T WORK WITH 2 LEVELS OF SSH!
        #testbed_access_config.set_attribute_value(DC.DEPLOYMENT_COMMUNICATION, DC.ACCESS_SSH)
        #testbed_access_config.set_attribute_value(DC.DEPLOYMENT_PORT, env.port)
        #testbed_access_config.set_attribute_value(DC.USE_AGENT, True)
        inst_root_dir = os.path.join(self.root_dir, "instance")
        os.mkdir(inst_root_dir)
        testbed_access_config.set_attribute_value(DC.ROOT_DIRECTORY, inst_root_dir)
        
        self._test_switched(
                controller_access_config = controller_access_config,
                testbed_access_config = testbed_access_config)
Esempio n. 4
0
 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")
Esempio n. 5
0
    def test_all_ssh_daemonized_if(self):
        env = test_util.test_environment()

        access_config = proxy.AccessConfiguration()
        access_config.set_attribute_value(DC.DEPLOYMENT_MODE, DC.MODE_DAEMON)
        access_config.set_attribute_value(DC.ROOT_DIRECTORY, self.root_dir)
        #access_config.set_attribute_value(DC.LOG_LEVEL, DC.DEBUG_LEVEL)
        access_config.set_attribute_value(DC.DEPLOYMENT_COMMUNICATION, DC.ACCESS_SSH)
        access_config.set_attribute_value(DC.DEPLOYMENT_PORT, env.port)
        access_config.set_attribute_value(DC.USE_AGENT, True)
        
        self._test_if(
            daemonize_testbed = True,
            controller_access_configuration = access_config)
Esempio n. 6
0
    def test_ssh_daemonized_tbd(self):
        env = test_util.test_environment()

        testbed_access_config = proxy.AccessConfiguration()
        testbed_access_config.set_attribute_value(DC.DEPLOYMENT_MODE, DC.MODE_DAEMON)
        testbed_access_config.set_attribute_value(DC.LOG_LEVEL, DC.DEBUG_LEVEL)
        testbed_access_config.set_attribute_value(DC.DEPLOYMENT_COMMUNICATION, DC.ACCESS_SSH)
        testbed_access_config.set_attribute_value(DC.DEPLOYMENT_PORT, env.port)
        testbed_access_config.set_attribute_value(DC.USE_AGENT, True)
        inst_root_dir = os.path.join(self.root_dir, "instance")
        os.mkdir(inst_root_dir)
        testbed_access_config.set_attribute_value(DC.ROOT_DIRECTORY, inst_root_dir)
        
        self._test_switched(
                testbed_access_config = testbed_access_config)
Esempio n. 7
0
 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")
Esempio n. 8
0
    def test_z_simple_ssh(self):  # _z_ cause we want it last - it messes up the process :(
        # Recreate environment
        environ = " ; ".join(map("export %s=%r".__mod__, os.environ.iteritems()))

        env = test_util.test_environment()

        access_config = proxy.AccessConfiguration(
            {
                DC.DEPLOYMENT_MODE: DC.MODE_DAEMON,
                DC.ROOT_DIRECTORY: self.root_dir,
                DC.LOG_LEVEL: DC.DEBUG_LEVEL,
                DC.DEPLOYMENT_COMMUNICATION: DC.ACCESS_SSH,
                DC.DEPLOYMENT_PORT: env.port,
                DC.USE_AGENT: True,
                DC.DEPLOYMENT_ENVIRONMENT_SETUP: environ,
            }
        )

        self._test_simple(daemonize_testbed=False, controller_access_configuration=access_config, environ=environ)
Esempio n. 9
0
    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")
Esempio n. 10
0
    def test_ssh_daemonized_integration(self):
        exp_desc, desc, app, node1, node2, iface1, iface2 = self.make_test_experiment(
        )
        env = test_util.test_environment()

        desc.set_attribute_value(DC.DEPLOYMENT_MODE, DC.MODE_DAEMON)
        inst_root_dir = os.path.join(self.root_dir, "instance")
        os.mkdir(inst_root_dir)
        desc.set_attribute_value(DC.ROOT_DIRECTORY, inst_root_dir)
        xml = exp_desc.to_xml()

        access_config = proxy.AccessConfiguration()
        access_config.set_attribute_value(DC.DEPLOYMENT_MODE, DC.MODE_DAEMON)
        access_config.set_attribute_value(DC.ROOT_DIRECTORY, self.root_dir)
        access_config.set_attribute_value(DC.DEPLOYMENT_COMMUNICATION,
                                          DC.ACCESS_SSH)
        access_config.set_attribute_value(DC.DEPLOYMENT_PORT, env.port)
        access_config.set_attribute_value(DC.USE_AGENT, True)
        access_config.set_attribute_value(
            DC.DEPLOYMENT_ENVIRONMENT_SETUP,
            "export PYTHONPATH=%r:%r:$PYTHONPATH "
            "export NEPI_TESTBEDS='mock:mock mock2:mock2' " % (
                os.path.dirname(os.path.dirname(mock.__file__)),
                os.path.dirname(os.path.dirname(mock2.__file__)),
            ))
        controller = proxy.create_experiment_controller(xml, access_config)

        try:
            controller.start()
            while not controller.is_finished(app.guid):
                time.sleep(0.5)
            fake_result = controller.trace(app.guid, "fake")
            comp_result = """PING 10.0.0.2 (10.0.0.2) 56(84) bytes of data.

--- 10.0.0.2 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
"""
            self.assertTrue(fake_result.startswith(comp_result))
        finally:
            controller.stop()
            controller.shutdown()
Esempio n. 11
0
 def test_ssh_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, 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")
     c.send_stop()
     reply = c.read_reply()
     self.assertEqual(reply, "Stopping server")
Esempio n. 12
0
    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")
Esempio n. 13
0
    def test_ssh_daemonized_integration(self):
        exp_desc, desc, app, node1, node2, iface1, iface2 = self.make_test_experiment()
        env = test_util.test_environment()
        
        desc.set_attribute_value(DC.DEPLOYMENT_MODE, DC.MODE_DAEMON)
        inst_root_dir = os.path.join(self.root_dir, "instance")
        os.mkdir(inst_root_dir)
        desc.set_attribute_value(DC.ROOT_DIRECTORY, inst_root_dir)
        xml = exp_desc.to_xml()
        
        access_config = proxy.AccessConfiguration()
        access_config.set_attribute_value(DC.DEPLOYMENT_MODE, DC.MODE_DAEMON)
        access_config.set_attribute_value(DC.ROOT_DIRECTORY, self.root_dir)
        access_config.set_attribute_value(DC.DEPLOYMENT_COMMUNICATION, DC.ACCESS_SSH)
        access_config.set_attribute_value(DC.DEPLOYMENT_PORT, env.port)
        access_config.set_attribute_value(DC.USE_AGENT, True)
        access_config.set_attribute_value(DC.DEPLOYMENT_ENVIRONMENT_SETUP, 
            "export PYTHONPATH=%r:%r:$PYTHONPATH "
            "export NEPI_TESTBEDS='mock:mock mock2:mock2' " % (
                os.path.dirname(os.path.dirname(mock.__file__)),
                os.path.dirname(os.path.dirname(mock2.__file__)),))
        controller = proxy.create_experiment_controller(xml, access_config)

        try:
            controller.start()
            while not controller.is_finished(app.guid):
                time.sleep(0.5)
            fake_result = controller.trace(app.guid, "fake")
            comp_result = """PING 10.0.0.2 (10.0.0.2) 56(84) bytes of data.

--- 10.0.0.2 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
"""
            self.assertTrue(fake_result.startswith(comp_result))
        finally:
            controller.stop()
            controller.shutdown()