[Kimchi-devel] [PATCH] [Kimchi 4/4] Add tests to verify if cache and io of a disk can be changed
Ramon Medeiros
ramonn at linux.vnet.ibm.com
Mon Mar 20 23:27:50 UTC 2017
Tests run both on update and template creation
Signed-off-by: Ramon Medeiros <ramonn at linux.vnet.ibm.com>
---
tests/test_rest.py | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 71 insertions(+), 1 deletion(-)
diff --git a/tests/test_rest.py b/tests/test_rest.py
index 852e4bd..96a5216 100644
--- a/tests/test_rest.py
+++ b/tests/test_rest.py
@@ -151,10 +151,35 @@ class RestTests(unittest.TestCase):
self.assertEquals(200, resp.status)
def test_edit_vm(self):
+ disks = [
+ {'index': 0, 'size': 10, 'format': 'qcow2',
+ 'pool': {"name": "/plugins/kimchi/storagepools/default-pool"}},
+ {'index': 1, 'size': 10, 'format': 'qcow2', 'io': 'threads',
+ 'cache': 'unsafe', 'bus': 'scsi',
+ 'pool': {"name": "/plugins/kimchi/storagepools/default-pool"}}]
+
req = json.dumps({'name': 'test',
- 'source_media': {'type': 'disk', 'path': fake_iso}})
+ 'source_media': {'type': 'disk', 'path': fake_iso},
+ 'disks': disks})
+
resp = self.request('/plugins/kimchi/templates', req, 'POST')
self.assertEquals(201, resp.status)
+ resp = json.loads(resp.read())
+
+ # update template storage
+ req = json.dumps({'disks': [
+ {'index': 0, 'size': 10, 'format': 'qcow2',
+ 'pool': {"name": "/plugins/kimchi/storagepools/default-pool"},
+ 'io': 'threads', 'cache': 'unsafe', 'bus': 'virtio'},
+ {'index': 1, 'size': 10, 'format': 'qcow2', 'io': 'threads',
+ 'cache': 'unsafe', 'bus': 'scsi',
+ 'pool': {"name": "/plugins/kimchi/storagepools/default-pool"}}]})
+ resp = self.request('/plugins/kimchi/templates/' + str(resp["name"]),
+ req, 'PUT')
+ resp = json.loads(resp.read())
+ self.assertEquals(resp['disks'][0]['bus'], 'virtio')
+ self.assertEquals(resp['disks'][0]['cache'], 'unsafe')
+ self.assertEquals(resp['disks'][0]['io'], 'threads')
req = json.dumps({'name': 'vm-1',
'template': '/plugins/kimchi/templates/test'})
@@ -166,6 +191,23 @@ class RestTests(unittest.TestCase):
vm = json.loads(self.request('/plugins/kimchi/vms/vm-1').read())
self.assertEquals('vm-1', vm['name'])
+ # test vm storage
+ storages = json.loads(
+ self.request('/plugins/kimchi/vms/vm-1/storages').read())
+ self.assertEquals(len(storages), 3)
+
+ # test sdb disk
+ resp = self.request('/plugins/kimchi/vms/vm-1/storages/sdb', 'GET')
+ self.assertEquals(resp.status, 200)
+ scsi_disk = json.loads(resp.read())
+ self.assertEquals(scsi_disk['cache'], 'unsafe')
+ self.assertEquals(scsi_disk['io'], 'threads')
+
+ # remove sdb disk
+ resp = self.request('/plugins/kimchi/vms/vm-1/storages/sdb',
+ '', 'DELETE')
+ self.assertEquals(resp.status, 204)
+
req = json.dumps({'cpu_info': {'maxvcpus': 5, 'vcpus': 3}})
resp = self.request('/plugins/kimchi/vms/vm-1', req, 'PUT')
self.assertEquals(200, resp.status)
@@ -330,6 +372,34 @@ class RestTests(unittest.TestCase):
resp = self.request('/plugins/kimchi/vms/∨м-црdαtеd', req, 'PUT')
self.assertEquals(400, resp.status)
+ # add volume as scsi
+ mock_base = '/tmp/mock.img'
+ os.system("qemu-img create -f qcow2 %s 100M" % mock_base)
+ req = json.dumps({'type': 'disk',
+ 'path': mock_base,
+ 'bus': 'scsi'})
+ resp = self.request('/plugins/kimchi/vms/∨м-црdαtеd/storages',
+ req, 'POST')
+ self.assertEquals(201, resp.status)
+ resp = json.loads(resp.read())
+ self.assertEquals("scsi", resp["bus"])
+ dev = resp["dev"]
+
+ # change io/cache
+ req = json.dumps({"io": "threads", "cache": "unsafe"})
+ resp = self.request('/plugins/kimchi/vms/∨м-црdαtеd/storages/' +
+ str(dev), req, 'PUT')
+ self.assertEquals(200, resp.status)
+ resp = json.loads(resp.read())
+ self.assertEquals('threads', resp['io'])
+ self.assertEquals('unsafe', resp['cache'])
+
+ # remove disk
+ resp = self.request('/plugins/kimchi/vms/∨м-црdαtеd/storages/' +
+ str(dev), req, 'DELETE')
+ os.system("rm -rf " + mock_base)
+ self.assertEquals(204, resp.status)
+
def test_vm_lifecycle(self):
# Create a Template
req = json.dumps({'name': 'test',
--
2.9.3
More information about the Kimchi-devel
mailing list