diff options
author | Cole Robinson <crobinso@redhat.com> | 2020-09-10 13:52:07 -0400 |
---|---|---|
committer | Cole Robinson <crobinso@redhat.com> | 2020-09-11 15:04:37 -0400 |
commit | 8560138cf2269b8bc8f3cf657ed282a2ac9d499f (patch) | |
tree | 47f158a75bc7bdad295aaaee13fb1a425898e0f5 /tests | |
parent | aa8572048bdc4947520de728fe2a3fec3b61815f (diff) | |
download | virt-manager-8560138cf2269b8bc8f3cf657ed282a2ac9d499f.tar.gz |
cli: Add --xml xpath option for virt-install and virt-xml
The --xml option allows users to request raw XML edits to virt-install
or virt-xml generated XML. This gives users a bit of a workaround
incase we don't have proper support for some XML property. The --xml
option can gain more features in the future if it makes sense, like
setting XML namespaces for example.
Basic usage is like: virt-install --xml ./@foo=bar ...
Which will change the generated <domain> XML to have
<domain foo='bar' ...
virt-xml works similarly. It can only be combined with --edit currently.
This only works with xpaths rooted against the entire document.
Signed-off-by: Cole Robinson <crobinso@redhat.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/data/cli/compare/virt-install-many-devices.xml | 14 | ||||
-rw-r--r-- | tests/data/cli/compare/virt-xml-edit-xpaths.xml | 26 | ||||
-rw-r--r-- | tests/test_cli.py | 13 |
3 files changed, 50 insertions, 3 deletions
diff --git a/tests/data/cli/compare/virt-install-many-devices.xml b/tests/data/cli/compare/virt-install-many-devices.xml index 421368dc..690267a7 100644 --- a/tests/data/cli/compare/virt-install-many-devices.xml +++ b/tests/data/cli/compare/virt-install-many-devices.xml @@ -1,4 +1,4 @@ -<domain type="kvm"> +<domain type="kvm" foo="bar"> <name>fedora</name> <uuid>00000000-1111-2222-3333-444444444444</uuid> <metadata> @@ -419,8 +419,10 @@ <tpm model="tpm-crb"> <backend type="emulator" version="2.0"/> </tpm> - <graphics type="sdl" display=":3.4" xauth="/tmp/.Xauthority"/> - <graphics type="spice" port="-1" tlsPort="-1" autoport="yes"> + <graphics type="sdl" display=":3.4" xauth="/tmp/.Xauthority"> + <ab>cd</ab> + </graphics> + <graphics type="spice" port="-1" tlsPort="-1" autoport="yes" ef="hg"> <image compression="off"/> </graphics> <graphics type="vnc" port="5950" keymap="ja" listen="1.2.3.4" passwd="foo"/> @@ -609,4 +611,10 @@ <qemu:arg value="bar"/> <qemu:env name="DISPLAY" value=":0.1"/> </qemu:commandline> + <baz>wib</baz> + <deleteme/> + <t1> + <t2 foo="123"/> + </t1> + <barenode/> </domain> diff --git a/tests/data/cli/compare/virt-xml-edit-xpaths.xml b/tests/data/cli/compare/virt-xml-edit-xpaths.xml new file mode 100644 index 00000000..e424f6cd --- /dev/null +++ b/tests/data/cli/compare/virt-xml-edit-xpaths.xml @@ -0,0 +1,26 @@ +-<domain type="test"> ++<domain type="test" foo="bar"> + <name>test-for-virtxml</name> + <uuid>12345678-12f4-1234-1234-123456789012</uuid> + <description>Test VM for virtxml cli tests +@@ + </libosinfo:libosinfo> + </metadata> + <memory unit="KiB">4194304</memory> +- <currentMemory unit="KiB">4194304</currentMemory> + <blkiotune> + <weight>100</weight> + <device> +@@ + <dhCert>AQAAAAAOAAAAQAAAAAOAAAAQAAAAAOAAAAQAAAAAOAAAAQAAAAAOAAA</dhCert> + <session>IHAVENOIDEABUTJUSTPROVIDINGASTRING</session> + </launchSecurity> ++ <new> ++ <element> ++ <test>1</test> ++ </element> ++ </new> + </domain> + +Domain 'test-for-virtxml' defined successfully. +Changes will take effect after the domain is fully powered off.
\ No newline at end of file diff --git a/tests/test_cli.py b/tests/test_cli.py index 869687cb..b26156ea 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -722,6 +722,15 @@ source.reservations.managed=no,source.reservations.source.type=unix,source.reser --qemu-commandline="-device vfio-pci,addr=05.0,sysfsdev=/sys/class/mdev_bus/0000:00:02.0/f321853c-c584-4a6b-b99a-3eee22a3919c" --qemu-commandline="-set device.video0.driver=virtio-vga" --qemu-commandline args="-foo bar" + +--xml /domain/@foo=bar +--xml xpath.set=./baz,xpath.value=wib +--xml ./deleteme/deleteme2/deleteme3=foo +--xml ./t1/t2/@foo=123 +--xml ./devices/graphics[1]/ab=cd +--xml ./devices/graphics[2]/@ef=hg +--xml xpath.create=./barenode +--xml xpath.delete=./deleteme/deleteme2 """, "many-devices", predefine_check="5.3.0") @@ -831,6 +840,8 @@ c.add_invalid("--boot uefi") # URI doesn't support UEFI bits c.add_invalid("--connect %(URI-KVM)s --boot uefi,arch=ppc64") # unsupported arch for UEFI c.add_invalid("--features smm=on --machine pc") # smm=on doesn't work for machine=pc c.add_invalid("--graphics type=vnc,keymap", grep="Option 'keymap' had no value set.") +c.add_invalid("--xml FOOXPATH", grep="form of XPATH=VALUE") # failure parsing xpath value +c.add_invalid("--xml /@foo=bar", grep="/@foo xmlXPathEval") # failure processing xpath @@ -1186,6 +1197,7 @@ c.add_invalid("test-for-virtxml --edit --graphics password=foo,keymap= --update c.add_invalid("--build-xml --memory 10,maxmemory=20") # building XML for option that doesn't support it c.add_invalid("test-state-shutoff --edit sparse=no --disk path=blah", grep="Don't know how to match device type 'disk' property 'sparse'") c.add_invalid("test --edit --boot network,cdrom --define --no-define") +c.add_invalid("test --add-device --xml ./@foo=bar", grep="--xml can only be used with --edit") c.add_compare("test --print-xml --edit --vcpus 7", "print-xml") # test --print-xml c.add_compare("--edit --cpu host-passthrough", "stdin-edit", input_file=(_VIRTXMLDIR + "virtxml-stdin-edit.xml")) # stdin test c.add_compare("--build-xml --cpu pentium3,+x2apic", "build-cpu") @@ -1203,6 +1215,7 @@ c.add_compare("--connect %(URI-KVM)s test-many-devices --edit --cpu host-copy", c = vixml.add_category("simple edit diff", "test-for-virtxml --edit --print-diff --define") +c.add_compare("""--xml ./@foo=bar --xml xpath.delete=./currentMemory --xml ./new/element/test=1""", "edit-xpaths") c.add_compare("""--metadata name=foo-my-new-name,os_name=fedora13,uuid=12345678-12F4-1234-1234-123456789AFA,description="hey this is my new very,very=new desc\\\'",title="This is my,funky=new title" """, "edit-simple-metadata") |