[Kimchi-devel] [PATCH v5 5/5] CDROM Management: changes in tests/test_model.py

Royce Lv lvroyce at linux.vnet.ibm.com
Fri Feb 14 08:51:29 UTC 2014


Reviewed-by: Royce Lv<lvroyce at linux.vnet.ibm.com>
On 2014年02月14日 09:45, Daniel Barboza wrote:
> From: Daniel Henrique Barboza <danielhb at linux.vnet.ibm.com>
>
> Adding model tests to verify the proper behavior of
> CDROM related model functions - add, remove and update.
>
> Signed-off-by: Daniel Henrique Barboza <danielhb at linux.vnet.ibm.com>
> ---
>   tests/test_model.py | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++
>   1 file changed, 56 insertions(+)
>
> diff --git a/tests/test_model.py b/tests/test_model.py
> index b374d2d..58a814b 100644
> --- a/tests/test_model.py
> +++ b/tests/test_model.py
> @@ -163,6 +163,62 @@ class ModelTests(unittest.TestCase):
>               self.assertEquals("virtio", iface["model"])
>
>       @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:
> +            vm_name = 'kimchi-cdrom'
> +            params = {'name': 'test', 'disks': []}
> +            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)
> +
> +            # dummy .iso files
> +            iso_path = '/tmp/existent.iso'
> +            iso_path2 = '/tmp/existent2.iso'
> +            open(iso_path, 'w').close()
> +            open(iso_path2, 'w').close()
> +            wrong_iso_path = '/nonexistent.iso'
> +            rollback.prependDefer(os.remove, iso_path)
> +            rollback.prependDefer(os.remove, iso_path2)
> +
> +            # storage count before adding new cdroms
> +            prev_count = len(inst.storages_get_list(vm_name))
> +
> +            # Create a cdrom
> +            cdrom_args = {"type": "cdrom",
> +                          "path": iso_path}
> +            cdrom_dev = inst.storages_create(vm_name, cdrom_args)
> +            storage_list = inst.storages_get_list(vm_name)
> +            self.assertEquals(prev_count + 1, len(storage_list))
> +
> +            # create a cdrom with existing dev_name
> +            cdrom_args['dev'] = cdrom_dev
> +            self.assertRaises(OperationFailed, inst.storages_create,
> +                              vm_name, cdrom_args)
> +
> +            # update path of existing cd with
> +            # non existent iso
> +            self.assertRaises(OperationFailed, inst.storage_update,
> +                              vm_name, cdrom_dev, {'path': wrong_iso_path})
> +
> +            # update path of existing cd with
> +            # existent iso
> +            inst.storage_update(vm_name, cdrom_dev, {'path': iso_path2})
> +            cdrom_info = inst.storage_lookup(vm_name, cdrom_dev)
> +            self.assertEquals(iso_path2, cdrom_info['path'])
> +
> +            # removing non existent cdrom
> +            self.assertRaises(NotFoundError, inst.storage_delete, vm_name,
> +                              "fakedev")
> +
> +            # removing valid cdrom
> +            inst.storage_delete(vm_name, cdrom_dev)
> +            storage_list = inst.storages_get_list(vm_name)
> +            self.assertEquals(prev_count, len(storage_list))
> +
> +    @unittest.skipUnless(utils.running_as_root(), 'Must be run as root')
>       def test_vm_storage_provisioning(self):
>           inst = model.Model(objstore_loc=self.tmp_store)
>




More information about the Kimchi-devel mailing list