Example #1
0
    def test00_launch_and_catch_the_output(self):
        """
        - create a simple script with active stdout and stderr
        - launch it and catch its output
        """
        queue = Queue.Queue()

        with ProcessSimulator() as script:

            config = ConfigHelper()
            config.vpn.command = "python"
            config.vpn.command_args = script.name


            launch_vpn = VPNLaunchControl(config, queue)
            def pb(): return True
            setattr(launch_vpn, "probe", pb)
            launch_vpn.start()


            outs = errs = ""
            for out, err in ProcessSimulator.output:
                outs += out
                errs += err

            p_outs, p_errs = queue.get()

            self.assertEqual(outs, p_outs)
            self.assertEqual(errs, p_errs)
Example #2
0
    def test04_probe_succeed(self):
        """Launched script returns 0"""
        def build_vpn_server(config):
            server = socket(AF_INET, SOCK_STREAM)
            server.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1)
            server.bind((config.vpn.host, config.vpn.port))
            server.listen(1)

            client_connection, address = server.accept()
            if client_connection:
                result = client_connection.recv(1024) # pyflakes.ignore
                client_connection.close()


        with ProcessSucceed() as script:
            config = ConfigHelper()
            config.vpn.command = "sh"
            config.vpn.command_args = script.name


            t = threading.Thread(target=build_vpn_server,
                                 args=(config,)
                                 )
            t.start()

            queue = Queue.Queue()

            launch_vpn = VPNLaunchControl(config, queue)
            ret = launch_vpn.start()

            self.assertEqual(ret, CC.VPN | CC.DONE)
Example #3
0
    def test03_probe_failed(self):
        """ Unreachable server """
        config = ConfigHelper()
        queue = Queue.Queue()

        launch_vpn = VPNLaunchControl(config, queue)

        ret = launch_vpn.start()

        self.assertEqual(ret, CC.VPN | CC.REFUSED)
Example #4
0
    def test02_return_code_failed(self):
        """Launched script returns 1"""

        queue = Queue.Queue()

        with ProcessFailed() as script:

            config = ConfigHelper()
            config.vpn.command = "sh"
            config.vpn.command_args = script.name


            launch_vpn = VPNLaunchControl(config, queue)
            def pb(): return True
            setattr(launch_vpn, "probe", pb)
            ret = launch_vpn.start()

            self.assertEqual(ret, CC.VPN | CC.FAILED)