On 11/20/2012 11:42 AM, Cleber Rosa wrote:
On 11/06/2012 02:09 AM, Amos Kong wrote:
----- Original Message -----
From: Yunping Zheng <[email protected]>

Using this patch you can enable or disable pci msi before test.
if you want to disable pci msi before test,just set:
     pci_msi_sensitive = yes
     disable_pci_msi = yes
in subtests.cfg.
when disable_pci_msi =yes, will modify the kernel params in grub.conf
and append "pci=nomsi."
when you using, you need sure you python support guestfs.

chang_log:
   V2 from V1
    using python guestfs lib.

Signed-off-by: Yunping Zheng <[email protected]>
---
  virttest/env_process.py |   53 ++++++++++++++++++++---
  virttest/utils_disk.py  |  109
  ++++++++++++++++++++++++++++++++++++++++++++++-
  2 files changed, 156 insertions(+), 6 deletions(-)

diff --git a/virttest/env_process.py b/virttest/env_process.py
index 0b3bd4e..1f89b82 100644
--- a/virttest/env_process.py
+++ b/virttest/env_process.py
@@ -3,7 +3,7 @@ from autotest.client import utils
  from autotest.client.shared import error
  import aexpect, kvm_monitor, ppm_utils, test_setup, virt_vm, kvm_vm
  import libvirt_vm, video_maker, utils_misc, storage, kvm_storage
-import remote, ovirt
+import remote, ovirt, utils_disk
    try:
      import PIL.Image
@@ -17,7 +17,7 @@ _screendump_thread = None
  _screendump_thread_termination_event = None
    -def preprocess_image(test, params, image_name):
+def preprocess_image(test, params, env, image_name):
      """
      Preprocess a single QEMU image according to the instructions in
      params.
  @@ -44,6 +44,14 @@ def preprocess_image(test, params, image_name):
              if not image.create(params):
                  raise error.TestError("Could not create image")
  +        #if you want set "pci=nomsi" before test, set
"disable_pci_msi = yes"
+        #and pci_msi_sensitive = "yes"
+        if params.get("pci_msi_sensitive", "no") == "yes":
+            disable_pci_msi = params.get("disable_pci_msi", "no")
+            enable_disable_pci_msi(test, params, env,
image_filename,
+                                   disable_pci_msi)
+
+
    def preprocess_vm(test, params, env, name):
      """
@@ -111,7 +119,7 @@ def preprocess_vm(test, params, env, name):
          vm.params = params
    -def postprocess_image(test, params, image_name):
+def postprocess_image(test, params, env, image_name):
      """
      Postprocess a single QEMU image according to the instructions in
      params.
  @@ -225,14 +233,14 @@ def process(test, params, env, image_func,
vm_func, vm_first=False):
                      if vm is not None and vm.is_alive():
                          vm.pause()
                      try:
-                        image_func(test, image_params, image_name)
+                        image_func(test, image_params, env,
image_name)
                      finally:
                          if vm is not None and vm.is_alive():
                              vm.resume()
          else:
              for image_name in params.objects("images"):
                  image_params = params.object_params(image_name)
-                image_func(test, image_params, image_name)
+                image_func(test, image_params, env, image_name)
        if not vm_first:
          _call_image_func()
@@ -588,3 +596,38 @@ def _take_screendumps(test, params, env):
                  _screendump_thread_termination_event = None
                  break
              _screendump_thread_termination_event.wait(delay)
+
+def enable_disable_pci_msi(test, params, env, image_filename,
disable_pci_msi):
+    """
+    Add or delete "pci=nomsi" in the kernel config line, before
guest is start.
+
+    @Parm  image_filename: image you want to modify.
+    @Param disable_pci_msi: flag of if disable pci msi.if
disable_pci_msi is
+                            True will add pci=nomsi in kernel config
line.
+    """
+
+    grub_file = params.get("grub_file", "/boot/grub/grub.conf")
+    kernel_cfg_pos_reg =  params.get("kernel_cfg_pos_reg",
+ "\s*kernel\s*\/vmlinuz-\d+.*")
+    msi_keyword = params.get("msi_keyword", " pci=nomsi")
+
+    f = utils_disk.Guest_Disk(image_filename)
+    kernel_config_ori = f.read_file(grub_file)
+    kernel_config_line = re.findall(kernel_cfg_pos_reg,
kernel_config_ori)[0]
+    kernel_need_modify = False
+
+    if disable_pci_msi == "yes":
+        if not re.findall(msi_keyword, kernel_config_line):
+            kernel_config_set = kernel_config_line + msi_keyword
+            kernel_need_modify = True
+    elif disable_pci_msi == "no":
+        if re.findall(msi_keyword, kernel_config_line):
+            kernel_config_set = re.sub(msi_keyword, "",
kernel_config_line)
+            kernel_need_modify = True
+    if kernel_need_modify:
+        for vm in env.get_all_vms():
+            if vm.is_alive():
+                vm.destroy()
+        time.sleep(1)
+        f.replace_image_file_content(grub_file, kernel_config_line,
+                                     kernel_config_set)

Better to update grub file by 'grubby', it's also support lilo and elilo.

Even better to rely on the Grubby class of autotest.client.tools.boottool:

import autotest.client.tools.boottool
g = autotest.client.tools.boottool.Grubby()
g.add_args(0, msi_keyword)

It's this simple.

Oops. Now I realize this is a guest kernel parameter change.



_______________________________________________
Autotest-kernel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/autotest-kernel

_______________________________________________
Autotest-kernel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/autotest-kernel

_______________________________________________
Autotest-kernel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/autotest-kernel

Reply via email to