-
Notifications
You must be signed in to change notification settings - Fork 168
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add case for mem balloon autodeflate #5196
Merged
chunfuwen
merged 1 commit into
autotest:master
from
nanli1:add_case_for_mem_balloon_autodeflate
Oct 25, 2023
+142
−0
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
libvirt/tests/cfg/memory/memory_balloon/mem_balloon_autodeflate.cfg
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
111
libvirt/tests/src/memory/memory_balloon/mem_balloon_autodeflate.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_vm_internal(): | ||
""" | ||
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_vm_internal() | ||
|
||
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_vm_internal() | ||
|
||
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,7 @@ augpath | |
ausearch | ||
auth | ||
Auth | ||
autodeflate | ||
autodestroy | ||
autogenerated | ||
autologin | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you miss destroy VM in teardown part?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, chunfu, We will get inactive guest after
sync()