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

shaohef at linux.vnet.ibm.com shaohef at linux.vnet.ibm.com
Wed Jul 23 10:49:09 UTC 2014


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

update test_model, test_mockmodel and test_rest

Signed-off-by: ShaoHe Feng <shaohef at linux.vnet.ibm.com>
---
 tests/test_mockmodel.py |  2 +-
 tests/test_model.py     | 17 ++++++++++++++++-
 tests/test_rest.py      | 12 ++++++++++++
 3 files changed, 29 insertions(+), 2 deletions(-)

diff --git a/tests/test_mockmodel.py b/tests/test_mockmodel.py
index e04b740..223879c 100644
--- a/tests/test_mockmodel.py
+++ b/tests/test_mockmodel.py
@@ -139,7 +139,7 @@ def test_vm_info(self):
 
         keys = set(('name', 'state', 'stats', 'uuid', 'memory', 'cpus',
                     'screenshot', 'icon', 'graphics', 'users', 'groups',
-                    'access'))
+                    'access', 'ticket'))
 
         stats_keys = set(('cpu_utilization',
                           'net_throughput', 'net_throughput_peak',
diff --git a/tests/test_model.py b/tests/test_model.py
index 30daafa..da9dae5 100644
--- a/tests/test_model.py
+++ b/tests/test_model.py
@@ -64,7 +64,7 @@ def test_vm_info(self):
 
         keys = set(('name', 'state', 'stats', 'uuid', 'memory', 'cpus',
                     'screenshot', 'icon', 'graphics', 'users', 'groups',
-                    'access'))
+                    'access', 'ticket'))
 
         stats_keys = set(('cpu_utilization',
                           'net_throughput', 'net_throughput_peak',
@@ -702,10 +702,25 @@ def test_vm_edit(self):
             vms = inst.vms_get_list()
             self.assertTrue('kimchi-vm1' in vms)
 
+            # update vm ticket when vm is not running
+            inst.vm_update(u'kimchi-vm1',
+                           {"ticket": {"passwd": "123456"}})
+
             inst.vm_start('kimchi-vm1')
             rollback.prependDefer(self._rollback_wrapper, inst.vm_poweroff,
                                   'kimchi-vm1')
 
+            vm_info = inst.vm_lookup(u'kimchi-vm1')
+            self.assertEquals('123456', vm_info['ticket']["passwd"])
+            self.assertEquals(None, vm_info['ticket']["expire"])
+
+            # update vm ticket when vm is running
+            inst.vm_update(u'kimchi-vm1',
+                           {"ticket": {"passwd": "abcdef", "expire": 20}})
+            vm_info = inst.vm_lookup(u'kimchi-vm1')
+            self.assertEquals('abcdef', vm_info['ticket']["passwd"])
+            self.assertGreaterEqual(20, vm_info['ticket']['expire'])
+
             info = inst.vm_lookup('kimchi-vm1')
             self.assertEquals('running', info['state'])
 
diff --git a/tests/test_rest.py b/tests/test_rest.py
index 54209ef..6f93941 100644
--- a/tests/test_rest.py
+++ b/tests/test_rest.py
@@ -218,9 +218,21 @@ def test_edit_vm(self):
         resp = self.request('/vms/vm-1', req, 'PUT')
         self.assertEquals(200, resp.status)
 
+        req = json.dumps({"ticket": {'passwd': "abcdef"}})
+        resp = self.request('/vms/vm-1', req, 'PUT')
+        info = json.loads(resp.read())
+        self.assertEquals('abcdef', info["ticket"]["passwd"])
+        self.assertEquals(None, info["ticket"]["expire"])
+
         resp = self.request('/vms/vm-1/poweroff', '{}', 'POST')
         self.assertEquals(200, resp.status)
 
+        req = json.dumps({"ticket": {'passwd': "123456", "expire": 20}})
+        resp = self.request('/vms/vm-1', req, 'PUT')
+        info = json.loads(resp.read())
+        self.assertEquals('123456', info["ticket"]["passwd"])
+        self.assertGreaterEqual(20, info["ticket"]["expire"])
+
         req = json.dumps({'name': 12})
         resp = self.request('/vms/vm-1', req, 'PUT')
         self.assertEquals(400, resp.status)
-- 
1.9.3




More information about the Kimchi-devel mailing list