def test_get_kvm_arch(self): """ Asserts for `autotest.client.kvm_control.get_kvm_arch` :returns: None """ self._mock_cpu_info("GenuineIntel\nvmx") self.assertTrue(kvm_control.get_kvm_arch() == 'kvm_intel') self._mock_cpu_info("AuthenticAMD\nsvm") self.assertTrue(kvm_control.get_kvm_arch() == 'kvm_amd') self._mock_cpu_info("HygonGenuine\nsvm") self.assertTrue(kvm_control.get_kvm_arch() == 'kvm_amd') self._mock_cpu_info("POWER7") self.assertTrue(kvm_control.get_kvm_arch() == 'kvm_power7') self._mock_cpu_info("AuthenticAMD") self.assertRaises(error.TestError, kvm_control.get_kvm_arch) self._mock_cpu_info("HygonGenuine") self.assertRaises(error.TestError, kvm_control.get_kvm_arch) self._mock_cpu_info("InvalidCPU") self.assertRaises(error.TestError, kvm_control.get_kvm_arch)
def sr_iov_cleanup(self): """ Clean up the sriov setup Check if the PCI hardware device drive is loaded with the appropriate, parameters (none of VFs), and if it's not, perform cleanup. @return: True, if the setup was completed successfuly, False otherwise. """ # Check if the host support interrupt remapping error.context("Clean up host env after PCI assign test", logging.info) kvm_re_probe = False if self.kvm_params is not None: if (self.auai_path and open(self.auai_path, "r").read().strip() == "Y"): if self.kvm_params and self.kvm_params[self.auai_path] == "N": kvm_re_probe = True else: kvm_re_probe = True # Try to re probe kvm module with interrupt remapping support if kvm_re_probe: kvm_arch = kvm_control.get_kvm_arch() utils.system("modprobe -r %s" % kvm_arch) utils.system("modprobe -r kvm") cmd = "modprobe kvm" if self.kvm_params: for i in self.kvm_params: if self.kvm_params[i] == "Y": params_name = os.path.split(i)[1] cmd += " %s=1" % params_name logging.info("Loading kvm with command: %s" % cmd) try: utils.system(cmd) except Exception: logging.debug("Failed to reload kvm") cmd = "modprobe %s" % kvm_arch logging.info("Loading %s with command: %s" % (kvm_arch, cmd)) utils.system(cmd) re_probe = False s = commands.getstatusoutput('lsmod | grep %s' % self.driver)[0] if s: cmd = "modprobe -r %s" % self.driver logging.info("Running host command: %s" % cmd) os.system(cmd) re_probe = True else: return True # Re-probe driver with proper number of VFs if re_probe: cmd = "modprobe %s" % self.driver msg = "Loading the driver '%s' without option" % self.driver error.context(msg, logging.info) s = commands.getstatusoutput(cmd)[0] utils.system("/etc/init.d/network restart", ignore_status=True) if s: return False return True
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 successfuly, False otherwise. """ # Check if the host support interrupt remapping kvm_re_probe = False o = utils.system_output("cat /var/log/dmesg") ecap = re.findall("ecap\s+(.\w+)", o) if ecap and int(ecap[0], 16) & 8 == 0: if self.kvm_params is not None: if self.auai_path and self.kvm_params[self.auai_path] == "N": kvm_re_probe = True else: kvm_re_probe = True # Try to re probe kvm module with interrupt remapping support if kvm_re_probe: kvm_arch = kvm_control.get_kvm_arch() utils.system("modprobe -r %s" % kvm_arch) utils.system("modprobe -r kvm") cmd = "modprobe kvm allow_unsafe_assigned_interrupts=1" if self.kvm_params is not None: for i in self.kvm_params: if "allow_unsafe_assigned_interrupts" not in i: if self.kvm_params[i] == "Y": params_name = os.path.split(i)[1] cmd += " %s=1" % params_name logging.info("Loading kvm with: %s" % cmd) try: utils.system(cmd) except Exception: logging.debug("Can not enable the interrupt remapping support") utils.system("modprobe %s" % kvm_arch) re_probe = False s, o = commands.getstatusoutput('lsmod | grep %s' % self.driver) if s: re_probe = True elif not self.check_vfs_count(): os.system("modprobe -r %s" % self.driver) re_probe = True else: return True # Re-probe driver with proper number of VFs if re_probe: cmd = "modprobe %s %s" % (self.driver, self.driver_option) logging.info("Loading the driver '%s' with option '%s'", self.driver, self.driver_option) s, o = commands.getstatusoutput(cmd) utils.system("/etc/init.d/network restart", ignore_status=True) if s: return False return True
def test_get_kvm_arch(self): """ Asserts for `autotest.client.kvm_control.get_kvm_arch` :returns: None """ self._mock_cpu_info("GenuineIntel\nvmx") self.assertTrue(kvm_control.get_kvm_arch() == 'kvm_intel') self._mock_cpu_info("AuthenticAMD\nsvm") self.assertTrue(kvm_control.get_kvm_arch() == 'kvm_amd') self._mock_cpu_info("POWER7") self.assertTrue(kvm_control.get_kvm_arch() == 'kvm_power7') self._mock_cpu_info("AuthenticAMD") self.assertRaises(error.TestError, kvm_control.get_kvm_arch) self._mock_cpu_info("InvalidCPU") self.assertRaises(error.TestError, kvm_control.get_kvm_arch)