[Kimchi-devel] [PATCH 2/3] cpu_info tests for model and mockmodel
Christy Perez
christy at linux.vnet.ibm.com
Tue Oct 28 17:15:05 UTC 2014
Signed-off-by: Christy Perez <christy at linux.vnet.ibm.com>
---
src/kimchi/mockmodel.py | 3 +++
tests/test_mockmodel.py | 24 ++++++++++++++++++++++++
tests/test_model.py | 13 +++++++++++++
3 files changed, 40 insertions(+)
diff --git a/src/kimchi/mockmodel.py b/src/kimchi/mockmodel.py
index 2d0135a..de9df0e 100644
--- a/src/kimchi/mockmodel.py
+++ b/src/kimchi/mockmodel.py
@@ -275,6 +275,9 @@ def templates_create(self, params):
msg_args = {'network': net_name, 'template': name}
raise InvalidParameter("KCHTMPL0003E", msg_args)
+ if params.get('cpu_info') is None:
+ params['cpu_info'] = dict()
+
t = MockVMTemplate(params, self)
if t.name in self._mock_templates:
raise InvalidOperation("KCHTMPL0001E", {'name': name})
diff --git a/tests/test_mockmodel.py b/tests/test_mockmodel.py
index 8de7ce9..7319531 100644
--- a/tests/test_mockmodel.py
+++ b/tests/test_mockmodel.py
@@ -90,6 +90,30 @@ def test_resource(self):
else:
self.fail("Expected exception not raised")
+ def test_template_cpu_info(self):
+ # Create default template
+ req = json.dumps({'name': 'test', 'cdrom': fake_iso})
+ resp = request(host, ssl_port, '/templates', req, 'POST')
+ rsp_body = resp.read()
+ template_data = json.loads(rsp_body)
+ # GET of cpu_info will be {}
+ cpu_info = template_data['cpu_info']
+ self.assertEquals(cpu_info, {})
+ self.assertEquals(cpu_info.get('topology'), None)
+
+ # Update topology
+ # GET of cpu_info will contain 'topology'
+ req = json.dumps({'cpu_info': {'topology': {'sockets': 1,
+ 'cores': 1,
+ 'threads': 1}}})
+ resp = request(host, ssl_port, '/templates/test', req, 'PUT')
+ rsp_body = resp.read()
+ template_data = json.loads(rsp_body)
+ cpu_info = template_data['cpu_info']
+ self.assertEquals(cpu_info, {'topology': {'sockets': 1,
+ 'cores': 1,
+ 'threads': 1}})
+
def test_screenshot_refresh(self):
# Create a VM
req = json.dumps({'name': 'test', 'cdrom': fake_iso})
diff --git a/tests/test_model.py b/tests/test_model.py
index e407fe5..903f6ac 100644
--- a/tests/test_model.py
+++ b/tests/test_model.py
@@ -795,6 +795,19 @@ def test_template_update(self):
for key in params.keys():
self.assertEquals(params[key], info[key])
+ # test cpu_info
+ # new-test has 1 cpu, so this should fail:
+ params['cpu_info'] = {"topology":
+ {"sockets": 1, "cores": 1, "threads": 2}}
+ self.assertRaises(InvalidParameter, inst.template_update,
+ 'new-test', params)
+
+ params['cpus'] = 2
+ inst.template_update('new-test', params)
+ info = inst.template_lookup('new-test')
+ for key in params.keys():
+ self.assertEquals(params[key], info[key])
+
# test update with non-existent network
params = {'networks': ["no-exist"]}
self.assertRaises(InvalidParameter, inst.template_update,
--
1.9.3
More information about the Kimchi-devel
mailing list