[Kimchi-devel] [PATCH 4/5 - v4] Test: Fix and add test related to disks in templates

Aline Manera alinefm at linux.vnet.ibm.com
Mon Nov 30 11:17:34 UTC 2015



On 30/11/2015 01:29, Rodrigo Trujillo wrote:
> This patch fixes problems in test cases after change the way Kimchi
> updates the disks in the Templates. Now disks have the storagepool
> assigned in its data.
>
> Signed-off-by: Rodrigo Trujillo <rodrigo.trujillo at linux.vnet.ibm.com>
> ---
>   src/wok/plugins/kimchi/mockmodel.py           |  5 ++-
>   src/wok/plugins/kimchi/tests/test_model.py    | 13 ++++++++
>   src/wok/plugins/kimchi/tests/test_rest.py     |  5 ++-
>   src/wok/plugins/kimchi/tests/test_template.py | 44 ++++++++++++++++++++++-----
>   4 files changed, 58 insertions(+), 9 deletions(-)
>
> diff --git a/src/wok/plugins/kimchi/mockmodel.py b/src/wok/plugins/kimchi/mockmodel.py
> index 9186f78..f31a297 100644
> --- a/src/wok/plugins/kimchi/mockmodel.py
> +++ b/src/wok/plugins/kimchi/mockmodel.py
> @@ -46,6 +46,7 @@ from wok.plugins.kimchi.model import storagevolumes
>   from wok.plugins.kimchi.model.templates import LibvirtVMTemplate
>   from wok.plugins.kimchi.model.users import PAMUsersModel
>   from wok.plugins.kimchi.model.groups import PAMGroupsModel
> +from wok.plugins.kimchi.utils import pool_name_from_uri
>   from wok.plugins.kimchi.vmtemplate import VMTemplate
>
>
> @@ -72,6 +73,7 @@ class MockModel(Model):
>           # test:///default driver
>           defaults = dict(osinfo.defaults)
>           defaults.update(mockmodel_defaults)
> +        defaults['disks'][0]['pool'] = defaults['storagepool']

The former storagepool information should be removed as each volume has 
its own pool information and the template.conf updated accordingly.

[[disk.0]]
# Disk size in GB
#size = 10

# Disk format
#format = qcow2

# Pool
pool = default

>           osinfo.defaults = dict(defaults)
>
>           self._mock_vgs = MockVolumeGroups()
> @@ -248,7 +250,8 @@ class MockModel(Model):
>       def _probe_image(self, path):
>           return ('unknown', 'unknown')
>
> -    def _get_volume_path(self, pool, vol):
> +    def _get_volume_path(self, pool_uri, vol):
> +        pool = pool_name_from_uri(pool_uri)
>           pool_info = self.storagepool_lookup(pool)
>           if pool_info['type'] == 'scsi':
>               return self._mock_storagevolumes.scsi_volumes[vol]['path']
> diff --git a/src/wok/plugins/kimchi/tests/test_model.py b/src/wok/plugins/kimchi/tests/test_model.py
> index 65d97f2..2d59594 100644
> --- a/src/wok/plugins/kimchi/tests/test_model.py
> +++ b/src/wok/plugins/kimchi/tests/test_model.py
> @@ -76,6 +76,16 @@ def tearDownModule():
>       shutil.rmtree(TMP_DIR)
>
>
> +def _setDiskPoolDefault():
> +    osinfo.defaults['disks'][0]['pool'] = \
> +        '/plugins/kimchi/storagepools/default'
> +
> +
> +def _setDiskPoolDefaultTest():
> +    osinfo.defaults['disks'][0]['pool'] = \
> +        '/plugins/kimchi/storagepools/default-pool'
> +
> +
>   class ModelTests(unittest.TestCase):
>       def setUp(self):
>           self.tmp_store = '/tmp/kimchi-store-test'
> @@ -1051,6 +1061,9 @@ class ModelTests(unittest.TestCase):
>                   'arch': 'i686'
>               }
>
> +            _setDiskPoolDefaultTest()
> +            rollback.prependDefer(_setDiskPoolDefault)
> +
>               inst.templates_create(params)
>               rollback.prependDefer(inst.template_delete, 'test')
>
> diff --git a/src/wok/plugins/kimchi/tests/test_rest.py b/src/wok/plugins/kimchi/tests/test_rest.py
> index 544f2e6..34348b8 100644
> --- a/src/wok/plugins/kimchi/tests/test_rest.py
> +++ b/src/wok/plugins/kimchi/tests/test_rest.py
> @@ -220,6 +220,8 @@ class RestTests(unittest.TestCase):
>           vm = json.loads(
>               self.request('/plugins/kimchi/vms/∨м-црdαtеd', req).read()
>           )
> +        # Memory was hot plugged
> +        params['memory'] += 1024
>           for key in params.keys():
>               self.assertEquals(params[key], vm[key])
>
> @@ -935,7 +937,8 @@ class RestTests(unittest.TestCase):
>           )
>           lun_name = json.loads(resp.read())[0]['name']
>
> -        tmpl_params['disks'] = [{'index': 0, 'volume': lun_name}]
> +        tmpl_params['disks'] = [{'index': 0, 'volume': lun_name,
> +                                'pool': tmpl_params['storagepool']}]
>           req = json.dumps(tmpl_params)
>           resp = self.request('/plugins/kimchi/templates', req, 'POST')
>           self.assertEquals(201, resp.status)
> diff --git a/src/wok/plugins/kimchi/tests/test_template.py b/src/wok/plugins/kimchi/tests/test_template.py
> index 3f026f3..3caad93 100644
> --- a/src/wok/plugins/kimchi/tests/test_template.py
> +++ b/src/wok/plugins/kimchi/tests/test_template.py
> @@ -25,7 +25,6 @@ from functools import partial
>
>   from tests.utils import get_free_port, patch_auth, request, run_server
>
> -from wok.plugins.kimchi import osinfo
>   from wok.plugins.kimchi.config import READONLY_POOL_TYPE
>   from wok.plugins.kimchi.mockmodel import MockModel
>
> @@ -37,6 +36,8 @@ port = None
>   ssl_port = None
>   cherrypy_port = None
>
> +DEFAULT_POOL = u'/plugins/kimchi/storagepools/default-pool'
> +
>
>   def setUpModule():
>       global test_server, model, host, port, ssl_port, cherrypy_port
> @@ -89,9 +90,11 @@ class TemplateTests(unittest.TestCase):
>           )
>           self.assertEquals(sorted(tmpl.keys()), sorted(keys))
>
> -        # Verify if default disk format was configured
> -        default_disk_format = osinfo.defaults['disks'][0]['format']
> -        self.assertEquals(tmpl['disks'][0]['format'], default_disk_format)
> +        disk_keys = ['index', 'pool', 'size', 'format']
> +        disk_pool_keys = ['name', 'type']
> +        self.assertEquals(sorted(tmpl['disks'][0].keys()), sorted(disk_keys))
> +        self.assertEquals(sorted(tmpl['disks'][0]['pool'].keys()),
> +                          sorted(disk_pool_keys))
>
>           # Clone a template
>           resp = self.request('/plugins/kimchi/templates/test/clone', '{}',
> @@ -212,13 +215,20 @@ class TemplateTests(unittest.TestCase):
>           self.assertEquals(update_tmpl['cdrom'], cdrom_data['cdrom'])
>
>           # Update disks
> -        disk_data = {'disks': [{'index': 0, 'size': 10, 'format': 'raw'},
> -                               {'index': 1, 'size': 20, 'format': 'raw'}]}
> +        disk_data = {'disks': [{'index': 0, 'size': 10, 'format': 'raw',
> +                                'pool': DEFAULT_POOL},
> +                               {'index': 1, 'size': 20, 'format': 'qcow2',
> +                                'pool': DEFAULT_POOL}]}
>           resp = self.request(new_tmpl_uri, json.dumps(disk_data), 'PUT')
>           self.assertEquals(200, resp.status)
>           resp = self.request(new_tmpl_uri)
>           self.assertEquals(200, resp.status)
>           updated_tmpl = json.loads(resp.read())
> +        disk_data['disks'][0]['pool'] = {'name': DEFAULT_POOL,
> +                                         'type': 'dir'}
> +
> +        disk_data['disks'][1]['pool'] = {'name': DEFAULT_POOL,
> +                                         'type': 'dir'}
>           self.assertEquals(updated_tmpl['disks'], disk_data['disks'])
>
>           # For all supported types, edit the template and check if
> @@ -227,13 +237,15 @@ class TemplateTests(unittest.TestCase):
>                         'qed', 'raw', 'vmdk', 'vpc']
>           for disk_type in disk_types:
>               disk_data = {'disks': [{'index': 0, 'format': disk_type,
> -                                    'size': 10}]}
> +                                    'size': 10, 'pool': DEFAULT_POOL}]}
>               resp = self.request(new_tmpl_uri, json.dumps(disk_data), 'PUT')
>               self.assertEquals(200, resp.status)
>
>               resp = self.request(new_tmpl_uri)
>               self.assertEquals(200, resp.status)
>               updated_tmpl = json.loads(resp.read())
> +            disk_data['disks'][0]['pool'] = {u'name': DEFAULT_POOL,
> +                                             u'type': u'dir'}
>               self.assertEquals(updated_tmpl['disks'], disk_data['disks'])
>
>           # Update folder
> @@ -348,6 +360,24 @@ class TemplateTests(unittest.TestCase):
>                                       'PUT')
>                   self.assertEquals(200, resp.status)
>
> +        # Test disk template update with different pool
> +        pool_uri = u'/plugins/kimchi/storagepools/kīмсhīUnitTestDirPool'
> +        disk_data = {'disks': [{'size': 5, 'format': 'qcow2',
> +                                'pool': pool_uri}]}
> +        req = json.dumps(disk_data)
> +        resp = self.request('/plugins/kimchi/templates/test', req, 'PUT')
> +        self.assertEquals(200, resp.status)
> +        del(disk_data['disks'][0]['pool'])
> +        disk_data['disks'][0]['index'] = 0
> +        disk_data['disks'][0]['pool'] = {u'name': pool_uri,
> +                                         u'type': u'dir'}
> +        tmpl = json.loads(
> +            self.request('/plugins/kimchi/templates/test').read())
> +        self.assertEquals(sorted(disk_data['disks'][0].keys()),
> +                          sorted(tmpl['disks'][0].keys()))
> +        self.assertEquals(sorted(disk_data['disks'][0].values()),
> +                          sorted(tmpl['disks'][0].values()))
> +
>       def test_tmpl_integrity(self):
>           # Create a network and a pool for testing template integrity
>           net = {'name': u'nat-network', 'connection': 'nat'}




More information about the Kimchi-devel mailing list