[Kimchi-devel] [PATCH v2 4/4] Add a new test case for pci hotplug on Power

Jose Ricardo Ziviani joserz at linux.vnet.ibm.com
Fri Jul 10 18:32:55 UTC 2015


 - From now on all templates are created with xhci usb controller, so a
   hotplug must be performed flawlessly. If anything wrong the test case
   will fail.

Signed-off-by: Jose Ricardo Ziviani <joserz at linux.vnet.ibm.com>
---
 tests/test_model.py | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 54 insertions(+)

diff --git a/tests/test_model.py b/tests/test_model.py
index 3828342..e1ad848 100644
--- a/tests/test_model.py
+++ b/tests/test_model.py
@@ -1205,6 +1205,60 @@ class ModelTests(unittest.TestCase):
         # remove files creates
         inst.repository_delete(repo_id)
 
+    def _host_is_PKVM():
+        import platform
+        distro, _, _ = platform.linux_distribution()
+        return distro == 'IBM_PowerKVM'
+
+    @unittest.skipUnless(_host_is_PKVM(), 'Only required for PowerKVM host')
+    def test_pci_hotplug_requires_xhci_usb_controller(self):
+        config.set("authentication", "method", "pam")
+        inst = model.Model(None, objstore_loc=self.tmp_store)
+        tpl_params = {'name': 'test', 'memory': 1024, 'cdrom': UBUNTU_ISO}
+        inst.templates_create(tpl_params)
+
+        with RollbackContext() as rollback:
+            vm_params = {'name': 'kimchi-vm1', 'template': '/templates/test'}
+            task1 = inst.vms_create(vm_params)
+            inst.task_wait(task1['id'])
+            rollback.prependDefer(utils.rollback_wrapper, inst.vm_delete,
+                                  'kimchi-vm1')
+            # Start vm
+            inst.vm_start('kimchi-vm1')
+            rollback.prependDefer(utils.rollback_wrapper, inst.vm_poweroff,
+                                  'kimchi-vm1')
+
+            # get a list with all pci devices supporting live attachment
+            pci_devices = inst.devices_get_list(_passthrough='true')
+            self.assertGreater(len(pci_devices), 0)
+
+            # search for an usb device to live attaching to avoid causing
+            # any problem to host during the tests
+            for pci_device in pci_devices:
+
+                device = inst.device_lookup(pci_device)
+
+                if 'product' not in device and 'description' not in \
+                   device['product']:
+                    continue
+
+                description = device['product']['description']
+
+                if not isinstance(description, str):
+                    continue
+
+                if 'usb' not in description.lower():
+                    continue
+
+                # attach the first device found
+                inst.vmhostdevs_create('kimchi-vm1', {'name': pci_device})
+                rollback.prependDefer(utils.rollback_wrapper,
+                                      inst.vmhostdev_delete,
+                                      'kimchi-vm1',
+                                      pci_device)
+
+                break
+
 
 class BaseModelTests(unittest.TestCase):
     class FoosModel(object):
-- 
1.9.1




More information about the Kimchi-devel mailing list