Skip to content

Commit

Permalink
add case for virt-xml-validate for virsh domcap
Browse files Browse the repository at this point in the history
    xxxx-17141:validate libvirt XML files against a virsh domcap schema
Signed-off-by: nanli <[email protected]>
  • Loading branch information
nanli1 committed Jan 24, 2025
1 parent 1aa9ac2 commit 8866594
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
3 changes: 3 additions & 0 deletions libvirt/tests/cfg/virt_cmd/virt_xml_validate.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,6 @@
secret_volume = "/var/lib/libvirt/images/virt_xml_validate.secret"
- interface:
schema = "interface"
- domcapabilities:
func_supported_since_libvirt_ver = (10, 10, 0)
schema = "domcapabilities"
17 changes: 16 additions & 1 deletion libvirt/tests/src/virt_cmd/virt_xml_validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from virttest import virsh
from virttest import data_dir
from virttest import libvirt_version
from virttest.utils_libvirt import libvirt_secret
from virttest.utils_test import libvirt

Expand Down Expand Up @@ -183,6 +184,16 @@ def interface_validate(test, file=None, **virsh_dargs):
test.error(str(e))


def domcap_validate(file=None, **virsh_dargs):
"""
Prepare schema domcapabilities.
:param file: domcapabilities output file
:param virsh_dargs: virsh debug args.
"""
cmd_result = virsh.domcapabilities(options="> %s" % file, **virsh_dargs)
libvirt.check_exit_status(cmd_result)


def run(test, params, env):
"""
Test for virt-xml-validate
Expand All @@ -203,7 +214,7 @@ def run(test, params, env):

valid_schemas = ['domain', 'domainsnapshot', 'network', 'storagepool',
'storagevol', 'nodedev', 'capability',
'nwfilter', 'secret', 'interface']
'nwfilter', 'secret', 'interface', 'domcapabilities']
if schema not in valid_schemas:
test.fail("invalid %s specified" % schema)

Expand All @@ -230,6 +241,10 @@ def run(test, params, env):
secret_validate(test, secret_volume, file=output_path, **virsh_dargs)
elif schema == "interface":
interface_validate(test, file=output_path, **virsh_dargs)
elif schema == "domcapabilities":
libvirt_version.is_libvirt_feature_supported(params)
domcap_validate(file=output_path, **virsh_dargs)
schema = ""
else:
# domain
virsh.dumpxml(vm_name, to_file=output_path)
Expand Down

0 comments on commit 8866594

Please sign in to comment.