From: Yiqiao Pu <[email protected]>

 In the new version of qemu in RHEL 6.0 device_add is instead of pci_add. So
 modify the scripts to suit for the new version of qemu.

Changs from v1:
Can support block device hotplug in scripts. But scsi is still not supported.

Signed-off-by: Yiqiao Pu <[email protected]>
---
 client/tests/kvm/tests/pci_hotplug.py |   71 +++++++++++++++++++++++++--------
 1 files changed, 54 insertions(+), 17 deletions(-)

diff --git a/client/tests/kvm/tests/pci_hotplug.py 
b/client/tests/kvm/tests/pci_hotplug.py
index 2c459d7..31ccd77 100644
--- a/client/tests/kvm/tests/pci_hotplug.py
+++ b/client/tests/kvm/tests/pci_hotplug.py
@@ -1,4 +1,4 @@
-import logging, os
+import logging, os, commands, re
 from autotest_lib.client.common_lib import error
 import kvm_subprocess, kvm_test_utils, kvm_utils, kvm_vm
 
@@ -35,26 +35,63 @@ def run_pci_hotplug(test, params, env):
 
     tested_model = params.get("pci_model")
     test_type = params.get("pci_type")
-
-    if test_type == "nic":
-        pci_add_cmd = "pci_add pci_addr=auto nic model=%s" % tested_model
-    elif test_type == "block":
-        image_params = kvm_utils.get_sub_dict(params, "stg")
-        image_filename = kvm_vm.get_image_filename(image_params, test.bindir)
-        pci_add_cmd = ("pci_add pci_addr=auto storage file=%s,if=%s" %
-                       (image_filename, tested_model))
-
-    # Execute pci_add (should be replaced by a proper monitor method call)
-    add_output = vm.monitor.cmd(pci_add_cmd)
-    if not "OK domain" in add_output:
-        raise error.TestFail("Add device failed. Hypervisor command is: %s. "
-                             "Output: %r" % (pci_add_cmd, add_output))
-    after_add = vm.monitor.info("pci")
+    image_format = params.get("image_format_stg")
+    s, o = commands.getstatusoutput("uname -r")
+    if len(re.findall("el6", o)) > 0:
+        cmd_type = "device"
+    else:
+        cmd_type = "pci"
+
+    if cmd_type == "pci":
+        if test_type == "nic":
+            pci_add_cmd = "pci_add pci_addr=auto nic model=%s" % tested_model
+        elif test_type == "block":
+            image_params = kvm_utils.get_sub_dict(params, "stg")
+            image_filename = kvm_vm.get_image_filename(image_params,
+                                                        test.bindir)
+            pci_add_cmd = ("pci_add pci_addr=auto storage file=%s,if=%s" %
+                           (image_filename, tested_model))
+        # Execute pci_add (should be replaced by a proper monitor method call)
+        add_output = vm.monitor.cmd(pci_add_cmd)
+        if not "OK domain" in add_output:
+            raise error.TestFail("Add device failed. Hypervisor command is: %s"
+                                  ". Output: %r" % (pci_add_cmd, add_output))
+        after_add = vm.monitor.info("pci")
+    elif cmd_type == "device":
+        # block device hotplug is not support rignt now
+        driver_id = test_type + "-" + kvm_utils.generate_random_id()
+        id = test_type + "-" + kvm_utils.generate_random_id()
+        if test_type == "nic":
+            if tested_model == "virtio":
+                tested_model = "virtio-net-pci"
+            pci_add_cmd = "device_add id=%s,driver=%s" % (id, tested_model)
+        elif test_type == "block":
+            image_params = kvm_utils.get_sub_dict(params, "stg")
+            image_filename = kvm_vm.get_image_filename(image_params,
+                                                        test.bindir)
+            if tested_model == "virtio":
+                tested_model = "virtio-blk-pci"
+            if tested_model == "scsi":
+                tested_model = "scsi-disk"
+            driver_add_cmd = " __com.redhat_drive_add file=%s,format=%s,id=%s" 
% \
+                          (image_filename, image_format, driver_id)
+            pci_add_cmd = "device_add id=%s,driver=%s,drive=%s" % \
+                           (id, tested_model, driver_id)
+            driver_output = vm.monitor.cmd(driver_add_cmd)
+
+        add_output = vm.monitor.cmd(pci_add_cmd)
+        after_add = vm.monitor.info("pci")
+        if not id in after_add:
+            raise error.TestFail("Add device failed. Hypervisor command is: %s"
+                                 ". Output: %r" % (pci_add_cmd, add_output))
 
     # Define a helper function to delete the device
     def pci_del(ignore_failure=False):
-        slot_id = "0" + add_output.split(",")[2].split()[1]
-        cmd = "pci_del pci_addr=%s" % slot_id
+        if cmd_type == "pci":
+            slot_id = "0" + add_output.split(",")[2].split()[1]
+            cmd = "pci_del pci_addr=%s" % slot_id
+        elif cmd_type == "device":
+            cmd = "device_del %s" % id
         # This should be replaced by a proper monitor method call
         vm.monitor.cmd(cmd)
 
-- 
1.7.1

_______________________________________________
Autotest mailing list
[email protected]
http://test.kernel.org/cgi-bin/mailman/listinfo/autotest

Reply via email to