예제 #1
0
    def cleanup_ports(self):
        """
        Clean state of all ports and set port to default state.
        Default state:
           No data on port or in port buffer.
           Read mode = blocking.
        """
        # Check if python is still alive
        match, tmp = self._cmd("is_alive()", 10)
        if (match is None) or (match != 0):
            logging.error("Python died/is stuck/have remaining threads")
            logging.debug(tmp)
            try:
                self.vm.verify_kernel_crash()

                match, tmp = self._cmd("guest_exit()", 10)
                if (match is None) or (match == 0):
                    self.session.close()
                    self.session = utils_test.wait_for_login(self.vm)
                self.cmd("killall -9 python "
                         "&& echo -n PASS: python killed"
                         "|| echo -n PASS: python was already dead", 10)

                self._init_guest()
                self._cleanup_ports()

            except Exception, inst:
                logging.error(inst)
                raise VirtioPortFatalException("virtio-console driver is "
                            "irreparably blocked, further tests might FAIL.")
예제 #2
0
    def __init__(self, vm):
        """ Initialize worker for use (including port init on guest) """
        self.vm = vm
        self.session = utils_test.wait_for_login(self.vm)

        timeout = 10
        if self.session.cmd_status('ls /tmp/virtio_console_guest.pyo'):
            # Copy virtio_console_guest.py into guests
            virt_dir = os.path.join(os.environ['AUTODIR'], 'virt')
            vksmd_src = os.path.join(virt_dir, "scripts",
                                     "virtio_console_guest.py")
            dst_dir = "/tmp"

            self.vm.copy_files_to(vksmd_src, dst_dir)

            # Compile and execute worker
            logging.debug("compile virtio_console_guest.py on guest %s",
                          self.vm.name)
            self.cmd("python -OO /tmp/virtio_console_guest.py -c "
                     "&& echo -n 'PASS: Compile virtio_guest finished' || "
                     "echo -n 'FAIL: Compile virtio_guest failed'", timeout)
            self.session.sendline()

        logging.debug("Starting virtio_console_guest.py on guest %s",
                      self.vm.name)
        self._execute_worker(timeout)
        self._init_guest(timeout)
예제 #3
0
 def reconnect(self, vm, timeout=10):
     """
     Reconnect to guest_worker (eg. after migration)
     @param vm: New VM object
     """
     self.vm = vm
     self.session = utils_test.wait_for_login(self.vm)
     self._execute_worker(timeout)
예제 #4
0
    def safe_exit_loopback_threads(self, send_pts, recv_pts):
        """
        Safely executes on_guest("virt.exit_threads()") using workaround of
        the stuck thread in loopback in mode=virt.LOOP_NONE .
        @param send_pts: list of possible send sockets we need to work around.
        @param recv_pts: list of possible recv sockets we need to read-out.
        """
        # No need to clean ports when VM is dead
        if not self.vm or self.vm.is_dead():
            return
        # in LOOP_NONE mode it might stuck in read/write
        # This command can't fail, can only freze so wait for the correct msg
        match, tmp = self._cmd("virt.exit_threads()", 3, ("^PASS: All threads"
                                                          " finished", ))
        if match is None:
            logging.warn("Workaround the stuck thread on guest")
            # Thread is stuck in read/write
            for send_pt in send_pts:
                send_pt.sock.sendall(".")
        elif match != 0:
            # Something else
            raise VirtioPortException("Unexpected fail\nMatch: %s\nData:\n%s" %
                                      (match, tmp))

        # Read-out all remaining data
        for recv_pt in recv_pts:
            while select.select([recv_pt.sock], [], [], 0.1)[0]:
                recv_pt.sock.recv(1024)

        # This will cause fail in case anything went wrong.
        match, tmp = self._cmd("print 'PASS: nothing'", 10,
                               ('^PASS: nothing', '^FAIL:'))
        if match is not 0:
            logging.error("Python is stuck/FAILed after read-out:\n%s", tmp)
            try:
                self.session.close()
                self.session = utils_test.wait_for_login(self.vm)
                if self.os_linux:  # On windows it dies with the connection
                    self.cmd(
                        "killall -9 python "
                        "&& echo -n PASS: python killed"
                        "|| echo -n PASS: python was already dead", 10)
                self._execute_worker()
                self._init_guest()
            except Exception, inst:
                logging.error(inst)
                raise VirtioPortFatalException(
                    "virtio-console driver is "
                    "irreparably blocked, further tests might FAIL.")
예제 #5
0
    def safe_exit_loopback_threads(self, send_pts, recv_pts):
        """
        Safely executes on_guest("virt.exit_threads()") using workaround of
        the stuck thread in loopback in mode=virt.LOOP_NONE .
        :param send_pts: list of possible send sockets we need to work around.
        :param recv_pts: list of possible recv sockets we need to read-out.
        """
        # No need to clean ports when VM is dead
        if not self.vm or self.vm.is_dead():
            return
        # in LOOP_NONE mode it might stuck in read/write
        # This command can't fail, can only freze so wait for the correct msg
        match, tmp = self._cmd("virt.exit_threads()", 3, ("^PASS: All threads"
                               " finished",))
        if match is None:
            logging.warn("Workaround the stuck thread on guest")
            # Thread is stuck in read/write
            for send_pt in send_pts:
                send_pt.sock.sendall(".")
        elif match != 0:
            # Something else
            raise VirtioPortException("Unexpected fail\nMatch: %s\nData:\n%s"
                                      % (match, tmp))

        # Read-out all remaining data
        for recv_pt in recv_pts:
            while select.select([recv_pt.sock], [], [], 0.1)[0]:
                recv_pt.sock.recv(1024)

        # This will cause fail in case anything went wrong.
        match, tmp = self._cmd("print 'PASS: nothing'", 10, ('^PASS: nothing',
                                                             '^FAIL:'))
        if match is not 0:
            logging.error("Python is stuck/FAILed after read-out:\n%s", tmp)
            try:
                self.session.close()
                self.session = utils_test.wait_for_login(self.vm)
                if self.os_linux:   # On windows it dies with the connection
                    self.cmd("killall -9 python "
                             "&& echo -n PASS: python killed"
                             "|| echo -n PASS: python was already dead", 10)
                self._execute_worker()
                self._init_guest()
            except Exception, inst:
                logging.error(inst)
                raise VirtioPortFatalException("virtio-console driver is "
                                               "irreparably blocked, further tests might FAIL.")
예제 #6
0
 def cleanup(self):
     """ Cleanup ports and quit the worker """
     # Verify that guest works
     if self.session and self.vm and self.vm.is_alive():
         self.cleanup_ports()
     if self.vm:
         self.vm.verify_kernel_crash()
     # Quit worker
     if self.session and self.vm and self.vm.is_alive():
         match, tmp = self._cmd("guest_exit()", 10)
         if match is not 0:
             logging.warn("guest_worker stuck during cleanup," " killing python...")
             self.session.close()
             self.session = utils_test.wait_for_login(self.vm)
             self.cmd(
                 "killall -9 python " "&& echo -n PASS: python killed" "|| echo -n PASS: python was already dead", 10
             )
         self.session.close()
     self.session = None
     self.vm = None
예제 #7
0
 def cleanup(self):
     """ Cleanup ports and quit the worker """
     # Verify that guest works
     if self.session and self.vm and self.vm.is_alive():
         self.cleanup_ports()
     if self.vm:
         self.vm.verify_kernel_crash()
     # Quit worker
     if self.session and self.vm and self.vm.is_alive():
         match, tmp = self._cmd("guest_exit()", 10)
         if match is not 0:
             logging.warn('guest_worker stuck during cleanup,'
                          ' killing python...')
             self.session.close()
             self.session = utils_test.wait_for_login(self.vm)
             self.cmd(
                 "killall -9 python "
                 "&& echo -n PASS: python killed"
                 "|| echo -n PASS: python was already dead", 10)
         self.session.close()
     self.session = None
     self.vm = None
예제 #8
0
    def __init__(self, vm):
        """ Initialize worker for use (including port init on guest) """
        self.vm = vm
        self.session = utils_test.wait_for_login(self.vm)
        self.__cmd_execute_worker = None

        # Detect the OS version
        guest_script_py = "virtio_console_guest.py"
        out = self.session.cmd_output("echo on")
        if "on" in out:
            self.os_linux = True
            guest_script_path = "/tmp/%s" % guest_script_py
            cmd_already_compiled_chck = "ls %so" % guest_script_path
            cmd_compile = ("python -OO %s -c "
                           "&& echo -n 'PASS: Compile virtio_guest finished' "
                           "|| echo -n 'FAIL: Compile virtio_guest failed'" %
                           guest_script_path)
            self.__cmd_execute_worker = (
                "python %so"
                "&& echo -n 'PASS: virtio_guest finished' "
                "|| echo -n 'FAIL: virtio_guest failed'" % guest_script_path)
        else:
            self.os_linux = False
            guest_script_path = "C:\\%s" % guest_script_py
            cmd_already_compiled_chck = "dir %so" % guest_script_path
            cmd_compile = ("%s -c "
                           "&& echo PASS: Compile virtio_guest finished "
                           "|| echo FAIL: Compile virtio_guest failed" %
                           guest_script_path)
            self.__cmd_execute_worker = ("%so "
                                         "&& echo PASS: virtio_guest finished "
                                         "|| echo FAIL: virtio_guest failed" %
                                         guest_script_path)

        # Copy, compile and run the worker
        timeout = 10
        if self.session.cmd_status(cmd_already_compiled_chck):
            if self.os_linux:
                # Disable [email protected] on systemd-like hosts
                self.session.cmd_status('systemctl mask '
                                        '*****@*****.**')
                self.session.cmd_status('systemctl stop '
                                        '*****@*****.**')
            # Copy virtio_console_guest.py into guests
            base_path = os.path.dirname(data_dir.get_data_dir())
            vksmd_src = os.path.join(base_path, 'scripts',
                                     'virtio_console_guest.py')

            self.vm.copy_files_to(vksmd_src, guest_script_path)

            # set echo off (self.cmd() musn't contain C:)
            self.session.sendline("echo off")
            # Compile worker
            logging.debug("Compile %s on guest %s", guest_script_py,
                          self.vm.name)
            try:
                self.cmd(cmd_compile, timeout)
            except VirtioPortException:
                if not self.os_linux:
                    logging.error("Script execution failed, do you have python"
                                  " and pywin32 installed? Currently this "
                                  "needs to be done manually!")
                raise
            self.session.sendline()

        # set echo off (self.cmd() musn't contain C:)
        self.session.sendline("echo off")
        logging.debug("Starting %so on guest %s", guest_script_py,
                      self.vm.name)
        self._execute_worker(timeout)
        self._init_guest(timeout)
예제 #9
0
    def __init__(self, vm):
        """ Initialize worker for use (including port init on guest) """
        self.vm = vm
        self.session = utils_test.wait_for_login(self.vm)
        self.__cmd_execute_worker = None

        # Detect the OS version
        guest_script_py = "virtio_console_guest.py"
        out = self.session.cmd_output("echo on")
        if "on" in out:
            self.os_linux = True
            guest_script_path = "/tmp/%s" % guest_script_py
            cmd_guest_size = ("du -b %s | cut -f1"
                              % guest_script_path)
            cmd_compile = ("python -OO %s -c "
                           "&& echo -n 'PASS: Compile virtio_guest finished' "
                           "|| echo -n 'FAIL: Compile virtio_guest failed'"
                           % guest_script_path)
            self.__cmd_execute_worker = ("python %so"
                                         "&& echo -n 'PASS: virtio_guest finished' "
                                         "|| echo -n 'FAIL: virtio_guest failed'"
                                         % guest_script_path)
        else:
            self.os_linux = False
            guest_script_path = "C:\\%s" % guest_script_py
            cmd_guest_size = ("for %%I in (%s) do @echo %%~zI"
                              % guest_script_path)
            cmd_compile = ("%s -c "
                           "&& echo PASS: Compile virtio_guest finished "
                           "|| echo FAIL: Compile virtio_guest failed"
                           % guest_script_path)
            self.__cmd_execute_worker = ("%so "
                                         "&& echo PASS: virtio_guest finished "
                                         "|| echo FAIL: virtio_guest failed"
                                         % guest_script_path)

        # Copy, compile and run the worker
        timeout = 10
        base_path = os.path.dirname(data_dir.get_data_dir())
        guest_script_src = os.path.join(base_path, 'scripts',
                                        'virtio_console_guest.py')
        script_size = utils.system_output("du -b %s | cut -f1"
                                          % guest_script_src).strip()
        script_size_guest = self.session.cmd_output(cmd_guest_size).strip()
        if script_size != script_size_guest:
            if self.os_linux:
                # Disable [email protected] on systemd-like hosts
                self.session.cmd_status('systemctl mask '
                                        '*****@*****.**')
                self.session.cmd_status('systemctl stop '
                                        '*****@*****.**')
            # Copy virtio_console_guest.py into guests
            self.vm.copy_files_to(guest_script_src, guest_script_path)

            # set echo off (self.cmd() musn't contain C:)
            self.session.sendline("echo off")
            # Compile worker
            logging.debug("Compile %s on guest %s", guest_script_py,
                          self.vm.name)
            try:
                self.cmd(cmd_compile, timeout)
            except VirtioPortException:
                if not self.os_linux:
                    logging.error("Script execution failed, do you have python"
                                  " and pywin32 installed? Currently this "
                                  "needs to be done manually!")
                raise
            self.session.sendline()

        # set echo off (self.cmd() musn't contain C:)
        self.session.sendline("echo off")
        logging.debug("Starting %so on guest %s", guest_script_py,
                      self.vm.name)
        self._execute_worker(timeout)
        self._init_guest(timeout)
예제 #10
0
    def __init__(self, vm):
        """ Initialize worker for use (including port init on guest) """
        self.vm = vm
        self.session = utils_test.wait_for_login(self.vm)
        self.__cmd_execute_worker = None

        # Detect the OS version
        guest_script_py = "virtio_console_guest.py"
        out = self.session.cmd_output("echo on")
        if "on" in out:
            self.os_linux = True
            guest_script_path = "/tmp/%s" % guest_script_py
            cmd_already_compiled_chck = "ls %so" % guest_script_path
            cmd_compile = ("python -OO %s -c "
                           "&& echo -n 'PASS: Compile virtio_guest finished' "
                           "|| echo -n 'FAIL: Compile virtio_guest failed'"
                     % guest_script_path)
            self.__cmd_execute_worker = ("python %so"
                                    "&& echo -n 'PASS: virtio_guest finished' "
                                    "|| echo -n 'FAIL: virtio_guest failed'"
                                    % guest_script_path)
        else:
            self.os_linux = False
            guest_script_path = "C:\\%s" % guest_script_py
            cmd_already_compiled_chck = "dir %so" % guest_script_path
            cmd_compile = ("%s -c "
                           "&& echo PASS: Compile virtio_guest finished "
                           "|| echo FAIL: Compile virtio_guest failed"
                           % guest_script_path)
            self.__cmd_execute_worker = ("%so "
                                    "&& echo PASS: virtio_guest finished "
                                    "|| echo FAIL: virtio_guest failed"
                                    % guest_script_path)

        # Copy, compile and run the worker
        timeout = 10
        if self.session.cmd_status(cmd_already_compiled_chck):
            # Copy virtio_console_guest.py into guests
            try:
                base_path = os.environ['AUTODIR']
            except KeyError:
                base_path = os.path.dirname(data_dir.get_data_dir())
            vksmd_src = os.path.join(base_path, 'scripts',
                                                'virtio_console_guest.py')
            dst_dir = "/tmp"

            self.vm.copy_files_to(vksmd_src, guest_script_path)

            # set echo off (self.cmd() musn't contain C:)
            self.session.sendline("echo off")
            # Compile worker
            logging.debug("Compile %s on guest %s", guest_script_py,
                          self.vm.name)
            try:
                self.cmd(cmd_compile, timeout)
            except VirtioPortException:
                if not self.os_linux:
                    logging.error("Script execution failed, do you have python"
                                  " and pywin32 installed? Currently this "
                                  "needs to be done manually!")
                raise
            self.session.sendline()

        # set echo off (self.cmd() musn't contain C:)
        self.session.sendline("echo off")
        logging.debug("Starting %so on guest %s", guest_script_py,
                      self.vm.name)
        self._execute_worker(timeout)
        self._init_guest(timeout)