def test_purge_noremovable(self, mock_remove, mock_undefine, mock_stop, mock_communicate, mock_popen): ''' Test virt.purge(removables=False) ''' xml = '''<domain type='kvm' id='7'> <name>test-vm</name> <devices> <disk type='file' device='disk'> <driver name='qemu' type='qcow2'/> <source file='/disks/test.qcow2'/> <target dev='vda' bus='virtio'/> </disk> <disk type='file' device='cdrom'> <driver name='qemu' type='raw'/> <source file='/disks/test-cdrom.iso'/> <target dev='hda' bus='ide'/> <readonly/> </disk> <disk type='file' device='floppy'> <driver name='qemu' type='raw'/> <source file='/disks/test-floppy.iso'/> <target dev='hdb' bus='ide'/> <readonly/> </disk> </devices> </domain> ''' self.set_mock_vm("test-vm", xml) res = virt.purge('test-vm', removables=False) self.assertTrue(res) mock_remove.assert_called_once() mock_remove.assert_any_call('/disks/test.qcow2')
def test_purge_noremovable(self, mock_remove, mock_undefine, mock_stop, mock_communicate, mock_popen): get_xml_mock = MagicMock(return_value='''<domain type='kvm' id='7'> <name>test-vm</name> <devices> <disk type='file' device='disk'> <driver name='qemu' type='qcow2'/> <source file='/disks/test.qcow2'/> <target dev='vda' bus='virtio'/> </disk> <disk type='file' device='cdrom'> <driver name='qemu' type='raw'/> <source file='/disks/test-cdrom.iso'/> <target dev='hda' bus='ide'/> <readonly/> </disk> <disk type='file' device='floppy'> <driver name='qemu' type='raw'/> <source file='/disks/test-floppy.iso'/> <target dev='hdb' bus='ide'/> <readonly/> </disk> </devices> </domain> ''') mock = MagicMock(return_value={}) with patch.object(virt, 'get_xml', get_xml_mock): res = virt.purge('test-vm', removables=False) self.assertTrue(res) mock_remove.assert_called_once() mock_remove.assert_any_call('/disks/test.qcow2')