[Kimchi-devel] [PATCHv6 7/7] Add tests for image based template
lvroyce at linux.vnet.ibm.com
lvroyce at linux.vnet.ibm.com
Wed Aug 6 09:03:48 UTC 2014
From: Royce Lv <lvroyce at linux.vnet.ibm.com>
Add model tests for image based template, validated vm creation.
Signed-off-by: Royce Lv <lvroyce at linux.vnet.ibm.com>
---
tests/test_model.py | 31 +++++++++++++++++++++++++++++++
tests/test_rest.py | 21 +++++++++++++++++++++
2 files changed, 52 insertions(+)
diff --git a/tests/test_model.py b/tests/test_model.py
index 9cfa312..80aadc7 100644
--- a/tests/test_model.py
+++ b/tests/test_model.py
@@ -107,6 +107,37 @@ class ModelTests(unittest.TestCase):
self.assertFalse('kimchi-vm' in vms)
@unittest.skipUnless(utils.running_as_root(), 'Must be run as root')
+ def test_image_based_template(self):
+ inst = model.Model(objstore_loc=self.tmp_store)
+
+ with RollbackContext() as rollback:
+ vol = 'base-vol.img'
+ params = {'name': vol,
+ 'capacity': 1024,
+ 'allocation': 1,
+ 'format': 'qcow2'}
+ inst.storagevolumes_create('default', params)
+ vol_path = inst.storagevolume_lookup('default', vol)['path']
+ rollback.prependDefer(inst.storagevolume_delete, 'default', vol)
+
+ params = {'name': 'test', 'disks': [{'base': vol_path}]}
+ inst.templates_create(params)
+ rollback.prependDefer(inst.template_delete, 'test')
+
+ params = {'name': 'kimchi-vm', 'template': '/templates/test'}
+ inst.vms_create(params)
+ rollback.prependDefer(inst.vm_delete, 'kimchi-vm')
+
+ vms = inst.vms_get_list()
+ self.assertTrue('kimchi-vm' in vms)
+
+ inst.vm_start('kimchi-vm')
+ rollback.prependDefer(inst.vm_poweroff, 'kimchi-vm')
+
+ info = inst.vm_lookup('kimchi-vm')
+ self.assertEquals('running', info['state'])
+
+ @unittest.skipUnless(utils.running_as_root(), 'Must be run as root')
def test_vm_graphics(self):
inst = model.Model(objstore_loc=self.tmp_store)
params = {'name': 'test', 'disks': [], 'cdrom': self.kimchi_iso}
diff --git a/tests/test_rest.py b/tests/test_rest.py
index a97cf90..e5164f9 100644
--- a/tests/test_rest.py
+++ b/tests/test_rest.py
@@ -868,6 +868,27 @@ class RestTests(unittest.TestCase):
resp = json.loads(resp.read())
self.assertIn(u"KCHVM0012E", resp['reason'])
+ def test_create_vm_with_img_based_template(self):
+ resp = json.loads(
+ self.request('/storagepools/default/storagevolumes').read())
+ self.assertEquals(0, len(resp))
+
+ # Create a Template
+ mock_base = '/tmp/mock.img'
+ open(mock_base, 'w').close()
+ req = json.dumps({'name': 'test', 'disks': [{'base': mock_base}]})
+ resp = self.request('/templates', req, 'POST')
+ self.assertEquals(201, resp.status)
+
+ req = json.dumps({'template': '/templates/test'})
+ json.loads(self.request('/vms', req, 'POST').read())
+
+ # Test storage volume created with backing store of base file
+ resp = json.loads(
+ self.request('/storagepools/default/storagevolumes').read())
+ self.assertEquals(1, len(resp))
+ self.assertEquals(mock_base, resp[0]['base']['path'])
+
def test_get_storagepools(self):
storagepools = json.loads(self.request('/storagepools').read())
self.assertEquals(2, len(storagepools))
--
1.8.3.2
More information about the Kimchi-devel
mailing list