diff mbox

Add a subtest pci_hotplug in kvm test

Message ID 20090804084745.GC8907@aFu.nay.redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Yolkfull Chow Aug. 4, 2009, 8:47 a.m. UTC
Sorry for just submitting a wrong patch file which including a bug, please ignore previous one
and review following patch:

Differences between previous patch:

- Use a loop waiting for some seconds to compare output of a command
- Use a loop waiting for some seconds to catch string indicates which
  PCI device
- Add option kill_vm_on_error in block_hotplug since once a model failed
  to be hot removed, it will affect next model

A better result I can get is:
-------
./scan_results.py
test                                                       status	seconds info
----                                                       ------	------- ----
Fedora.11.32.nic_hotplug.nic_8139                          GOOD	107     completed successfully
Fedora.11.32.nic_hotplug.nic_virtio                        FAIL	76	Not found pci model:virtio; Command is:lspci | tail -n1
Fedora.11.32.block_hotplug.fmt_qcow2.block_virtio          GOOD	92	completed successfully
Fedora.11.32.block_hotplug.fmt_qcow2.block_scsi            GOOD	48	completed successfully
RHEL.5.3.i386.nic_hotplug.nic_8139                         GOOD	144     completed successfully
RHEL.5.3.i386.nic_hotplug.nic_virtio                       GOOD	48	completed successfully
RHEL.5.3.i386.block_hotplug.fmt_qcow2.block_virtio         GOOD	47	completed successfully
RHEL.5.3.i386.block_hotplug.fmt_qcow2.block_scsi           GOOD	47	completed successfully
Win2008.32.nic_hotplug.nic_8139                            GOOD	141     completed successfully
Win2008.32.nic_hotplug.nic_virtio                          GOOD	99	completed successfully
Win2008.32.block_hotplug.fmt_qcow2.block_scsi              GOOD	90	completed successfully
----                                                       GOOD	953


Signed-off-by: Yolkfull Chow <yzhou@redhat.com>
---
 client/tests/kvm/kvm.py               |    1 +
 client/tests/kvm/kvm_tests.cfg.sample |   67 +++++++++++++++++++++
 client/tests/kvm/kvm_tests.py         |  105 +++++++++++++++++++++++++++++++++
 client/tests/kvm/kvm_vm.py            |    2 +
 4 files changed, 175 insertions(+), 0 deletions(-)
diff mbox

Patch

diff --git a/client/tests/kvm/kvm.py b/client/tests/kvm/kvm.py
index 070e463..f985388 100644
--- a/client/tests/kvm/kvm.py
+++ b/client/tests/kvm/kvm.py
@@ -56,6 +56,7 @@  class kvm(test.test):
                 "linux_s3":     test_routine("kvm_tests", "run_linux_s3"),
                 "stress_boot":  test_routine("kvm_tests", "run_stress_boot"),
                 "timedrift":    test_routine("kvm_tests", "run_timedrift"),
+                "pci_hotplug":   test_routine("kvm_tests", "run_pci_hotplug"),
                 }
 
         # Make it possible to import modules from the test's bindir
diff --git a/client/tests/kvm/kvm_tests.cfg.sample b/client/tests/kvm/kvm_tests.cfg.sample
index 7cd12cb..9af1bc8 100644
--- a/client/tests/kvm/kvm_tests.cfg.sample
+++ b/client/tests/kvm/kvm_tests.cfg.sample
@@ -118,6 +118,53 @@  variants:
         kill_vm = yes
         kill_vm_gracefully = no
 
+    - nic_hotplug:
+        type = pci_hotplug
+        pci_type = nic
+        modprobe_acpiphp = no
+        reference_cmd = lspci
+        find_pci_cmd = 'lspci | tail -n1'
+        pci_test_cmd = 'nslookup www.redhat.com'
+        wait_secs_for_hook_up = 3
+        variants:
+            - nic_8139:
+                pci_model = rtl8139
+                match_string = "8139"
+            - nic_virtio:
+                pci_model = virtio
+                match_string = "Virtio network device"
+            - nic_e1000:
+                pci_model = e1000
+                match_string = "Gigabit Ethernet Controller"
+
+    - block_hotplug:
+        type = pci_hotplug
+        pci_type = block
+        reference_cmd = lspci
+        find_pci_cmd = 'lspci | tail -n1'
+        images += " stg"
+        boot_drive_stg = no
+        image_name_stg = storage
+        image_size_stg = 1G
+        remove_image_stg = yes
+        force_create_image_stg = yes
+        pci_test_cmd = "yes | mke2fs `fdisk -l 2>&1 | awk '/\/dev\/[sv]d[a-z] doesn/ {print $2}'`"
+        wait_secs_for_hook_up = 3
+        kill_vm_on_error = yes
+        variants:
+            - block_virtio:
+                pci_model = virtio
+                match_string = "Virtio block device"
+            - block_scsi:
+                pci_model = scsi
+                match_string = "SCSI"
+        variants:
+            - fmt_qcow2:
+                image_format_stg = qcow2
+            - fmt_raw:
+                image_format_stg = raw
+                only Fedora Ubuntu Windows
+
 
 # NICs
 variants:
@@ -259,6 +306,10 @@  variants:
             - RHEL:
                 no setup
                 ssh_prompt = "\[root@.{0,50}][\#\$] "
+                nic_hotplug:
+                    modprobe_module = acpiphp
+                block_hotplug:
+                    modprobe_module = acpiphp
 
                 variants:
                     - 5.3.i386:
@@ -345,6 +396,22 @@  variants:
             # Alternative host load:
             #host_load_command = "dd if=/dev/urandom of=/dev/null"
             host_load_instances = 8
+        nic_hotplug:
+            reference_cmd = ipconfig /all
+            find_pci_cmd = ipconfig /all | find "Description"
+            wait_secs_for_hook_up = 10
+            nic_e1000:
+                match_string = "Intel(R) PRO/1000 MT Network Connection"
+            nic_virtio:
+                match_string = "VirtIO Ethernet"
+        block_hotplug:
+            use_telnet = yes
+            ssh_port = 23
+            guest_port_ssh = 23
+            wait_secs_for_hook_up = 10
+            reference_cmd = wmic diskdrive list brief
+            find_pci_cmd = wmic diskdrive list brief
+            pci_test_cmd = echo select disk 1 > dt && echo online disk >> dt && echo detail disk >> dt && echo exit >> dt && diskpart /s dt
 
         variants:
             - Win2000:
diff --git a/client/tests/kvm/kvm_tests.py b/client/tests/kvm/kvm_tests.py
index 9784ec9..b553003 100644
--- a/client/tests/kvm/kvm_tests.py
+++ b/client/tests/kvm/kvm_tests.py
@@ -743,3 +743,108 @@  def run_timedrift(test, params, env):
                              % drift_total)
 
     session.close()
+
+
+def run_pci_hotplug(test, params, env):
+    """
+    Test pci devices' hotplug
+    1) PCI add a deivce (NIC / block)
+    2) Compare output of hypervisor command `info pci`
+    3) Compare output of guest command `reference_cmd`
+    4) Verify whether pci_model is shown in `pci_find_cmd`
+    5) Check whether the newly added pci device works fine
+    6) PCI delete the device, verify whether could remove the pci device
+
+    @param test:   kvm test object
+    @param params: Dictionary with the test parameters
+    @param env:    Dictionary with test environment.
+    """
+    vm = kvm_utils.env_get_vm(env, params.get("main_vm"))
+    if not vm:
+        raise error.TestError("VM object not found in environment")
+    if not vm.is_alive():
+        raise error.TestError("VM seems to be dead; Test requires a living VM")
+
+    logging.info("Waiting for guest to be up...")
+
+    session = kvm_utils.wait_for(vm.ssh_login, 240, 0, 2)
+    if not session:
+        raise error.TestFail("Could not log into guest")
+
+    logging.info("Logged in")
+
+    # Modprobe the module if specified in config file
+    if params.get("modprobe_module"):
+        module = params.get("modprobe_module")
+        if session.get_command_status("modprobe %s" % module):
+            raise error.TestError("Modprobe module '%s' failed" % module)
+
+    # Get output of command 'info pci' as reference
+    s, info_pci_ref = vm.send_monitor_cmd("info pci")
+
+    # Get output of command as reference
+    reference = session.get_command_output(params.get("reference_cmd"))
+
+    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_name = params.get("image_name_stg")
+        image_filename = "%s.%s" % (image_name, params.get("image_format_stg"))
+        image_dir = os.path.join(test.bindir, "images")
+        storage_name = os.path.join(image_dir, image_filename)
+        pci_add_cmd = ("pci_add pci_addr=auto storage file=%s,if=%s" %
+                                    (storage_name, tested_model))
+
+    # Implement pci_add
+    s, add_output = vm.send_monitor_cmd(pci_add_cmd)
+    if not "OK domain" in add_output:
+        raise error.TestFail("Add device failed;Hypervisor command is: %s; "
+                             "Output: %s" % (pci_add_cmd, add_output))
+
+    # Compare the output of 'info pci'
+    s, after_add = vm.send_monitor_cmd("info pci")
+    if after_add == info_pci_ref:
+        raise error.TestFail("No new PCI device shown after executing "
+                             "hypervisor command: 'info pci'")
+
+    # Define a helper function to compare the output
+    def new_shown():
+        o = session.get_command_output(params.get("reference_cmd"))
+        if reference == o:
+            return False
+        return True
+
+    secs = int(params.get("wait_secs_for_hook_up"))
+    if not kvm_utils.wait_for(new_shown, 30, secs, 3):
+        raise error.TestFail("No new device shown in output of command "
+                  "executed in guest: %s" % params.get("reference_cmd"))
+
+    # Define a helper function to catch PCI device string
+    def find_pci():
+        output = session.get_command_output(params.get("find_pci_cmd"))
+        if not params.get("match_string") in output:
+            return False
+        return True
+
+    if not kvm_utils.wait_for(find_pci, 30, 3, 3):
+        raise error.TestFail("Not found pci model:%s; Command is:%s" %
+                          (tested_model, params.get("find_pci_cmd")))
+
+    # Test the newly added device
+    s, o = session.get_command_status_output(params.get("pci_test_cmd"))
+    if s:
+        raise error.TestFail("Check for %s device failed after PCI hotplug;"
+                                    "Output: %s" % (test_type, o))
+
+    # Delete the added pci device
+    slot_id = "0" + add_output.split(",")[2].split()[1]
+    cmd = "pci_del pci_addr=%s" % slot_id
+    s, after_del = vm.send_monitor_cmd(cmd)
+    if after_del == after_add:
+        raise error.TestFail("Failed to hot remove pci device:%s; "
+                    "Hypervisor command: %s" % (tested_model, cmd))
+
+    session.close()
diff --git a/client/tests/kvm/kvm_vm.py b/client/tests/kvm/kvm_vm.py
index eba9b84..4a7a85c 100644
--- a/client/tests/kvm/kvm_vm.py
+++ b/client/tests/kvm/kvm_vm.py
@@ -225,6 +225,8 @@  class VM:
 
         for image_name in kvm_utils.get_sub_dict_names(params, "images"):
             image_params = kvm_utils.get_sub_dict(params, image_name)
+            if image_params.get("boot_drive") == "no":
+                continue
             qemu_cmd += " -drive file=%s" % get_image_filename(image_params,
                                                                image_dir)
             if image_params.get("drive_format"):