[Kimchi-devel] [PATCH V2] Template: Assign 'raw' to disk format if pool is 'logical' or [i]scsi

Aline Manera alinefm at linux.vnet.ibm.com
Fri Apr 17 17:18:06 UTC 2015


Reviewed-by: Aline Manera <alinefm at linux.vnet.ibm.com>

On 17/04/2015 01:15, Rodrigo Trujillo wrote:
> Kimchi always creates raw disk format to new vm disks if the storagepool
> is logical, iscsi or scsi. But, new templates where not using this
> logic and was possible, through API calls, to create a template with a
> SCSI storagepool and disk format vmdk, for instance.
> This patch fixes this issue and makes necessary change in one of the
> tests in order to avoid an error with _get_storage_type() and
> deactivated storagepools.
>
> Signed-off-by: Rodrigo Trujillo <rodrigo.trujillo at linux.vnet.ibm.com>
> ---
>   src/kimchi/model/templates.py | 4 ++--
>   src/kimchi/vmtemplate.py      | 5 +++++
>   tests/test_template.py        | 2 ++
>   3 files changed, 9 insertions(+), 2 deletions(-)
>
> diff --git a/src/kimchi/model/templates.py b/src/kimchi/model/templates.py
> index 6bc8aca..8a1820d 100644
> --- a/src/kimchi/model/templates.py
> +++ b/src/kimchi/model/templates.py
> @@ -94,7 +94,7 @@ class TemplatesModel(object):
>           # Creates the template class with necessary information
>           # Checkings will be done while creating this class, so any exception
>           # will be raised here
> -        t = LibvirtVMTemplate(params, scan=True)
> +        t = LibvirtVMTemplate(params, scan=True, conn=self.conn)
>           name = params['name']
>           try:
>               with self.objstore as session:
> @@ -231,8 +231,8 @@ class TemplateModel(object):
>
>   class LibvirtVMTemplate(VMTemplate):
>       def __init__(self, args, scan=False, conn=None):
> -        VMTemplate.__init__(self, args, scan)
>           self.conn = conn
> +        VMTemplate.__init__(self, args, scan)
>
>       def _storage_validate(self):
>           pool_uri = self.info['storagepool']
> diff --git a/src/kimchi/vmtemplate.py b/src/kimchi/vmtemplate.py
> index 62772e5..3e4630d 100644
> --- a/src/kimchi/vmtemplate.py
> +++ b/src/kimchi/vmtemplate.py
> @@ -75,6 +75,11 @@ class VMTemplate(object):
>               args['graphics'] = graphics
>           self.info.update(args)
>
> +        # Assign right disk format to logical and [i]scsi storagepools
> +        if self._get_storage_type() in ['logical', 'iscsi', 'scsi']:
> +            for i, disk in enumerate(self.info['disks']):
> +                self.info['disks'][i]['format'] = 'raw'
> +
>       def _get_os_info(self, args, scan):
>           distro = version = 'unknown'
>
> diff --git a/tests/test_template.py b/tests/test_template.py
> index 23a24fb..acdb7c6 100644
> --- a/tests/test_template.py
> +++ b/tests/test_template.py
> @@ -329,6 +329,8 @@ class TemplateTests(unittest.TestCase):
>
>           pool = {'type': 'dir', 'name': 'dir-pool', 'path': '/tmp/dir-pool'}
>           self.request('/storagepools', json.dumps(pool), 'POST')
> +        pool_uri = '/storagepools/%s' % pool['name'].encode('utf-8')
> +        self.request(pool_uri + '/activate', '{}', 'POST')
>
>           # Create a template using the custom network and pool
>           t = {'name': 'test', 'cdrom': '/tmp/mock.iso',




More information about the Kimchi-devel mailing list