[Kimchi-devel] [PATCH V3 4/4] Implement integrity verification: update test case
shaohef at linux.vnet.ibm.com
shaohef at linux.vnet.ibm.com
Fri Feb 21 06:59:28 UTC 2014
From: ShaoHe Feng <shaohef at linux.vnet.ibm.com>
update test_model.py and test_rest.py
Signed-off-by: ShaoHe Feng <shaohef at linux.vnet.ibm.com>
---
tests/test_model.py | 33 +++++++++++++++++++++++++++++++++
tests/test_rest.py | 40 ++++++++++++++++++++++++++++++++++++++++
2 files changed, 73 insertions(+)
diff --git a/tests/test_model.py b/tests/test_model.py
index 298a39e..9c01bce 100644
--- a/tests/test_model.py
+++ b/tests/test_model.py
@@ -24,6 +24,7 @@
import os
import platform
import psutil
+import shutil
import tempfile
import threading
import time
@@ -441,6 +442,38 @@ class ModelTests(unittest.TestCase):
self.assertEquals(params[key], info[key])
@unittest.skipUnless(utils.running_as_root(), 'Must be run as root')
+ def test_template_integrity(self):
+ inst = model.Model('test:///default',
+ objstore_loc=self.tmp_store)
+
+ with RollbackContext() as rollback:
+ net_name = 'test-network'
+ net_args = {'name': net_name,
+ 'connection': 'nat',
+ 'subnet': '127.0.100.0/24'}
+ inst.networks_create(net_args)
+
+ path = '/tmp/kimchi-iso/'
+ if not os.path.exists(path):
+ os.makedirs(path)
+ iso = path + 'ubuntu12.04.iso'
+ iso_gen.construct_fake_iso(iso, True, '12.04', 'ubuntu')
+
+ params = {'name': 'test', 'memory': 1024, 'cpus': 1,
+ 'networks': ['test-network'], 'cdrom': iso,
+ 'disks': [{'volume':iso}]}
+ inst.templates_create(params)
+ rollback.prependDefer(inst.template_delete, 'test')
+
+ inst.network_delete(net_name)
+ shutil.rmtree(path)
+
+ info = inst.template_lookup('test')
+ self.assertEquals(info['invalid']['cdrom'], [iso])
+ self.assertEquals(info['invalid']['networks'], [net_name])
+ self.assertEquals(info['invalid']['disks'], [iso])
+
+ @unittest.skipUnless(utils.running_as_root(), 'Must be run as root')
def test_template_clone(self):
inst = model.Model('qemu:///system',
objstore_loc=self.tmp_store)
diff --git a/tests/test_rest.py b/tests/test_rest.py
index 0d574aa..af4f1dc 100644
--- a/tests/test_rest.py
+++ b/tests/test_rest.py
@@ -25,6 +25,7 @@ import base64
import json
import os
import random
+import shutil
import time
import unittest
@@ -32,6 +33,7 @@ import unittest
from functools import partial
+import iso_gen
import kimchi.mockmodel
import kimchi.server
from kimchi.rollbackcontext import RollbackContext
@@ -1073,6 +1075,44 @@ class RestTests(unittest.TestCase):
resp = self.request('/templates/%s' % tmpl_name, '{}', 'DELETE')
self.assertEquals(204, resp.status)
+ def test_template_integrity(self):
+
+ path = '/tmp/kimchi-iso/'
+ if not os.path.exists(path):
+ os.makedirs(path)
+ iso = path + 'ubuntu12.04.iso'
+ iso_gen.construct_fake_iso(iso, True, '12.04', 'ubuntu')
+
+ req = json.dumps({'name': 'test-network',
+ 'connection': 'nat',
+ 'net': '127.0.1.0/24'})
+ resp = request(host, port, '/networks', req, 'POST')
+ self.assertEquals(201, resp.status)
+
+
+ t = {'name': 'test', 'memory': 1024, 'cpus': 1,
+ 'networks': ['test-network'], 'cdrom': iso,
+ 'disks': [{'volume':iso}]}
+
+ req = json.dumps(t)
+ resp = self.request('/templates', req, 'POST')
+ self.assertEquals(201, resp.status)
+
+ shutil.rmtree(path)
+ # Delete the network
+ resp = request(host, port, '/networks/test-network', '{}', 'DELETE')
+ self.assertEquals(204, resp.status)
+
+ # Verify the template
+ res = json.loads(self.request('/templates/test').read())
+ self.assertEquals(res['invalid']['cdrom'], [iso])
+ self.assertEquals(res['invalid']['networks'], ['test-network'])
+ self.assertEquals(res['invalid']['disks'], [iso])
+
+ # Delete the template
+ resp = request(host, port, '/templates/test', '{}', 'DELETE')
+ self.assertEquals(204, resp.status)
+
def test_iso_scan_shallow(self):
# fake environment preparation
self._create_pool('pool-3')
--
1.8.4.2
More information about the Kimchi-devel
mailing list