
From: ShaoHe Feng <shaohef@linux.vnet.ibm.com> same mechanism with other feature tests. Signed-off-by: ShaoHe Feng <shaohef@linux.vnet.ibm.com> Signed-off-by: Royce Lv <lvroyce@linux.vnet.ibm.com> --- src/kimchi/config.py.in | 14 +++++++++++++- src/kimchi/featuretests.py | 42 +++++++++++++++++++++++++++++++++++++++++- 2 files changed, 54 insertions(+), 2 deletions(-) diff --git a/src/kimchi/config.py.in b/src/kimchi/config.py.in index f8a645a..bca15ef 100644 --- a/src/kimchi/config.py.in +++ b/src/kimchi/config.py.in @@ -26,7 +26,7 @@ import threading from ConfigParser import SafeConfigParser - +from kimchi.featuretests import FeatureTests from kimchi.xmlutils import xpath_get_text __version__ = "@kimchiversion@" @@ -125,6 +125,18 @@ class Paths(object): paths = Paths() +class LivirtSupportAPI(object): + def __init__(self): + self.apis = { + "meta_element": FeatureTests.libvirt_config_support_metadata()} + + def get_apis(self): + return self.apis + + +libvirt_support_apis = LivirtSupportAPI().get_apis() + + class PluginPaths(Paths): def __init__(self, name): diff --git a/src/kimchi/featuretests.py b/src/kimchi/featuretests.py index b1001ea..956f328 100644 --- a/src/kimchi/featuretests.py +++ b/src/kimchi/featuretests.py @@ -23,14 +23,15 @@ import lxml.etree as ET import socket import subprocess import threading +import uuid from lxml.builder import E +from kimchi.rollbackcontext import RollbackContext from kimchi.utils import kimchi_log - ISO_STREAM_XML = """ <domain type='kvm'> <name>ISO_STREAMING</name> @@ -53,6 +54,17 @@ ISO_STREAM_XML = """ </devices> </domain>""" +SIMPLE_VM_XML = """ +<domain type='kvm'> + <name>%s</name> + <uuid>%s</uuid> + <memory unit='KiB'>10240</memory> + <os> + <type arch='x86_64' machine='pc'>hvm</type> + <boot dev='hd'/> + </os> +</domain>""" + SCSI_FC_XML = """ <pool type='scsi'> <name>TEST_SCSI_FC_POOL</name> @@ -175,3 +187,31 @@ class FeatureTests(object): pool is None or pool.undefine() conn is None or conn.close() return True + + @staticmethod + def libvirt_config_support_metadata(): + vm_uuid = uuid.uuid1() + vm_name = "kimchi_test_%s" % vm_uuid + KIMCHI_META_URL = "https://github.com/kimchi-project/kimchi/metadata/" + xml = SIMPLE_VM_XML % (vm_name, vm_uuid) + meta_support = False + with RollbackContext() as rollback: + FeatureTests.disable_screen_error_logging() + rollback.prependDefer(FeatureTests.enable_screen_error_logging) + conn = libvirt.open('qemu:///system') + rollback.prependDefer(conn.close) + dom = conn.defineXML(xml) + rollback.prependDefer(dom.undefine) + try: + dom.setMetadata(libvirt.VIR_DOMAIN_METADATA_ELEMENT, + "<metatest/>", "kimchi", + KIMCHI_META_URL + "metatest", + flags=libvirt.VIR_DOMAIN_AFFECT_CURRENT) + meta_support = True + except libvirt.libvirtError as e: + if e.get_error_code() == libvirt.VIR_ERR_ARGUMENT_UNSUPPORTED: + meta_support = False + else: + raise + + return meta_support -- 1.9.0