Esempio n. 1
0
 def _log_lines(self, log_str):
     """
     Record monitor cmd/output in log file.
     """
     try:
         for l in log_str.splitlines():
             utils_misc.log_line(self.log_file, l)
     except Exception:
         pass
Esempio n. 2
0
 def _log_lines(self, log_str):
     """
     Record monitor cmd/output in log file.
     """
     try:
         for l in log_str.splitlines():
             utils_misc.log_line(self.log_file, l)
     except Exception:
         pass
Esempio n. 3
0
def _tcpdump_handler(env, filename, line):
    """
    Helper for handler tcpdump output.

    :params address_cache: address cache path.
    :params filename: Log file name for tcpdump message.
    :params line: Tcpdump output message.
    """
    try:
        utils_misc.log_line(filename, line)
    except Exception, reason:
        logging.warn("Can't log tcpdump output, '%s'", reason)
Esempio n. 4
0
def _tcpdump_handler(env, filename, line):
    """
    Helper for handler tcpdump output.

    :params address_cache: address cache path.
    :params filename: Log file name for tcpdump message.
    :params line: Tcpdump output message.
    """
    try:
        utils_misc.log_line(filename, line)
    except Exception, reason:
        logging.warn("Can't log tcpdump output, '%s'", reason)
Esempio n. 5
0
 def _output_logger_handler(self, line):
     try:
         log_line(self._logfile, line)
     except Exception as e:
         logging.warn("Can't log ip sniffer output: '%s'", e)
     if self._output_handler(line):
         return
     # We can check whether the process is terminated unexpectedly
     # here since the terminated status is a line of the output
     match = self._re_sniffer_finished.match(line)
     if match:
         if match.group(1) != "0":
             logging.error(
                 "IP sniffer (%s) terminated unexpectedly! "
                 "please check the log to get the details "
                 "(status: %s)", self.command, match.group(1))
Esempio n. 6
0
    def sr_iov_setup(self):
        """
        Ensure the PCI device is working in sr_iov mode.

        Check if the PCI hardware device drive is loaded with the appropriate,
        parameters (number of VFs), and if it's not, perform setup.

        :return: True, if the setup was completed successfully, False otherwise.
        :rtype: bool
        """
        # Check if the host support interrupt remapping
        error.context("Set up host env for PCI assign test", logging.info)
        kvm_re_probe = True
        o = utils.system_output("dmesg")
        ecap = re.findall("ecap\s+(.\w+)", o)
        if not ecap:
            logging.error("Fail to check host interrupt remapping support.")
        else:
            if int(ecap[0], 16) & 8 == 8:
                # host support interrupt remapping.
                # No need enable allow_unsafe_assigned_interrupts.
                kvm_re_probe = False
            if self.kvm_params is not None:
                if self.auai_path and self.kvm_params[self.auai_path] == "Y":
                    kvm_re_probe = False
        # Try to re probe kvm module with interrupt remapping support
        if kvm_re_probe:
            cmd = "echo Y > %s" % self.auai_path
            error.context("enable PCI passthrough with '%s'" % cmd,
                          logging.info)
            try:
                utils.system(cmd)
            except Exception:
                logging.debug("Can not enable the interrupt remapping support")
        lnk = "/sys/module/vfio_iommu_type1/parameters/allow_unsafe_interrupts"
        if self.device_driver == "vfio-pci":
            status = utils.system('lsmod | grep vfio', ignore_status=True)
            if status:
                logging.info("Load vfio-pci module.")
                cmd = "modprobe vfio-pci"
                utils.run(cmd)
                time.sleep(3)
            if not ecap or (int(ecap[0], 16) & 8 != 8):
                cmd = "echo Y > %s" % lnk
                error.context("enable PCI passthrough with '%s'" % cmd,
                              logging.info)
                utils.run(cmd)
        re_probe = False
        status = utils.system("lsmod | grep %s" % self.driver,
                              ignore_status=True)
        if status:
            re_probe = True
        elif not self.check_vfs_count():
            utils.system_output("modprobe -r %s" % self.driver, timeout=60)
            re_probe = True
        else:
            self.setup = None
            return True

        # Re-probe driver with proper number of VFs
        if re_probe:
            cmd = "modprobe %s %s" % (self.driver, self.driver_option)
            error.context("Loading the driver '%s' with command '%s'" %
                          (self.driver, cmd), logging.info)
            status = utils.system(cmd, ignore_status=True)
            dmesg = utils.system_output("dmesg", timeout=60, ignore_status=True)
            file_name = "host_dmesg_after_load_%s.txt" % self.driver
            logging.info("Log dmesg after loading '%s' to '%s'.", self.driver,
                         file_name)
            utils_misc.log_line(file_name, dmesg)
            utils.system("/etc/init.d/network restart", ignore_status=True)
            if status:
                return False
            self.setup = None
            return True
Esempio n. 7
0
    def sr_iov_setup(self):
        """
        Ensure the PCI device is working in sr_iov mode.

        Check if the PCI hardware device drive is loaded with the appropriate,
        parameters (number of VFs), and if it's not, perform setup.

        :return: True, if the setup was completed successfully, False otherwise.
        :rtype: bool
        """
        # Check if the host support interrupt remapping
        error.context("Set up host env for PCI assign test", logging.info)
        kvm_re_probe = True
        o = utils.system_output("dmesg")
        ecap = re.findall("ecap\s+(.\w+)", o)
        if not ecap:
            logging.error("Fail to check host interrupt remapping support.")
        else:
            if int(ecap[0], 16) & 8 == 8:
                # host support interrupt remapping.
                # No need enable allow_unsafe_assigned_interrupts.
                kvm_re_probe = False
            if self.kvm_params is not None:
                if self.auai_path and self.kvm_params[self.auai_path] == "Y":
                    kvm_re_probe = False
        # Try to re probe kvm module with interrupt remapping support
        if kvm_re_probe:
            cmd = "echo Y > %s" % self.auai_path
            error.context("enable PCI passthrough with '%s'" % cmd,
                          logging.info)
            try:
                utils.system(cmd)
            except Exception:
                logging.debug("Can not enable the interrupt remapping support")
        lnk = "/sys/module/vfio_iommu_type1/parameters/allow_unsafe_interrupts"
        if self.device_driver == "vfio-pci":
            status = utils.system('lsmod | grep vfio', ignore_status=True)
            if status:
                logging.info("Load vfio-pci module.")
                cmd = "modprobe vfio-pci"
                utils.run(cmd)
                time.sleep(3)
            if not ecap or (int(ecap[0], 16) & 8 != 8):
                cmd = "echo Y > %s" % lnk
                error.context("enable PCI passthrough with '%s'" % cmd,
                              logging.info)
                utils.run(cmd)
        re_probe = False
        status = utils.system("lsmod | grep %s" % self.driver,
                              ignore_status=True)
        if status:
            re_probe = True
        elif not self.check_vfs_count():
            os.system("modprobe -r %s" % self.driver)
            re_probe = True
        else:
            self.setup = None
            return True

        # Re-probe driver with proper number of VFs
        if re_probe:
            cmd = "modprobe %s %s" % (self.driver, self.driver_option)
            error.context("Loading the driver '%s' with command '%s'" %
                          (self.driver, cmd), logging.info)
            status = utils.system(cmd, ignore_status=True)
            dmesg = utils.system_output("dmesg", ignore_status=True)
            file_name = "host_dmesg_after_load_%s.txt" % self.driver
            logging.info("Log dmesg after loading '%s' to '%s'.", self.driver,
                         file_name)
            utils_misc.log_line(file_name, dmesg)
            utils.system("/etc/init.d/network restart", ignore_status=True)
            if status:
                return False
            self.setup = None
            return True