tests: Cover more of cloner.py from test_cli.py

Cover more cases via the virt-clone CLI testing, than just the
test_cloner.py unit style testing.

Change most of the virt-clone --print-xml testing to also attempt the
clone operation as well via a hidden cli option, to ensure we aren't
testing XML of any bogus operations

Signed-off-by: Cole Robinson <crobinso@redhat.com>
This commit is contained in:
Cole Robinson 2020-09-03 15:59:59 -04:00
parent f157aa1839
commit c0d1e76941
14 changed files with 347 additions and 6 deletions

View File

@ -0,0 +1,23 @@
<domain type='kvm'>
<name>clone-orig</name>
<uuid>aaa3ae22-fed2-bfbd-ac02-3bea3bcfad82</uuid>
<memory>262144</memory>
<currentMemory>262144</currentMemory>
<vcpu>1</vcpu>
<os>
<type arch='i686' machine='pc'>hvm</type>
<boot dev='cdrom'/>
<loader readonly='yes' type='pflash'>/usr/share/ovmf/ovmf-efi.fd</loader>
<nvram>/nvram/clone-orig-missing_VARS.fd</nvram>
</os>
<features>
<acpi/>
</features>
<clock offset='utc'/>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash>
<devices>
<emulator>/usr/bin/qemu-kvm</emulator>
</devices>
</domain>

View File

@ -0,0 +1,23 @@
<domain type='kvm'>
<name>clone-orig</name>
<uuid>aaa3ae22-fed2-bfbd-ac02-3bea3bcfad82</uuid>
<memory>262144</memory>
<currentMemory>262144</currentMemory>
<vcpu>1</vcpu>
<os>
<type arch='i686' machine='pc'>hvm</type>
<boot dev='cdrom'/>
<loader readonly='yes' type='pflash'>/usr/share/ovmf/ovmf-efi.fd</loader>
<nvram>/nvram-newpool/clone-orig-vars.fd</nvram>
</os>
<features>
<acpi/>
</features>
<clock offset='utc'/>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash>
<devices>
<emulator>/usr/bin/qemu-kvm</emulator>
</devices>
</domain>

View File

@ -0,0 +1,25 @@
<domain type="test">
<name>origtest-clone</name>
<uuid>00000000-1111-2222-3333-444444444444</uuid>
<memory>8388608</memory>
<currentMemory>2097152</currentMemory>
<vcpu>2</vcpu>
<os>
<type arch="i686">hvm</type>
<boot dev="hd"/>
</os>
<clock offset="utc"/>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash>
<devices>
<disk type="file" device="disk">
<target dev="hda" bus="ide"/>
<source file="/dev/default-pool/default-vol-clone"/>
</disk>
<disk type="file" device="floppy">
<target dev="fda" bus="fdc"/>
<readonly/>
</disk>
</devices>
</domain>

View File

@ -0,0 +1,34 @@
<domain type="test">
<name>origtest-clone</name>
<uuid>00000000-1111-2222-3333-444444444444</uuid>
<memory>8388608</memory>
<currentMemory>2097152</currentMemory>
<vcpu>2</vcpu>
<os>
<type arch="i686">hvm</type>
<boot dev="hd"/>
</os>
<clock offset="utc"/>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash>
<devices>
<disk type="file" device="disk">
<target dev="hda" bus="ide"/>
<source file="/tmp/__virtinst_cli_exist1-clone.img"/>
</disk>
<disk type="file" device="disk">
<target dev="hdb" bus="ide"/>
<source file="/tmp/__virtinst_cli_exist2-clone.img"/>
</disk>
<disk type="file" device="cdrom">
<target dev="hdc" bus="ide"/>
<source file="/tmp/__virtinst_cli_exist2.img"/>
<readonly/>
</disk>
<disk type="file" device="floppy">
<target dev="fda" bus="fdc"/>
<readonly/>
</disk>
</devices>
</domain>

View File

@ -73,5 +73,11 @@
<source mode="bind"/>
<target type="virtio" name="org.qemu.guest_agent.0"/>
</channel>
<graphics type="vnc" port="-1" listen="127.0.0.1">
<listen type="address" address="127.0.0.1"/>
</graphics>
<video>
<model type="cirrus" vram="16384" heads="1" primary="yes"/>
</video>
</devices>
</domain>

View File

@ -0,0 +1,83 @@
<domain type="test">
<name>test-newclone</name>
<uuid>12345678-12F4-1234-1234-123456789AFA</uuid>
<memory unit="KiB">409600</memory>
<currentMemory unit="KiB">204800</currentMemory>
<vcpu placement="static">5</vcpu>
<os>
<type arch="i686">hvm</type>
<loader type="rom">/usr/lib/xen/boot/hvmloader</loader>
<boot dev="hd"/>
</os>
<features>
<acpi/>
<apic/>
</features>
<clock offset="utc"/>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash>
<devices>
<emulator>/usr/lib/xen/bin/qemu-dm</emulator>
<disk type="block" device="floppy">
<driver type="vmdk"/>
<source dev="/dev/disk-pool/newclone1.img"/>
<target dev="fda" bus="fdc"/>
<address type="drive" controller="0" bus="0" target="0" unit="0"/>
</disk>
<disk type="block" device="disk">
<source dev="/dev/disk-pool/diskvol2"/>
<target dev="sda" bus="scsi"/>
<readonly/>
<address type="drive" controller="0" bus="0" target="0" unit="0"/>
</disk>
<disk type="file" device="cdrom">
<target dev="sdb" bus="scsi"/>
<readonly/>
<address type="drive" controller="0" bus="0" target="0" unit="1"/>
</disk>
<disk type="block" device="disk">
<driver type="qcow2"/>
<source dev="/dev/default-pool/collidevol1.img"/>
<target dev="sdc" bus="scsi"/>
<shareable/>
<address type="drive" controller="0" bus="0" target="0" unit="2"/>
</disk>
<disk type="file" device="disk">
<source file="/dev/default-pool/newclone3.img"/>
<target dev="hda" bus="ide"/>
<address type="drive" controller="0" bus="0" target="0" unit="0"/>
</disk>
<disk type="file" device="disk">
<source file="/dev/default-pool/testvol9.img"/>
<target dev="hdb" bus="ide"/>
<address type="drive" controller="0" bus="0" target="0" unit="1"/>
</disk>
<controller type="scsi" index="0"/>
<controller type="fdc" index="0"/>
<controller type="ide" index="0"/>
<controller type="virtio-serial" index="0"/>
<interface type="network">
<mac address="12:34:56:1A:B2:C3"/>
<source network="default"/>
<model type="e1000"/>
</interface>
<interface type="user">
<mac address="12:34:56:1A:B7:C3"/>
</interface>
<parallel type="file">
<source path="/tmp/foo.log"/>
<target port="0"/>
</parallel>
<channel type="unix">
<source mode="bind"/>
<target type="virtio" name="org.qemu.guest_agent.0"/>
</channel>
<graphics type="vnc" port="-1" listen="127.0.0.1">
<listen type="address" address="127.0.0.1"/>
</graphics>
<video>
<model type="cirrus" vram="16384" heads="1" primary="yes"/>
</video>
</devices>
</domain>

View File

@ -0,0 +1,23 @@
<domain type="kvm">
<name>clone-orig-clone</name>
<uuid>00000000-1111-2222-3333-444444444444</uuid>
<memory>262144</memory>
<currentMemory>262144</currentMemory>
<vcpu>1</vcpu>
<os>
<type arch="i686" machine="pc">hvm</type>
<boot dev="cdrom"/>
<loader readonly="yes" type="pflash">/usr/share/ovmf/ovmf-efi.fd</loader>
<nvram>/nvram/clone-orig-clone_VARS.fd</nvram>
</os>
<features>
<acpi/>
</features>
<clock offset="utc"/>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash>
<devices>
<emulator>/usr/bin/qemu-kvm</emulator>
</devices>
</domain>

View File

@ -0,0 +1,43 @@
<domain type="test">
<name>test-clone-simple-clone</name>
<uuid>00000000-1111-2222-3333-444444444444</uuid>
<memory unit="KiB">409600</memory>
<currentMemory unit="KiB">204800</currentMemory>
<vcpu placement="static">5</vcpu>
<os>
<type arch="i686">hvm</type>
<loader type="rom">/usr/lib/xen/boot/hvmloader</loader>
<boot dev="hd"/>
</os>
<features>
<acpi/>
<apic/>
</features>
<clock offset="utc"/>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash>
<devices>
<emulator>/usr/lib/xen/bin/qemu-dm</emulator>
<disk type="file" device="disk">
<driver type="qcow2"/>
<source file="/foo.img"/>
<target dev="hda" bus="ide"/>
<address type="drive" controller="0" bus="0" target="0" unit="0"/>
</disk>
<controller type="ide" index="0"/>
<interface type="user">
<mac address="00:11:22:33:44:55"/>
</interface>
<parallel type="file">
<source path="/tmp/foo.log"/>
<target port="0"/>
</parallel>
<graphics type="vnc" port="-1">
<listen type="address"/>
</graphics>
<video>
<model type="cirrus" vram="16384" heads="1" primary="yes"/>
</video>
</devices>
</domain>

View File

@ -0,0 +1,17 @@
<domain type="test">
<name>clone-empty-clone</name>
<uuid>00000000-1111-2222-3333-444444444444</uuid>
<memory>8388608</memory>
<currentMemory>2097152</currentMemory>
<vcpu>2</vcpu>
<os>
<type arch="i686">hvm</type>
<boot dev="hd"/>
</os>
<clock offset="utc"/>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash>
<devices>
</devices>
</domain>

View File

@ -0,0 +1,23 @@
<domain type="kvm">
<name>clone-orig-clone</name>
<uuid>00000000-1111-2222-3333-444444444444</uuid>
<memory>262144</memory>
<currentMemory>262144</currentMemory>
<vcpu>1</vcpu>
<os>
<type arch="i686" machine="pc">hvm</type>
<boot dev="cdrom"/>
<loader readonly="yes" type="pflash">/usr/share/ovmf/ovmf-efi.fd</loader>
<nvram>/nvram/clone-orig-clone_VARS.fd</nvram>
</os>
<features>
<acpi/>
</features>
<clock offset="utc"/>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash>
<devices>
<emulator>/usr/bin/qemu-kvm</emulator>
</devices>
</domain>

View File

@ -0,0 +1,23 @@
<domain type="kvm">
<name>clone-orig-clone</name>
<uuid>00000000-1111-2222-3333-444444444444</uuid>
<memory>262144</memory>
<currentMemory>262144</currentMemory>
<vcpu>1</vcpu>
<os>
<type arch="i686" machine="pc">hvm</type>
<boot dev="cdrom"/>
<loader readonly="yes" type="pflash">/usr/share/ovmf/ovmf-efi.fd</loader>
<nvram>/nvram-newpool/clone-orig-clone_VARS.fd</nvram>
</os>
<features>
<acpi/>
</features>
<clock offset="utc"/>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash>
<devices>
<emulator>/usr/bin/qemu-kvm</emulator>
</devices>
</domain>

View File

@ -867,6 +867,12 @@ test-many-devices, like an alternate RNG, EOL OS ID, title field
<parallel type='file'>
<source path='/tmp/foo.log'/>
</parallel>
<graphics type="vnc" port="6000" listen="127.0.0.1">
<listen type="address" address="127.0.0.1"/>
</graphics>
<video>
<model type="cirrus" vram="16384" heads="1" primary="yes"/>
</video>
<channel type='unix'>
<source mode='bind' path='/var/lib/libvirt/qemu/channel/target/test-for-clone/org.qemu.guest_agent.0'/>
<target type='virtio' name='org.qemu.guest_agent.0'/>

View File

@ -404,6 +404,7 @@ class App(object):
elif self.appname == "virt-clone":
if "--print-xml" not in cli:
args += " --print-xml"
args += " --__test-nodry"
return args
@ -1301,6 +1302,8 @@ _CLONE_UNMANAGED = "--original-xml %s/clone-disk.xml" % XMLDIR
_CLONE_MANAGED = "--original-xml %s/clone-disk-managed.xml" % XMLDIR
_CLONE_NOEXIST = "--original-xml %s/clone-disk-noexist.xml" % XMLDIR
_CLONE_NVRAM = "--original-xml %s/clone-nvram-auto.xml" % XMLDIR
_CLONE_NVRAM_NEWPOOL = "--original-xml %s/clone-nvram-newpool.xml" % XMLDIR
_CLONE_NVRAM_MISSING = "--original-xml %s/clone-nvram-missing.xml" % XMLDIR
_CLONE_EMPTY = "--original-xml %s/clone-empty.xml" % XMLDIR
vclon = App("virt-clone")
@ -1314,10 +1317,14 @@ c.add_invalid(_CLONE_UNMANAGED + " --auto-clone") # Auto flag w/ local storage,
c = vclon.add_category("misc", "")
c.add_compare("--connect %(URI-KVM)s -o test-clone --auto-clone", "clone-auto1")
c.add_compare("--connect %(URI-TEST-FULL)s -o test-clone-simple --name newvm --auto-clone", "clone-auto2")
c.add_valid("--connect %(URI-KVM)s " + _CLONE_NVRAM + " --auto-clone") # hits a particular nvram code path
c.add_valid(_CLONE_EMPTY + " --auto-clone --uuid 12345678-12F4-1234-1234-123456789AFA --reflink --mac 12:34:56:1A:B2:C3") # Auto flag, no storage
c.add_valid(_CLONE_MANAGED + " --auto-clone") # Auto flag w/ managed storage
c.add_valid(_CLONE_UNMANAGED + " --auto-clone") # Auto flag w/ local storage
c.add_compare("--connect %(URI-KVM)s " + _CLONE_NVRAM + " --auto-clone", "clone-nvram") # hits a particular nvram code path
c.add_compare("--connect %(URI-KVM)s " + _CLONE_NVRAM_NEWPOOL + " --auto-clone", "nvram-newpool") # hits a particular nvram code path
c.add_compare("--connect %(URI-KVM)s " + _CLONE_NVRAM_MISSING + " --auto-clone", "nvram-missing") # hits a particular nvram code path
c.add_compare("--connect %(URI-KVM)s -o test-clone -n test-newclone --mac 12:34:56:1A:B2:C3 --mac 12:34:56:1A:B7:C3 --uuid 12345678-12F4-1234-1234-123456789AFA --file /dev/disk-pool/newclone1.img --file /dev/default-pool/newclone2.img --skip-copy=hdb --force-copy=sdb --file /dev/default-pool/newclone3.img", "clone-manual")
c.add_compare(_CLONE_EMPTY + " --auto-clone --print-xml", "empty") # Auto flag, no storage
c.add_compare("--connect %(URI-KVM)s -o test-clone-simple --auto -f /foo.img --print-xml", "cross-pool") # cross pool cloning which fails with test driver but let's confirm the XML
c.add_compare(_CLONE_MANAGED + " --auto-clone", "auto-managed") # Auto flag w/ managed storage
c.add_compare(_CLONE_UNMANAGED + " --auto-clone", "auto-unmanaged") # Auto flag w/ local storage
c.add_valid("--connect %(URI-TEST-FULL)s -o test-clone --auto-clone --nonsparse") # Auto flag, actual VM, skip state check
c.add_valid("--connect %(URI-TEST-FULL)s -o test-clone-simple -n newvm --preserve-data --file %(EXISTIMG1)s") # Preserve data shouldn't complain about existing volume
c.add_valid("-n clonetest " + _CLONE_UNMANAGED + " --file %(EXISTIMG3)s --file %(EXISTIMG4)s --check path_exists=off") # Skip existing file check
@ -1329,6 +1336,7 @@ c.add_invalid(_CLONE_EMPTY + " --auto-clone -n test") # new name raises error
c.add_invalid("-o test --auto-clone", grep="shutoff") # VM is running, but --clone-running isn't passed
c.add_invalid("--connect %(URI-TEST-FULL)s -o test-clone-simple -n newvm --file %(EXISTIMG1)s") # Should complain about overwriting existing file
c.add_invalid("--connect %(URI-TEST-REMOTE)s -o test-clone-simple --auto-clone --file /dev/default-pool/testvol9.img --check all=off", grep="Clone onto existing storage volume") # hit a specific error message
c.add_invalid("--connect %(URI-TEST-FULL)s -o test-clone-full --auto-clone", grep="not enough free space") # catch failure of clone path setting
c = vclon.add_category("general", "-n clonetest")
@ -1341,7 +1349,7 @@ c.add_valid(_CLONE_UNMANAGED + " --file virt-install --file %(EXISTIMG1)s --pres
c.add_valid(_CLONE_UNMANAGED + " --file %(NEWCLONEIMG1)s --file %(NEWCLONEIMG2)s --file %(NEWCLONEIMG3)s --force-copy=hdc") # XML w/ disks, force copy a readonly target
c.add_valid(_CLONE_UNMANAGED + " --file %(NEWCLONEIMG1)s --file %(NEWCLONEIMG2)s --force-copy=fda") # XML w/ disks, force copy a target with no media
c.add_valid(_CLONE_MANAGED + " --file %(NEWIMG1)s") # XML w/ managed storage, specify managed path
c.add_valid(_CLONE_MANAGED + " --file %(NEWIMG1)s --reflink") # XML w/ managed storage, specify managed path
c.add_valid(_CLONE_MANAGED + " --file %(NEWIMG1)s --reflink") # XML w/ managed storage, specify managed path, use --reflink option
c.add_valid(_CLONE_NOEXIST + " --file %(EXISTIMG1)s --preserve") # XML w/ managed storage, specify managed path across pools# Libvirt test driver doesn't support cloning across pools# XML w/ non-existent storage, with --preserve
c.add_valid("--connect %(URI-TEST-FULL)s -o test-clone -n test --auto-clone --replace") # Overwriting existing running VM
c.add_invalid(_CLONE_EMPTY + " foobar") # Positional arguments error

View File

@ -138,6 +138,8 @@ def parse_args():
# Just used for clone tests
misc.add_argument("--clone-running", action="store_true",
default=False, help=argparse.SUPPRESS)
misc.add_argument("--__test-nodry", action="store_true",
default=False, help=argparse.SUPPRESS)
cli.add_misc_options(misc, prompt=True, replace=True, printxml=True)
@ -197,9 +199,11 @@ def main(conn=None):
# setup design object
design.setup_clone()
run = True
if options.xmlonly:
run = options.__test_nodry
print_stdout(design.clone_xml, do_force=True)
else:
if run:
design.start_duplicate(cli.get_meter())
print_stdout("")