[Kimchi-devel] [PATCH 4/4] support create/delete VMIface: update testcase

shaohef at linux.vnet.ibm.com shaohef at linux.vnet.ibm.com
Tue Jan 21 17:25:20 UTC 2014


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

updage tests/test_model.py and tests/test_rest.py

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

diff --git a/tests/test_model.py b/tests/test_model.py
index c6c5d0e..547ad6b 100644
--- a/tests/test_model.py
+++ b/tests/test_model.py
@@ -131,6 +131,14 @@ class ModelTests(unittest.TestCase):
             inst.vms_create(params)
             rollback.prependDefer(inst.vm_delete, 'kimchi-ifaces')
 
+            # Create a network
+            net_name = 'test-network'
+            net_args = {'name': net_name,
+                        'connection': 'nat',
+                        'subnet': '127.0.100.0/24'}
+            inst.networks_create(net_args)
+            rollback.prependDefer(inst.network_delete, net_name)
+
             ifaces = inst.vmifaces_get_list('kimchi-ifaces')
             self.assertEquals(1, len(ifaces))
 
@@ -139,6 +147,20 @@ class ModelTests(unittest.TestCase):
             self.assertEquals("default", iface['network'])
             self.assertIn("model", iface)
 
+            # attach network interface to vm
+            iface_args = {"type": "network",
+                          "network": "test-network",
+                          "model": "virtio"}
+            mac = inst.vmifaces_create('kimchi-ifaces', iface_args)
+            self.assertEquals(17, len(mac))
+            # detach network interface from vm
+            rollback.prependDefer(inst.vmiface_delete, 'kimchi-ifaces', mac)
+
+            iface = inst.vmiface_lookup('kimchi-ifaces', mac)
+            self.assertEquals("network", iface["type"])
+            self.assertEquals("test-network", iface['network'])
+            self.assertEquals("virtio", iface["model"])
+
     @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 5543cb5..935db9a 100644
--- a/tests/test_rest.py
+++ b/tests/test_rest.py
@@ -360,6 +360,16 @@ class RestTests(unittest.TestCase):
             rollback.prependDefer(self.request,
                                   '/vms/test-vm', '{}', 'DELETE')
 
+            # Create a network
+            req = json.dumps({'name': 'test-network',
+                              'connection': 'nat',
+                              'net': '127.0.1.0/24'})
+            resp = self.request('/networks', req, 'POST')
+            self.assertEquals(201, resp.status)
+            # Delete the network
+            rollback.prependDefer(self.request,
+                                  '/networks/test-network', '{}', 'DELETE')
+
             ifaces = json.loads(self.request('/vms/test-vm/ifaces').read())
             self.assertEquals(1, len(ifaces))
 
@@ -370,6 +380,23 @@ class RestTests(unittest.TestCase):
                 self.assertEquals(17, len(res['mac']))
                 self.assertEquals('virtio', res['model'])
 
+            # attach network interface to vm
+            req = json.dumps({"type": "network",
+                              "network": "test-network",
+                              "model": "virtio"})
+            resp = self.request('/vms/test-vm/ifaces', req, 'POST')
+            self.assertEquals(201, resp.status)
+            iface = json.loads(resp.read())
+
+            self.assertEquals('test-network', iface['network'])
+            self.assertEquals(17, len(iface['mac']))
+            self.assertEquals('virtio', iface['model'])
+            self.assertEquals('network', iface['type'])
+
+            # detach network interface from vm
+            resp = self.request('/vms/test-vm/ifaces' % iface['mac'],
+                                '{}', 'DELETE')
+            self.assertEquals(204, resp.status)
 
     def test_vm_customise_storage(self):
         # Create a Template
-- 
1.8.4.2




More information about the Kimchi-devel mailing list