[Kimchi-devel] [PATCH 7/7] Guest disks: Update testcase
Aline Manera
alinefm at linux.vnet.ibm.com
Thu Apr 17 01:49:53 UTC 2014
On 04/13/2014 05:16 AM, lvroyce at linux.vnet.ibm.com wrote:
> From: Royce Lv <lvroyce at linux.vnet.ibm.com>
>
> Tested attach and detach disks,
> according to current vm distro and version,
> choose proper bus for disk if no bus assigned.
> Hot plug for virtio disk works while ide disk does not.
>
> Signed-off-by: Royce Lv <lvroyce at linux.vnet.ibm.com>
> ---
> tests/test_model.py | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 62 insertions(+)
>
> diff --git a/tests/test_model.py b/tests/test_model.py
> index 3041196..a5d2a06 100644
> --- a/tests/test_model.py
> +++ b/tests/test_model.py
> @@ -167,6 +167,68 @@ class ModelTests(unittest.TestCase):
> self.assertEquals("virtio", iface["model"])
>
> @unittest.skipUnless(utils.running_as_root(), 'Must be run as root')
> + def test_vm_disk(self):
> + def _attach_disk(bus_type=None):
> + disk_args = {"type": "disk",
> + "path": disk_path}
> + if bus_type:
> + disk_args['bus'] = bus_type
> + else:
> + bus_type = 'virtio'
> + disk = inst.vmstorages_create(vm_name, disk_args)
> + storage_list = inst.vmstorages_get_list(vm_name)
> + self.assertEquals(prev_count + 1, len(storage_list))
> +
> + # Check the bus type to be 'virtio'
> + disk_info = inst.vmstorage_lookup(vm_name, disk)
> + self.assertEquals(u'disk', disk_info['type'])
> + self.assertEquals(disk_path, disk_info['path'])
> + self.assertEquals(bus_type, disk_info['bus'])
> + return disk
> +
> + inst = model.Model(objstore_loc=self.tmp_store)
> + with RollbackContext() as rollback:
> + vm_name = 'kimchi-cdrom'
> + params = {'name': 'test', 'disks': [], 'cdrom': self.kimchi_iso}
> + inst.templates_create(params)
> + rollback.prependDefer(inst.template_delete, 'test')
> + params = {'name': vm_name, 'template': '/templates/test'}
> + inst.vms_create(params)
> + rollback.prependDefer(inst.vm_delete, vm_name)
> +
> + prev_count = len(inst.vmstorages_get_list(vm_name))
> + self.assertEquals(1, prev_count)
> +
> + # dummy .iso files
> + disk_path = '/tmp/existent.qcow2'
> + disk_path2 = '/tmp/existent2.qcow2'
> + open(disk_path, 'w').close()
> + rollback.prependDefer(os.remove, disk_path)
> + open(disk_path2, 'w').close()
> +
Add rollback to delete disk_path2 ?
> + # Cold plug and unplug a disk
> + disk = _attach_disk()
> + inst.vmstorage_delete(vm_name, disk)
> +
> + # Hot plug a disk
> + inst.vm_start(vm_name)
> + disk = _attach_disk()
> + inst.vmstorage_delete(vm_name, disk)
> +
> + # Hot plug 'ide' bus disk does not work
> + self.assertRaises(InvalidOperation, _attach_disk, 'ide')
> + inst.vm_poweroff(vm_name)
> +
> + # Cold plug 'ide' bus disk can work
> + disk = _attach_disk()
> +
> + # update path is not supported for disk
> + self.assertRaises(
> + InvalidOperation, inst.vmstorage_update,
> + vm_name, disk, {'path': disk_path2})
> + inst.vmstorage_delete(vm_name, disk)
> +
> + @unittest.skipUnless(utils.running_as_root(), 'Must be run as root')
> def test_vm_cdrom(self):
> inst = model.Model(objstore_loc=self.tmp_store)
> with RollbackContext() as rollback:
More information about the Kimchi-devel
mailing list