[PATCH V10 2/7] add method to test libvirt metadata api are available

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/featuretests.py | 31 +++++++++++++++++++++++++++++++ src/kimchi/model/config.py | 2 ++ 2 files changed, 33 insertions(+) diff --git a/src/kimchi/featuretests.py b/src/kimchi/featuretests.py index b1001ea..5192361 100644 --- a/src/kimchi/featuretests.py +++ b/src/kimchi/featuretests.py @@ -28,6 +28,7 @@ import threading from lxml.builder import E +from kimchi.rollbackcontext import RollbackContext from kimchi.utils import kimchi_log @@ -53,6 +54,16 @@ ISO_STREAM_XML = """ </devices> </domain>""" +SIMPLE_VM_XML = """ +<domain type='kvm'> + <name>A_SIMPLE_VM</name> + <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 +186,23 @@ class FeatureTests(object): pool is None or pool.undefine() conn is None or conn.close() return True + + @staticmethod + def has_metadata_support(): + KIMCHI_META_URL = "https://github.com/kimchi-project/kimchi/" + KIMCHI_NAMESPACE = "kimchi" + 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(SIMPLE_VM_XML) + rollback.prependDefer(dom.undefine) + try: + dom.setMetadata(libvirt.VIR_DOMAIN_METADATA_ELEMENT, + "<metatest/>", KIMCHI_NAMESPACE, + KIMCHI_META_URL, + flags=libvirt.VIR_DOMAIN_AFFECT_CURRENT) + return True + except libvirt.libvirtError: + return False diff --git a/src/kimchi/model/config.py b/src/kimchi/model/config.py index c9e3e9d..0ef0855 100644 --- a/src/kimchi/model/config.py +++ b/src/kimchi/model/config.py @@ -53,6 +53,7 @@ class CapabilitiesModel(object): self.qemu_stream_dns = False self.libvirt_stream_protocols = [] self.fc_host_support = False + self.metadata_support = False # Subscribe function to set host capabilities to be run when cherrypy # server is up @@ -65,6 +66,7 @@ class CapabilitiesModel(object): self.qemu_stream_dns = FeatureTests.qemu_iso_stream_dns() self.nfs_target_probe = FeatureTests.libvirt_support_nfs_probe() self.fc_host_support = FeatureTests.libvirt_support_fc_host() + self.metadata_support = FeatureTests.has_metadata_support() self.libvirt_stream_protocols = [] for p in ['http', 'https', 'ftp', 'ftps', 'tftp']: -- 1.9.0
participants (1)
-
shaohef@linux.vnet.ibm.com