[Kimchi-devel] [PATCH] Template disk format test fixes

Daniel Henrique Barboza dhbarboza82 at gmail.com
Tue Jul 21 17:56:04 UTC 2015


Patch applied to master branch of https://github.com/danielhb/kimchi

On 07/20/2015 09:43 AM, dhbarboza82 at gmail.com wrote:
> From: Daniel Henrique Barboza <dhbarboza82 at gmail.com>
>
> Unit tests must consider the scenario where the user set
> a default disk format other than 'qcow2'.
>
> Signed-off-by: Daniel Henrique Barboza <dhbarboza82 at gmail.com>
> ---
>   src/kimchi/vmtemplate.py | 7 ++++---
>   tests/test_model.py      | 5 ++++-
>   tests/test_template.py   | 4 +++-
>   3 files changed, 11 insertions(+), 5 deletions(-)
>
> diff --git a/src/kimchi/vmtemplate.py b/src/kimchi/vmtemplate.py
> index 28c6448..2646573 100644
> --- a/src/kimchi/vmtemplate.py
> +++ b/src/kimchi/vmtemplate.py
> @@ -159,7 +159,8 @@ class VMTemplate(object):
>           dev, xml = get_disk_xml(params)
>           return xml
>   
> -    def _get_default_disk0_format(self):
> +    @staticmethod
> +    def get_default_disk0_format():
>           config_file = os.path.join(paths.conf_dir, 'template.conf')
>           config = ConfigObj(config_file)
>   
> @@ -174,7 +175,7 @@ class VMTemplate(object):
>   
>           base_disk_params = {'type': 'disk', 'disk': 'file',
>                               'bus': self.info['disk_bus'],
> -                            'format': self._get_default_disk0_format()}
> +                            'format': self.get_default_disk0_format()}
>           logical_disk_params = {'format': 'raw'}
>           iscsi_disk_params = {'disk': 'block', 'format': 'raw'}
>   
> @@ -202,7 +203,7 @@ class VMTemplate(object):
>           return unicode(disks_xml, 'utf-8')
>   
>       def to_volume_list(self, vm_uuid):
> -        default_vol_format = self._get_default_disk0_format()
> +        default_vol_format = self.get_default_disk0_format()
>           storage_path = self._get_storage_path()
>           ret = []
>           for i, d in enumerate(self.info['disks']):
> diff --git a/tests/test_model.py b/tests/test_model.py
> index bc71c50..717b9bc 100644
> --- a/tests/test_model.py
> +++ b/tests/test_model.py
> @@ -738,8 +738,11 @@ class ModelTests(unittest.TestCase):
>           inst = model.Model(None,
>                              objstore_loc=self.tmp_store)
>   
> +        # template disk format must be qcow2 because vmsnapshot
> +        # only supports this format
>           orig_params = {'name': 'test', 'memory': 1024, 'cpus': 1,
> -                       'cdrom': UBUNTU_ISO}
> +                       'cdrom': UBUNTU_ISO,
> +                       'disks': [{'size': 1, 'format': 'qcow2'}]}
>           inst.templates_create(orig_params)
>   
>           with RollbackContext() as rollback:
> diff --git a/tests/test_template.py b/tests/test_template.py
> index acdb7c6..83561c1 100644
> --- a/tests/test_template.py
> +++ b/tests/test_template.py
> @@ -24,6 +24,7 @@ import unittest
>   
>   from functools import partial
>   
> +from kimchi.vmtemplate import VMTemplate
>   from kimchi.config import READONLY_POOL_TYPE
>   from kimchi.mockmodel import MockModel
>   from utils import get_free_port, patch_auth, request, run_server
> @@ -87,7 +88,8 @@ class TemplateTests(unittest.TestCase):
>           self.assertEquals(sorted(tmpl.keys()), sorted(keys))
>   
>           # Verify if default disk format was configured
> -        self.assertEquals(tmpl['disks'][0]['format'], 'qcow2')
> +        default_disk_format = VMTemplate.get_default_disk0_format()
> +        self.assertEquals(tmpl['disks'][0]['format'], default_disk_format)
>   
>           # Clone a template
>           resp = self.request('/templates/test/clone', '{}', 'POST')




More information about the Kimchi-devel mailing list