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

Rodrigo Trujillo rodrigo.trujillo at linux.vnet.ibm.com
Wed Nov 25 06:45:44 UTC 2015


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/tests/test_rest.py     |  7 +++++-
 src/wok/plugins/kimchi/tests/test_template.py | 34 ++++++++++++++++++++++++---
 2 files changed, 37 insertions(+), 4 deletions(-)

diff --git a/src/wok/plugins/kimchi/tests/test_rest.py b/src/wok/plugins/kimchi/tests/test_rest.py
index 544f2e6..2aabbc0 100644
--- a/src/wok/plugins/kimchi/tests/test_rest.py
+++ b/src/wok/plugins/kimchi/tests/test_rest.py
@@ -33,7 +33,7 @@ from tests.utils import run_server, wait_task
 from wok.rollbackcontext import RollbackContext
 from wok.utils import add_task
 
-from wok.plugins.kimchi import mockmodel
+from wok.plugins.kimchi import mockmodel, osinfo
 from wok.plugins.kimchi.osinfo import get_template_default
 
 import iso_gen
@@ -47,6 +47,9 @@ ssl_port = None
 cherrypy_port = None
 fake_iso = '/tmp/fake.iso'
 
+# Set default test pool, as it is used and checked in every template creation
+osinfo.defaults['disks'][0]['storagepool'] = \
+        '/plugins/kimchi/storagepools/default-pool'
 
 def setUpModule():
     global test_server, model, host, port, ssl_port, cherrypy_port
@@ -220,6 +223,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])
 
diff --git a/src/wok/plugins/kimchi/tests/test_template.py b/src/wok/plugins/kimchi/tests/test_template.py
index 5e89d22..af6352d 100644
--- a/src/wok/plugins/kimchi/tests/test_template.py
+++ b/src/wok/plugins/kimchi/tests/test_template.py
@@ -38,6 +38,11 @@ ssl_port = None
 cherrypy_port = None
 
 
+DEFAULT_POOL = '/plugins/kimchi/storagepools/default-pool'
+# Set default test pool, as it is used and checked in every template creation
+osinfo.defaults['disks'][0]['storagepool'] = DEFAULT_POOL
+
+
 def setUpModule():
     global test_server, model, host, port, ssl_port, cherrypy_port
 
@@ -89,6 +94,10 @@ class TemplateTests(unittest.TestCase):
         )
         self.assertEquals(sorted(tmpl.keys()), sorted(keys))
 
+        disk_keys = ['index', 'storagepool', 'storagepooltype', 'size',
+                     'format']
+        self.assertEquals(sorted(tmpl['disks'][0].keys()), sorted(disk_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)
@@ -212,8 +221,10 @@ 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',
+                     'storagepool': DEFAULT_POOL, 'storagepooltype': 'dir'},
+                               {'index': 1, 'size': 20, 'format': 'raw',
+                     'storagepool': DEFAULT_POOL, 'storagepooltype': 'dir'}]}
         resp = self.request(new_tmpl_uri, json.dumps(disk_data), 'PUT')
         self.assertEquals(200, resp.status)
         resp = self.request(new_tmpl_uri)
@@ -227,7 +238,8 @@ 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, 'storagepool': DEFAULT_POOL,
+                         'storagepooltype': 'dir'}]}
             resp = self.request(new_tmpl_uri, json.dumps(disk_data), 'PUT')
             self.assertEquals(200, resp.status)
 
@@ -346,6 +358,22 @@ class TemplateTests(unittest.TestCase):
                                     'PUT')
                 self.assertEquals(200, resp.status)
 
+        # Test disl template update with different pool
+        disk_data = {'disks': [{'size': 5, 'format': 'qcow2',
+          'storagepool': u'/plugins/kimchi/storagepools/kīмсhīUnitTestDirPool',
+                     }]}
+        req = json.dumps(disk_data)
+        resp = self.request('/plugins/kimchi/templates/test', req, 'PUT')
+        self.assertEquals(200, resp.status)
+        disk_data['disks'][0]['index'] = 0
+        disk_data['disks'][0]['storagepooltype'] = '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'}
-- 
2.1.0




More information about the Kimchi-devel mailing list