[Kimchi-devel] [PATCH V2 5/5] vm ticket in backend: update test case

shaohef at linux.vnet.ibm.com shaohef at linux.vnet.ibm.com
Tue Jul 15 15:45:13 UTC 2014


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

update test_model and test_rest

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

diff --git a/tests/test_model.py b/tests/test_model.py
index 2c77514..c182752 100644
--- a/tests/test_model.py
+++ b/tests/test_model.py
@@ -183,6 +183,37 @@ def test_vm_ifaces(self):
             self.assertEquals("e1000", iface["model"])
 
     @unittest.skipUnless(utils.running_as_root(), 'Must be run as root')
+    def test_vm_ticket(self):
+        inst = model.Model(objstore_loc=self.tmp_store)
+        with RollbackContext() as rollback:
+            params = {'name': 'test', 'disks': [], 'cdrom': self.kimchi_iso}
+            inst.templates_create(params)
+            rollback.prependDefer(inst.template_delete, 'test')
+            params = {'name': 'kimchi-ticket', 'template': '/templates/test'}
+            inst.vms_create(params)
+            rollback.prependDefer(inst.vm_delete, 'kimchi-ticket')
+
+            # update vm persistent ticket configure
+            ticket_args = {"passwd": "123456"}
+            inst.vmticket_update('kimchi-ticket', ticket_args)
+            ticket = inst.vmticket_lookup('kimchi-ticket')
+            self.assertEquals("123456", ticket['passwd'])
+
+            inst.vm_start('kimchi-ticket')
+            rollback.prependDefer(inst.vm_poweroff, 'kimchi-ticket')
+            # update live vm ticket configure
+            ticket_args = {"passwd": "abcdef"}
+            inst.vmticket_update('kimchi-ticket', ticket_args)
+            ticket = inst.vmticket_lookup('kimchi-ticket')
+            self.assertEquals("abcdef", ticket['passwd'])
+
+            ticket_args = {"passwd": "123456", "expire": 0.1}
+            inst.vmticket_update('kimchi-ticket', ticket_args)
+            time.sleep(0.2)
+            self.assertRaises(OperationFailed, inst.vmticket_lookup,
+                              'kimchi-ticket')
+
+    @unittest.skipUnless(utils.running_as_root(), 'Must be run as root')
     def test_vm_disk(self):
         disk_path = '/tmp/existent2.iso'
         open(disk_path, 'w').close()
diff --git a/tests/test_rest.py b/tests/test_rest.py
index 694d907..460177e 100644
--- a/tests/test_rest.py
+++ b/tests/test_rest.py
@@ -624,6 +624,42 @@ def test_vm_iface(self):
                                 '{}', 'DELETE')
             self.assertEquals(204, resp.status)
 
+    def test_vm_ticket(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')
+
+            ticket = json.loads(self.request('/vms/test-vm/ticket').read())
+            self.assertEquals('123456', ticket['passwd'])
+
+            # update vm ticket
+            req = json.dumps({"passwd": "abcdef"})
+            resp = self.request('/vms/test-vm/ticket', req, 'PUT')
+            ticket = json.loads(resp.read())
+            self.assertEquals('abcdef', ticket['passwd'])
+
+            # ticket expire take effect
+            req = json.dumps({"passwd": "abcdef", "expire": 0.1})
+            resp = self.request('/vms/test-vm/ticket', req, 'PUT')
+            time.sleep(0.2)
+            resp = self.request('/vms/test-vm/ticket')
+            self.assertEquals(500, resp.status)
+
     def test_vm_customise_storage(self):
         # Create a Template
         req = json.dumps({'name': 'test', 'cdrom': '/nonexistent.iso',
-- 
1.9.3




More information about the Kimchi-devel mailing list