[Kimchi-devel] [PATCH 4/4] Add tests to verify if cache and io of a disk can be changed

Ramon Medeiros posted 4 patches 7 years, 7 months ago
[Kimchi-devel] [PATCH 4/4] Add tests to verify if cache and io of a disk can be changed
Posted by Ramon Medeiros 7 years, 7 months ago
Tests run both on update and template creation

Signed-off-by: Ramon Medeiros <ramonn@linux.vnet.ibm.com>
---
 tests/test_rest.py | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 55 insertions(+), 1 deletion(-)

diff --git a/tests/test_rest.py b/tests/test_rest.py
index 852e4bd..a704283 100644
--- a/tests/test_rest.py
+++ b/tests/test_rest.py
@@ -151,8 +151,17 @@ 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)
 
@@ -166,6 +175,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 +356,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

_______________________________________________
Kimchi-devel mailing list
Kimchi-devel@ovirt.org
http://lists.ovirt.org/mailman/listinfo/kimchi-devel
Re: [Kimchi-devel] [PATCH 4/4] Add tests to verify if cache and io of a disk can be changed
Posted by Aline Manera 7 years, 7 months ago

On 03/10/2017 08:19 PM, Ramon Medeiros wrote:
> Tests run both on update and template creation
>
> Signed-off-by: Ramon Medeiros <ramonn@linux.vnet.ibm.com>
> ---
>   tests/test_rest.py | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++-
>   1 file changed, 55 insertions(+), 1 deletion(-)
>
> diff --git a/tests/test_rest.py b/tests/test_rest.py
> index 852e4bd..a704283 100644
> --- a/tests/test_rest.py
> +++ b/tests/test_rest.py
> @@ -151,8 +151,17 @@ 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)
>   

Please, add tests to update an existing Template to change io, cache and 
bus disk information.

> @@ -166,6 +175,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 +356,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',

_______________________________________________
Kimchi-devel mailing list
Kimchi-devel@ovirt.org
http://lists.ovirt.org/mailman/listinfo/kimchi-devel