[dts] [PATCH v2] framework: add virt_type option for virt type(kvm/libvirt) selection

Herbert Guan herbert.guan at arm.com
Thu Jan 25 10:17:39 CET 2018


Allow users to use test config file to specify virt type (kvm,
libvirt, etc) by 'virt_type' option.  If not specified in config
file, the default virt_type is kvm (qemu_kvm).
qemu_libvirt is modified to make the api interface compatible with
qemu_kvm with below 2 changes:
1) added function set_vm_device().
2) support guestpci auto-generate when adding a PCI device

Test suite developers will only need to use 'CreateVirt' instead of
'QEMUKvm' for VM creation and then this test suite will be able to
support both kvm and libvirt.

Signed-off-by: Herbert Guan <herbert.guan at arm.com>
---
 framework/qemu_libvirt.py | 33 +++++++++++++++------------
 framework/virt_base.py    |  7 +++---
 framework/virt_common.py  | 58 +++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 80 insertions(+), 18 deletions(-)
 mode change 100644 => 100755 framework/qemu_libvirt.py
 mode change 100644 => 100755 framework/virt_base.py
 create mode 100755 framework/virt_common.py

diff --git a/framework/qemu_libvirt.py b/framework/qemu_libvirt.py
old mode 100644
new mode 100755
index 59a0c9e..66fc54b
--- a/framework/qemu_libvirt.py
+++ b/framework/qemu_libvirt.py
@@ -229,7 +229,6 @@ class LibvirtKvm(VirtBase):
         ET.SubElement(os, 'boot', {'dev': 'hd'})
         features = ET.SubElement(self.domain, 'features')
         ET.SubElement(features, 'acpi')
-        ET.SubElement(features, 'gic', {'version': '3'})
 
         ET.SubElement(self.domain, 'cpu',
             {'mode': 'host-passthrough', 'check': 'none'})
@@ -408,6 +407,9 @@ class LibvirtKvm(VirtBase):
             return (bus, slot, func, dom)
         return None
 
+    def set_vm_device(self, driver='pci-assign', **opts):
+        self.add_vm_device(**opts)
+
     def add_vm_device(self, **options):
         """
         options:
@@ -437,20 +439,23 @@ class LibvirtKvm(VirtBase):
                       'slot': '0x%s' % slot,
                       'function': '0x%s' % func})
         if 'guestpci' in options.keys():
-            pci = self.__parse_pci(options['guestpci'])
-            if pci is None:
-                return False
-            bus, slot, func, dom = pci
-            ET.SubElement(hostdevice, 'address', {
-                  'type': 'pci', 'domain': '0x%s' % dom, 'bus': '0x%s' % bus,
-                  'slot': '0x%s' % slot, 'function': '0x%s' % func})
-            # save host and guest pci address mapping
-            pci_map = {}
-            pci_map['hostpci'] = pci_addr
-            pci_map['guestpci'] = options['guestpci']
-            self.pci_maps.append(pci_map)
+            guest_pci_addr = options['guestpci']
         else:
-            print utils.RED('Host device pass-through need guestpci option!!!')
+            guest_pci_addr = '0000:%s:00.0' % hex(self.pciindex)[2:]
+            self.pciindex += 1
+        pci = self.__parse_pci(guest_pci_addr)
+        if pci is None:
+            print utils.RED('Invalid guestpci for host device pass-through!!!')
+            return False
+        bus, slot, func, dom = pci
+        ET.SubElement(hostdevice, 'address', {
+              'type': 'pci', 'domain': '0x%s' % dom, 'bus': '0x%s' % bus,
+              'slot': '0x%s' % slot, 'function': '0x%s' % func})
+        # save host and guest pci address mapping
+        pci_map = {}
+        pci_map['hostpci'] = pci_addr
+        pci_map['guestpci'] = guest_pci_addr
+        self.pci_maps.append(pci_map)
 
     def add_vm_net(self, **options):
         """
diff --git a/framework/virt_base.py b/framework/virt_base.py
old mode 100644
new mode 100755
index e93cbab..b26a25a
--- a/framework/virt_base.py
+++ b/framework/virt_base.py
@@ -144,10 +144,9 @@ class VirtBase(object):
 
         # replace global configurations with local configurations
         for param in self.local_conf:
-            if 'mem' in param.keys():
-                self.__save_local_config('mem', param['mem'])
-            if 'cpu' in param.keys():
-                self.__save_local_config('cpu', param['cpu'])
+            if 'virt_type' in param.keys():
+                # param 'virt_type' is for virt_base only
+                continue
             # save local configurations
             for key in param.keys():
                 self.__save_local_config(key, param[key])
diff --git a/framework/virt_common.py b/framework/virt_common.py
new file mode 100755
index 0000000..ce4c9a5
--- /dev/null
+++ b/framework/virt_common.py
@@ -0,0 +1,58 @@
+# BSD LICENSE
+#
+# Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+#   * Redistributions of source code must retain the above copyright
+#     notice, this list of conditions and the following disclaimer.
+#   * Redistributions in binary form must reproduce the above copyright
+#     notice, this list of conditions and the following disclaimer in
+#     the documentation and/or other materials provided with the
+#     distribution.
+#   * Neither the name of Intel Corporation nor the names of its
+#     contributors may be used to endorse or promote products derived
+#     from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+import os
+import exception
+
+from config import VirtConf
+from settings import CONFIG_ROOT_PATH
+
+from qemu_kvm import QEMUKvm
+from qemu_libvirt import LibvirtKvm
+
+def CreateVirt(dut, vm_name, suite_name):
+    conf = VirtConf(CONFIG_ROOT_PATH + os.sep + suite_name + '.cfg')
+    conf.load_virt_config(vm_name)
+    local_conf = conf.get_virt_config()
+    # Default virt_type is 'KVM'
+    virt_type = 'KVM'
+    for param in local_conf:
+        if 'virt_type' in param.keys():
+            virt_type = param['virt_type'][0]['virt_type']
+
+    if virt_type == 'KVM':
+        return QEMUKvm(dut, vm_name, suite_name)
+    elif virt_type == 'LIBVIRT':
+        return LibvirtKvm(dut, vm_name, suite_name)
+    else:
+        raise Exception("Virt type %s is not supported!" 
+            % virt_type)
+
+
-- 
1.8.3.1



More information about the dts mailing list