[Kimchi-devel] [PATCH v2 2/4] Update (mock)model to generate proper JSON

Adam King rak at linux.vnet.ibm.com
Fri Feb 21 01:59:33 UTC 2014


Update the model and the mock model to generate proper JSON.
Update the automated tests to validate against the new data format.

Signed-off-by: Adam King <rak at linux.vnet.ibm.com>
---
 src/kimchi/mockmodel.py | 11 +++++++----
 src/kimchi/model/vms.py |  2 +-
 tests/test_mockmodel.py |  2 +-
 tests/test_model.py     |  2 +-
 4 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/src/kimchi/mockmodel.py b/src/kimchi/mockmodel.py
index ba9859b..6a44bf7 100644
--- a/src/kimchi/mockmodel.py
+++ b/src/kimchi/mockmodel.py
@@ -921,11 +921,14 @@ class MockVM(object):
         ifaces = [MockVMIface(net) for net in self.networks]
         self.storagedevices = {}
         self.ifaces = dict([(iface.info['mac'], iface) for iface in ifaces])
+
+        stats = {'cpu_utilization': 20,
+                 'net_throughput': 35,
+                 'net_throughput_peak': 100,
+                 'io_throughput': 45,
+                 'io_throughput_peak': 100}
         self.info = {'state': 'shutoff',
-                     'stats': "{'cpu_utilization': 20, 'net_throughput' : 35, \
-                                'net_throughput_peak': 100, \
-                                'io_throughput': 45, \
-                                'io_throughput_peak': 100}",
+                     'stats': stats,
                      'uuid': self.uuid,
                      'memory': template_info['memory'],
                      'cpus': template_info['cpus'],
diff --git a/src/kimchi/model/vms.py b/src/kimchi/model/vms.py
index b482e80..9da6688 100644
--- a/src/kimchi/model/vms.py
+++ b/src/kimchi/model/vms.py
@@ -306,7 +306,7 @@ class VMModel(object):
         res['io_throughput_peak'] = vm_stats.get('max_disk_io', 100)
 
         return {'state': state,
-                'stats': str(res),
+                'stats': res,
                 'uuid': dom.UUIDString(),
                 'memory': info[2] >> 10,
                 'cpus': info[3],
diff --git a/tests/test_mockmodel.py b/tests/test_mockmodel.py
index 4ac08dd..ab5eb59 100644
--- a/tests/test_mockmodel.py
+++ b/tests/test_mockmodel.py
@@ -149,7 +149,7 @@ class MockModelTests(unittest.TestCase):
         self.assertEquals(1024, info['memory'])
         self.assertEquals(1, info['cpus'])
         self.assertEquals('images/icon-vm.png', info['icon'])
-        self.assertEquals(stats_keys, set(eval(info['stats']).keys()))
+        self.assertEquals(stats_keys, set(info['stats'].keys()))
         self.assertEquals('vnc', info['graphics']['type'])
         self.assertEquals('0.0.0.0', info['graphics']['listen'])
 
diff --git a/tests/test_model.py b/tests/test_model.py
index 298a39e..d3315a0 100644
--- a/tests/test_model.py
+++ b/tests/test_model.py
@@ -67,7 +67,7 @@ class ModelTests(unittest.TestCase):
         self.assertEquals(2048, info['memory'])
         self.assertEquals(2, info['cpus'])
         self.assertEquals(None, info['icon'])
-        self.assertEquals(stats_keys, set(eval(info['stats']).keys()))
+        self.assertEquals(stats_keys, set(info['stats'].keys()))
         self.assertRaises(NotFoundError, inst.vm_lookup, 'nosuchvm')
 
     @unittest.skipUnless(utils.running_as_root(), 'Must be run as root')
-- 
1.8.1.4




More information about the Kimchi-devel mailing list