[Kimchi-devel] [PATCH 3/3][Kimchi] Fix and add tests to related to max memory in xml

Rodrigo Trujillo rodrigo.trujillo at linux.vnet.ibm.com
Wed Dec 16 13:25:49 UTC 2015


This patch fixes some problems with max memory checkings and add 2 new
tests.

Signed-off-by: Rodrigo Trujillo <rodrigo.trujillo at linux.vnet.ibm.com>
---
 tests/test_template.py   | 13 +++++++++++++
 tests/test_vmtemplate.py | 24 +++++++++++++++++-------
 2 files changed, 30 insertions(+), 7 deletions(-)

diff --git a/tests/test_template.py b/tests/test_template.py
index 0cc5ac8..0b3dd98 100644
--- a/tests/test_template.py
+++ b/tests/test_template.py
@@ -20,6 +20,7 @@
 
 import json
 import os
+import psutil
 import unittest
 from functools import partial
 
@@ -140,6 +141,18 @@ class TemplateTests(unittest.TestCase):
         )
         self.assertEquals(tmpl['disks'][0]['format'], 'vmdk')
 
+        # Create template with memory higher than host max
+        if hasattr(psutil, 'virtual_memory'):
+            max_mem = (psutil.virtual_memory().total >> 10 >> 10)
+        else:
+            max_mem = (psutil.TOTAL_PHYMEM >> 10 >> 10)
+        memory = max_mem + 1024
+        t = {'name': 'test-maxmem', 'cdrom': '/tmp/mock.iso', 'memory': memory}
+        req = json.dumps(t)
+        resp = self.request('/plugins/kimchi/templates', req, 'POST')
+        self.assertEquals(500, resp.status)
+        self.assertTrue(str(max_mem) in resp.read())
+
     def test_customized_tmpl(self):
         # Create a template
         t = {'name': 'test', 'cdrom': '/tmp/mock.iso'}
diff --git a/tests/test_vmtemplate.py b/tests/test_vmtemplate.py
index 79e3b52..de2d542 100644
--- a/tests/test_vmtemplate.py
+++ b/tests/test_vmtemplate.py
@@ -18,6 +18,7 @@
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
 
 import os
+import psutil
 import unittest
 import uuid
 
@@ -88,12 +89,7 @@ class VMTemplateTests(unittest.TestCase):
     def test_to_xml(self):
         graphics = {'type': 'spice', 'listen': '127.0.0.1'}
         vm_uuid = str(uuid.uuid4()).replace('-', '')
-        if os.uname()[4] in ['ppc', 'ppc64', 'ppc64le']:
-            maxmem = 3328
-        else:
-            maxmem = 3072
-        t = VMTemplate({'name': 'test-template', 'cdrom': self.iso,
-                       'max_memory': maxmem << 10})
+        t = VMTemplate({'name': 'test-template', 'cdrom': self.iso})
         xml = t.to_vm_xml('test-vm', vm_uuid, graphics=graphics)
         self.assertEquals(vm_uuid, xpath_get_text(xml, "/domain/uuid")[0])
         self.assertEquals('test-vm', xpath_get_text(xml, "/domain/name")[0])
@@ -102,7 +98,21 @@ class VMTemplateTests(unittest.TestCase):
         expr = "/domain/devices/graphics/@listen"
         self.assertEquals(graphics['listen'], xpath_get_text(xml, expr)[0])
         expr = "/domain/maxMemory/@slots"
-        self.assertEquals('2', xpath_get_text(xml, expr)[0])
+        self.assertEquals('3', xpath_get_text(xml, expr)[0])
+        expr = "/domain/maxMemory"
+        self.assertEquals(str((1024 * 4) << 10), xpath_get_text(xml, expr)[0])
+
+        if hasattr(psutil, 'virtual_memory'):
+            host_memory = psutil.virtual_memory().total >> 10
+        else:
+            host_memory = psutil.TOTAL_PHYMEM >> 10
+        t = VMTemplate({'name': 'test-template', 'cdrom': self.iso,
+                        'memory': (host_memory >> 10) - 512})
+        xml = t.to_vm_xml('test-vm', vm_uuid, graphics=graphics)
+        expr = "/domain/maxMemory"
+        self.assertEquals(str(host_memory), xpath_get_text(xml, expr)[0])
+        expr = "/domain/maxMemory/@slots"
+        self.assertEquals('1', xpath_get_text(xml, expr)[0])
 
     def test_arg_merging(self):
         """
-- 
2.1.0




More information about the Kimchi-devel mailing list