[Kimchi-devel] [PATCH 7/7] VM supports interfaces: update testcase

shaohef at linux.vnet.ibm.com shaohef at linux.vnet.ibm.com
Thu Jan 16 15:56:41 UTC 2014


From: ShaoHe Feng <shaohef at linux.vnet.ibm.com>

update test_rest and test_model

Signed-off-by: ShaoHe Feng <shaohef at linux.vnet.ibm.com>
---
 tests/test_model.py | 19 +++++++++++++++++++
 tests/test_rest.py  | 31 +++++++++++++++++++++++++++++++
 2 files changed, 50 insertions(+)

diff --git a/tests/test_model.py b/tests/test_model.py
index a38e3c6..65c31d2 100644
--- a/tests/test_model.py
+++ b/tests/test_model.py
@@ -121,6 +121,25 @@ class ModelTests(unittest.TestCase):
         inst.template_delete('test')
 
     @unittest.skipUnless(utils.running_as_root(), 'Must be run as root')
+    def test_vm_ifaces(self):
+        inst = kimchi.model.Model(objstore_loc=self.tmp_store)
+        with RollbackContext() as rollback:
+            params = {'name': 'test', 'disks': []}
+            inst.templates_create(params)
+            rollback.prependDefer(inst.template_delete, 'test')
+            params = {'name': 'kimchi-ifaces', 'template': '/templates/test'}
+            inst.vms_create(params)
+            rollback.prependDefer(inst.vm_delete, 'kimchi-ifaces')
+
+            ifaces = inst.vmifaces_get_list('kimchi-ifaces')
+            self.assertEquals(1, len(ifaces))
+
+            iface = inst.vmiface_lookup('kimchi-ifaces', ifaces[0])
+            self.assertEquals(17, len(iface['mac']))
+            self.assertEquals("default", iface['network'])
+            self.assertIn("model", iface)
+
+    @unittest.skipUnless(utils.running_as_root(), 'Must be run as root')
     def test_vm_storage_provisioning(self):
         inst = kimchi.model.Model(objstore_loc=self.tmp_store)
 
diff --git a/tests/test_rest.py b/tests/test_rest.py
index a8e5842..b7ce364 100644
--- a/tests/test_rest.py
+++ b/tests/test_rest.py
@@ -340,6 +340,37 @@ class RestTests(unittest.TestCase):
         resp = self.request('/templates/test', '{}', 'DELETE')
         self.assertEquals(204, resp.status)
 
+    def test_vm_iface(self):
+
+        with RollbackContext() as rollback:
+            # Create a template as a base for our VMs
+            req = json.dumps({'name': 'test', 'cdrom': '/nonexistent.iso'})
+            resp = self.request('/templates', req, 'POST')
+            self.assertEquals(201, resp.status)
+            # Delete the template
+            rollback.prependDefer(self.request,
+                                  '/templates/test', '{}', 'DELETE')
+
+            # Create a VM with default args
+            req = json.dumps({'name': 'test-vm',
+                              'template': '/templates/test'})
+            resp = self.request('/vms', req, 'POST')
+            self.assertEquals(201, resp.status)
+            # Delete the VM
+            rollback.prependDefer(self.request,
+                                  '/vms/test-vm', '{}', 'DELETE')
+
+            ifaces = json.loads(self.request('/vms/test-vm/ifaces').read())
+            self.assertEquals(1, len(ifaces))
+
+            for iface in ifaces:
+                res = json.loads(self.request('/vms/test-vm/ifaces/%s' %
+                                              iface['name']).read())
+                self.assertEquals('default', res['network'])
+                self.assertEquals(17, len(res['mac']))
+                self.assertEquals('virtio', res['model'])
+
+
     def test_vm_customise_storage(self):
         # Create a Template
         req = json.dumps({'name': 'test', 'cdrom': '/nonexistent.iso',
-- 
1.8.4.2




More information about the Kimchi-devel mailing list