Reviewed-by: Aline Manera <alinefm(a)linux.vnet.ibm.com>
On 01/24/2014 12:03 AM, shaohef(a)linux.vnet.ibm.com wrote:
From: ShaoHe Feng <shaohef(a)linux.vnet.ibm.com>
update test_rest and test_model
Signed-off-by: ShaoHe Feng <shaohef(a)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 8077f4d..c6c5d0e 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 dd2747b..ac533ea 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['mac']).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',