Skip to content

Commit

Permalink
add case for mem balloon autodeflate
Browse files Browse the repository at this point in the history
   VIRT-299026: Memory balloon autodeflate config
Signed-off-by: nanli <[email protected]>
  • Loading branch information
nanli1 committed Sep 26, 2023
1 parent 69841a0 commit d6409f5
Show file tree
Hide file tree
Showing 3 changed files with 142 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
- memory.balloon.autodeflate:
type = mem_balloon_autodeflate
start_vm = no
set_mem = 1945600
mem_unit = "KiB"
current_mem_unit = "KiB"
current_mem = "2097152"
mem_value = "2097152"
dominfo_check = "Max memory:(\s+)${mem_value} KiB\nUsed memory:(\s+)${set_mem} KiB"
variants:
- virtio_model:
memballoon_model = "virtio"
- virtio_trans_model:
memballoon_model = "virtio-transitional"
- virtio_non_trans_model:
memballoon_model = "virtio-non-transitional"
variants:
- autodeflate_undefined:
autodeflate = ''
auto_attr = ""
- autodeflate_off:
autodeflate = "off"
auto_attr = ",'autodeflate':'${autodeflate}'"
- autodeflate_on:
autodeflate = "on"
auto_attr = ",'autodeflate':'${autodeflate}'"
device_dict = "{'model':'${memballoon_model}' ${auto_attr}}"
variants:
- memory_allocation:
mem_attrs = {'memory_unit':'${mem_unit}','memory':${mem_value},'current_mem':${current_mem},'current_mem_unit':'${current_mem_unit}'}
111 changes: 111 additions & 0 deletions libvirt/tests/src/memory/memory_balloon/mem_balloon_autodeflate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# Copyright Redhat
#
# SPDX-License-Identifier: GPL-2.0

# Author: Nannan Li<[email protected]>
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

from virttest import virsh

from virttest.libvirt_xml import vm_xml
from virttest.utils_test import libvirt
from virttest.libvirt_xml.devices import memballoon
from virttest.staging import utils_memory


def run(test, params, env):
"""
Verify the autodeflate takes effect with various memory balloon models.
Scenario:
1.memory balloon models: virtio, virtio-transitional, virtio-non-transitional.
2.autodeflate: on, off, default.
3.mem config: mem, current mem.
"""
def get_memtotal():
"""
Get memTotal value
:return: mem_total, the value of 'cat /proc/meminfo | grep MemTotal'
"""
session = vm.wait_for_login()
mem_total = utils_memory.memtotal(session)
session.close()

return mem_total

def run_test():
"""
Define and start guest
Check memTotal and memory allocation
"""
test.log.info("TEST_STEP1: Define guest")
vmxml = vm_xml.VMXML.new_from_dumpxml(vm_name)

vmxml.del_device('memballoon', by_tag=True)
mem_balloon = memballoon.Memballoon()
mem_balloon.setup_attrs(**device_dict)
vmxml.devices = vmxml.devices.append(mem_balloon)

vmxml.setup_attrs(**mem_attrs)
vmxml.sync()

test.log.info("TEST_STEP2: Start guest ")
if not vm.is_alive():
vm.start()
vmxml = vm_xml.VMXML.new_from_dumpxml(vm_name)
test.log.debug("After define vm, get vmxml is:\n%s", vmxml)

test.log.info("TEST_STEP3: Login guest and get the total guest memory")
init_mem_total = get_memtotal()

test.log.info("TEST_STEP4: Change guest current memory allocation")
result = virsh.setmem(domain=vm_name, size=set_mem, debug=True)
libvirt.check_exit_status(result)

test.log.info("TEST_STEP5: Login guest and get the total guest memory")
second_mem_total = get_memtotal()

if autodeflate == "on":
if second_mem_total != init_mem_total:
test.fail("Total guest memory should not changed from '%d' to "
"'%d'" % (init_mem_total, second_mem_total))
else:
if init_mem_total - second_mem_total != mem_value - set_mem:
test.fail("The difference between two memTotal values: '%d-%d'"
" should be '%d'" % (init_mem_total, second_mem_total,
mem_value - set_mem))
test.log.debug("Get twice correct memTotal:'%d' and '%d'",
init_mem_total, second_mem_total)

test.log.info("TEST_STEP6: Check the memory allocation")
dominfo = virsh.dominfo(vm_name, ignore_status=True, debug=True)
libvirt.check_result(dominfo, expected_match=dominfo_check)

def teardown_test():
"""
Clean data.
"""
test.log.info("TEST_TEARDOWN: Clean up env.")
bkxml.sync()

vm_name = params.get("main_vm")
vm = env.get_vm(vm_name)
vmxml = vm_xml.VMXML.new_from_inactive_dumpxml(vm_name)
bkxml = vmxml.copy()

mem_attrs = eval(params.get("mem_attrs", "{}"))
device_dict = eval(params.get("device_dict", "{}"))
autodeflate = params.get("autodeflate", '')
mem_value = int(params.get("mem_value"))
set_mem = int(params.get("set_mem"))
dominfo_check = params.get("dominfo_check")

try:
run_test()

finally:
teardown_test()
1 change: 1 addition & 0 deletions spell.ignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ augpath
ausearch
auth
Auth
autodeflate
autodestroy
autogenerated
autologin
Expand Down

0 comments on commit d6409f5

Please sign in to comment.