예제 #1
0
    def _vagrant(self, command):
        """
        calls the vagrant executable

        Args:

            command: list or string containing the parameters for vagrant

        Returns:

            Tuple consisting of the return value and a list of output lines
        """
        logging.info("Executing: %s %s" % (self.vagrant_executable,
                                           " ".join(command)))
        args = [self.vagrant_executable] + command
        p = subprocess.Popen(args, shell=False, cwd=self.root,
                             stdout=subprocess.PIPE, stderr=subprocess.STDOUT)

        def log_output(line):
            logging.debug("[v] " + line.strip())

        stdout_queue = Queue()
        stdout_reader = AsynchronousFileReader(fd=p.stdout, queue=stdout_queue,
                                               action=log_output)

        stdout_reader.start()
        output_lines = []
        while not stdout_reader.eof():
            while not stdout_queue.empty():
                output_lines += [stdout_queue.get()]

        stdout_reader.join()
        return (p.returncode, output_lines)
    def test_file_reader_with_normal_output(self):
        p = subprocess.Popen(['ls', '-lah'], shell=True, stdout=subprocess.PIPE, cwd='/tmp/')
        stdout_queue = Queue.Queue()
        def print_line(line):
            pass

        stdout_reader = AsynchronousFileReader(fd=p.stdout, queue=stdout_queue, action=print_line)
        stdout_reader.start()

        stdout_reader.join()
    def test_file_reader_with_timed_output(self):
        p = subprocess.Popen('ping -c 1 -t 1 g****e.cx', shell=True, stdout=subprocess.PIPE, cwd='/tmp/')
        stdout_queue = Queue.Queue()
        def print_line(line):
            pass

        stdout_reader = AsynchronousFileReader(fd=p.stdout, queue=stdout_queue, action=print_line)
        stdout_reader.start()

        stdout_reader.join()
    def test_output_result(self):
        p = subprocess.Popen(['/bin/echo', '"Hello, world!"'], stdout=subprocess.PIPE, cwd='/tmp/')
        stdout_queue = Queue.Queue()
        def print_line(line):
            pass

        stdout_reader = AsynchronousFileReader(fd=p.stdout, queue=stdout_queue, action=print_line)
        stdout_reader.start()

        stdout_reader.join()

        output_lines = []
        while not stdout_queue.empty():
            output_lines += [stdout_queue.get()]

        self.assertTrue("Hello, world" in output_lines[0])
예제 #5
0
파일: vagrant.py 프로젝트: sffej/EvilGenius
    def _vagrant(self, command):
        """
        calls the vagrant executable

        Args:

            command: list or string containing the parameters for vagrant

        Returns:

            Tuple consisting of the return value and a list of output lines
        """
        logging.info("Executing: %s %s" %
                     (self.vagrant_executable, " ".join(command)))
        args = [self.vagrant_executable] + command
        p = subprocess.Popen(args,
                             shell=False,
                             cwd=self.root,
                             stdout=subprocess.PIPE,
                             stderr=subprocess.STDOUT)

        def log_output(line):
            logging.debug("[v] " + line.strip())

        stdout_queue = Queue()
        stdout_reader = AsynchronousFileReader(fd=p.stdout,
                                               queue=stdout_queue,
                                               action=log_output)

        stdout_reader.start()
        output_lines = []
        while not stdout_reader.eof():
            while not stdout_queue.empty():
                output_lines += [stdout_queue.get()]

        stdout_reader.join()
        return (p.returncode, output_lines)