On 04/24/2014 02:19 PM, shaohef(a)linux.vnet.ibm.com wrote:
From: ShaoHe Feng <shaohef(a)linux.vnet.ibm.com>
same mechanism with other feature tests.
Signed-off-by: ShaoHe Feng <shaohef(a)linux.vnet.ibm.com>
Signed-off-by: Royce Lv <lvroyce(a)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
The better place to insert it is in src/kimchi/model/config.py as all
the feature tests are made there.
So we can have single place for it.
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>
the uuid is not required to create a vm
+ <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
You should not raise an exception during feature test.
Independent of which error occurred you should only return meta_support
= False and handle that info when using it
except libvirt.libvirtError as e:
return False
+
+ return meta_support