This patch fixes all tests, changing memory API, to support
memory: {'current', 'maxmemory'}.
It also include some new tests to test changing maxmemory parameter.
Signed-off-by: Rodrigo Trujillo <rodrigo.trujillo(a)linux.vnet.ibm.com>
---
tests/test_livemigration.py | 6 ++----
tests/test_model.py | 22 ++++++++++++++--------
tests/test_rest.py | 23 ++++++++++++++++++-----
tests/test_template.py | 38 ++++++++++++++++++++++++++++++++------
tests/test_vmtemplate.py | 26 +++++++++++++++-----------
5 files changed, 81 insertions(+), 34 deletions(-)
diff --git a/tests/test_livemigration.py b/tests/test_livemigration.py
index 7119688..35d2175 100644
--- a/tests/test_livemigration.py
+++ b/tests/test_livemigration.py
@@ -98,14 +98,12 @@ class LiveMigrationTests(unittest.TestCase):
params = {'name': u'template_test_vm_migrate',
'disks': [],
'cdrom': UBUNTU_ISO,
- 'memory': 2048,
- 'max_memory': 4096 << 10}
+ 'memory': {'current': 2048, 'maxmemory': 4096
<< 10}}
self.inst.templates_create(params)
params = {'name': u'template_test_vm_migrate_nonshared',
'disks': [{'name': 'test_vm_migrate.img',
'size': 1}],
'cdrom': UBUNTU_ISO,
- 'memory': 2048,
- 'max_memory': 4096*1024}
+ 'memory': {'current': 2048, 'maxmemory':
4096*1024}}
self.inst.templates_create(params)
def tearDown(self):
diff --git a/tests/test_model.py b/tests/test_model.py
index 097c2d6..fcd1bbd 100644
--- a/tests/test_model.py
+++ b/tests/test_model.py
@@ -113,7 +113,7 @@ class ModelTests(unittest.TestCase):
self.assertEquals(keys, set(info.keys()))
self.assertEquals('running', info['state'])
self.assertEquals('test', info['name'])
- self.assertEquals(2048, info['memory'])
+ self.assertEquals(2048, info['memory']['current'])
self.assertEquals(2, info['cpu_info']['vcpus'])
self.assertEquals(2, info['cpu_info']['maxvcpus'])
self.assertEquals(None, info['icon'])
@@ -270,9 +270,10 @@ class ModelTests(unittest.TestCase):
pool_uri = "/plugins/kimchi/storagepools/default"
tmpl_info = {"cpu_info": {"vcpus": 1}, "name":
tmpl_name,
"graphics": {"type": "vnc",
"listen": "127.0.0.1"},
- "networks": ["default"], "memory":
1024, "folder": [],
- "icon": "images/icon-vm.png",
"cdrom": "",
- "os_distro": "unknown",
"os_version": "unknown",
+ "networks": ["default"], "memory":
{'current': 1024},
+ "folder": [], "icon":
"images/icon-vm.png",
+ "cdrom": "", "os_distro":
"unknown",
+ "os_version": "unknown",
"disks": [{"base": vol_path,
"size": 10,
"format": "qcow2",
"pool": {"name": pool_uri}}]}
@@ -755,7 +756,9 @@ class ModelTests(unittest.TestCase):
def test_vm_memory_hotplug(self):
config.set("authentication", "method", "pam")
inst = model.Model(None, objstore_loc=self.tmp_store)
- orig_params = {'name': 'test', 'memory': 1024,
'cdrom': UBUNTU_ISO}
+ orig_params = {'name': 'test',
+ 'memory': {'current': 1024, 'maxmemory':
3072},
+ 'cdrom': UBUNTU_ISO}
inst.templates_create(orig_params)
with RollbackContext() as rollback:
@@ -771,11 +774,12 @@ class ModelTests(unittest.TestCase):
'kimchi-vm1')
# Hotplug memory, only available in Libvirt >= 1.2.14
- params = {'memory': 2048}
+ params = {'memory': {'current': 2048}}
if inst.capabilities_lookup()['mem_hotplug_support']:
inst.vm_update('kimchi-vm1', params)
rollback.prependDefer(utils.rollback_wrapper, inst.vm_delete,
'kimchi-vm1')
+ params['memory']['maxmemory'] = 3072
self.assertEquals(params['memory'],
inst.vm_lookup('kimchi-vm1')['memory'])
else:
@@ -789,7 +793,7 @@ class ModelTests(unittest.TestCase):
# template disk format must be qcow2 because vmsnapshot
# only supports this format
- orig_params = {'name': 'test', 'memory': 1024,
+ orig_params = {'name': 'test', 'memory':
{'current': 1024},
'cpu_info': {'vcpus': 1},
'cdrom': UBUNTU_ISO,
'disks': [{'size': 1, 'format':
'qcow2', 'pool': {
@@ -907,7 +911,9 @@ class ModelTests(unittest.TestCase):
self.assertEquals(4, vm_info['cpu_info']['maxvcpus'])
# rename and increase memory when vm is not running
- params = {'name': u'пeω-∨м', 'memory': 2048}
+ params = {'name': u'пeω-∨м',
+ 'memory': {'current': 2048,
+ 'maxmemory': 2048}}
inst.vm_update('kimchi-vm1', params)
rollback.prependDefer(utils.rollback_wrapper, inst.vm_delete,
u'пeω-∨м')
diff --git a/tests/test_rest.py b/tests/test_rest.py
index 1fc0f71..8da7853 100644
--- a/tests/test_rest.py
+++ b/tests/test_rest.py
@@ -152,6 +152,19 @@ class RestTests(unittest.TestCase):
resp = self.request('/plugins/kimchi/vms/vm-1', req, 'PUT')
self.assertEquals(200, resp.status)
+ # Test max memory
+ req = json.dumps({'memory': {'maxmemory': 23}})
+ resp = self.request('/plugins/kimchi/vms/vm-1', req, 'PUT')
+ self.assertEquals(400, resp.status)
+
+ req = json.dumps({'memory': {'maxmemory': 'maxmem 80'}})
+ resp = self.request('/plugins/kimchi/vms/vm-1', req, 'PUT')
+ self.assertEquals(400, resp.status)
+
+ req = json.dumps({'memory': {'maxmemory': 3072}})
+ resp = self.request('/plugins/kimchi/vms/vm-1', req, 'PUT')
+ self.assertEquals(200, resp.status)
+
resp = self.request('/plugins/kimchi/vms/vm-1/start', '{}',
'POST')
self.assertEquals(200, resp.status)
@@ -171,7 +184,7 @@ class RestTests(unittest.TestCase):
# Check if there is support to memory hotplug, once vm is running
resp = self.request('/plugins/kimchi/config/capabilities').read()
conf = json.loads(resp)
- req = json.dumps({'memory': 2048})
+ req = json.dumps({'memory': {'current': 2048}})
resp = self.request('/plugins/kimchi/vms/vm-1', req, 'PUT')
if conf['mem_hotplug_support']:
self.assertEquals(200, resp.status)
@@ -211,11 +224,11 @@ class RestTests(unittest.TestCase):
resp = self.request('/plugins/kimchi/vms/vm-1', req, 'PUT')
self.assertEquals(400, resp.status)
- req = json.dumps({'memory': 100})
+ req = json.dumps({'memory': {'current': 100}})
resp = self.request('/plugins/kimchi/vms/vm-1', req, 'PUT')
self.assertEquals(400, resp.status)
- req = json.dumps({'memory': 'ten gigas'})
+ req = json.dumps({'memory': {'current': 'ten gigas'}})
resp = self.request('/plugins/kimchi/vms/vm-1', req, 'PUT')
self.assertEquals(400, resp.status)
@@ -225,7 +238,7 @@ class RestTests(unittest.TestCase):
self.assertEquals(400, resp.status)
params = {'name': u'∨м-црdαtеd', 'cpu_info':
{'vcpus': 5},
- 'memory': 3072}
+ 'memory': {'current': 3072}}
req = json.dumps(params)
resp = self.request('/plugins/kimchi/vms/vm-1', req, 'PUT')
self.assertEquals(303, resp.status)
@@ -233,7 +246,7 @@ class RestTests(unittest.TestCase):
self.request('/plugins/kimchi/vms/∨м-црdαtеd', req).read()
)
# Memory was hot plugged
- params['memory'] += 1024
+ params['memory']['current'] += 1024
for key in params.keys():
self.assertEquals(params[key], vm[key])
diff --git a/tests/test_template.py b/tests/test_template.py
index da0037e..08e92e4 100644
--- a/tests/test_template.py
+++ b/tests/test_template.py
@@ -70,7 +70,8 @@ class TemplateTests(unittest.TestCase):
# Create a template without cdrom and disk specified fails with 400
t = {'name': 'test', 'os_distro': 'ImagineOS',
- 'os_version': '1.0', 'memory': 1024,
'cpu_info': {'vcpus': 1}}
+ 'os_version': '1.0', 'memory': {'current':
1024},
+ 'cpu_info': {'vcpus': 1}}
req = json.dumps(t)
resp = self.request('/plugins/kimchi/templates', req, 'POST')
self.assertEquals(400, resp.status)
@@ -146,10 +147,11 @@ class TemplateTests(unittest.TestCase):
else:
max_mem = (psutil.TOTAL_PHYMEM >> 10 >> 10)
memory = max_mem + 1024
- t = {'name': 'test-maxmem', 'cdrom':
'/tmp/mock.iso', 'memory': memory}
+ t = {'name': 'test-maxmem', 'cdrom':
'/tmp/mock.iso',
+ 'memory': {'current': memory}}
req = json.dumps(t)
resp = self.request('/plugins/kimchi/templates', req, 'POST')
- self.assertEquals(500, resp.status)
+ self.assertEquals(400, resp.status)
self.assertTrue(str(max_mem) in resp.read())
def test_customized_tmpl(self):
@@ -219,12 +221,36 @@ class TemplateTests(unittest.TestCase):
update_tmpl = json.loads(resp.read())
self.assertEquals(update_tmpl['cpu_info'],
cpu_info_data['cpu_info'])
- # Update memory
- req = json.dumps({'memory': 2048})
+ # Test memory and max memory
+ # - memory greated than max memory (1024 default)
+ req = json.dumps({'memory': {'current': 2048}})
+ resp = self.request(new_tmpl_uri, req, 'PUT')
+ self.assertEquals(400, resp.status)
+ # - max memory greater than 1TiB limit
+ req = json.dumps({'memory': {'maxmemory': 1073741824 + 1024}})
+ resp = self.request(new_tmpl_uri, req, 'PUT')
+ self.assertEquals(400, resp.status)
+ self.assertTrue('KCHVM0079E' in resp.read())
+ # - change only max memory
+ req = json.dumps({'memory': {'maxmemory': 3072}})
+ resp = self.request(new_tmpl_uri, req, 'PUT')
+ self.assertEquals(200, resp.status)
+ update_tmpl = json.loads(resp.read())
+ self.assertEquals(3072, update_tmpl['memory']['maxmemory'])
+ # - change only memory
+ req = json.dumps({'memory': {'current': 2048}})
+ resp = self.request(new_tmpl_uri, req, 'PUT')
+ self.assertEquals(200, resp.status)
+ update_tmpl = json.loads(resp.read())
+ self.assertEquals(2048, update_tmpl['memory']['current'])
+ self.assertEquals(3072, update_tmpl['memory']['maxmemory'])
+ # - change both values
+ req = json.dumps({'memory': {'current': 1024,
'maxmemory': 1024}})
resp = self.request(new_tmpl_uri, req, 'PUT')
self.assertEquals(200, resp.status)
update_tmpl = json.loads(resp.read())
- self.assertEquals(2048, update_tmpl['memory'])
+ self.assertEquals(1024, update_tmpl['memory']['current'])
+ self.assertEquals(1024, update_tmpl['memory']['maxmemory'])
# Update cdrom
cdrom_data = {'cdrom': '/tmp/mock2.iso'}
diff --git a/tests/test_vmtemplate.py b/tests/test_vmtemplate.py
index e157198..f5c44bd 100644
--- a/tests/test_vmtemplate.py
+++ b/tests/test_vmtemplate.py
@@ -98,21 +98,23 @@ 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('3', xpath_get_text(xml, expr)[0])
- expr = "/domain/maxMemory"
- self.assertEquals(str((1024 * 4) << 10), xpath_get_text(xml, expr)[0])
+ # The default is memory and maxmemory have the same value, so
+ # max memory tag is not set
+ self.assertEquals(0, len(xpath_get_text(xml, expr)))
+ expr = "/domain/memory"
+ self.assertEquals(str(1024), 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])
+ 'memory': {'current': (host_memory >> 10) -
512}})
+ try:
+ xml = t.to_vm_xml('test-vm', vm_uuid, graphics=graphics)
+ except Exception as e:
+ # Test current memory greater than maxmemory (1024/default)
+ self.assertTrue('KCHVM0041E' in e.message)
def test_arg_merging(self):
"""
@@ -121,12 +123,14 @@ class VMTemplateTests(unittest.TestCase):
"""
graphics = {'type': 'vnc', 'listen':
'127.0.0.1'}
args = {'name': 'test', 'os_distro': 'opensuse',
'os_version': '12.3',
- 'cpu_info': {'vcpus': 2, 'maxvcpus': 4},
'memory': 2048,
+ 'cpu_info': {'vcpus': 2, 'maxvcpus': 4},
+ 'memory': {'current': 2048, 'maxmemory': 3072},
'networks': ['foo'], 'cdrom': self.iso,
'graphics': graphics}
t = VMTemplate(args)
self.assertEquals(2, t.info.get('cpu_info', {}).get('vcpus'))
self.assertEquals(4, t.info.get('cpu_info', {}).get('maxvcpus'))
- self.assertEquals(2048, t.info.get('memory'))
+ self.assertEquals(2048, t.info.get('memory').get('current'))
+ self.assertEquals(3072, t.info.get('memory').get('maxmemory'))
self.assertEquals(['foo'], t.info.get('networks'))
self.assertEquals(self.iso, t.info.get('cdrom'))
self.assertEquals(graphics, t.info.get('graphics'))
--
2.1.0