Skip to content

Commit

Permalink
Merge pull request #5399 from hs0210/memory_fix_destsize_check
Browse files Browse the repository at this point in the history
memory: Fix the expected memory size after balloon
  • Loading branch information
dzhengfy authored Jan 28, 2024
2 parents 66086ab + b4f95fa commit 5e92de8
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions libvirt/tests/src/memory/memory_allocation/define_value_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ def run_positive_test():
test.log.info("TEST_STEP4: Check guest memory value")
session = vm.wait_for_login()
guest_mem = utils_misc.get_mem_info(session)
session.close()
test.log.debug("Get memory value in guest: %s", guest_mem)

test.log.info("TEST_STEP5: Check currentmemory change to "
"the value and round up to a multiple of default pagesize")
check_mem_after_operation('login')
check_mem_after_operation('login', session)
session.close()
vmxml = vm_xml.VMXML.new_from_dumpxml(vm_name)
current_mem_new = vmxml.get_current_mem()

Expand Down Expand Up @@ -107,14 +107,14 @@ def check_mem_config(dest_unit):
for item in eval(pattern):
libvirt_vmxml.check_guest_xml_by_xpaths(vmxml, item)

def check_mem_after_operation(operation="start"):
def check_mem_after_operation(operation="start", session=None):
"""
Check mem after operation
:param operation: guest operation
"""
new_vmxml = vm_xml.VMXML.new_from_dumpxml(vm_name)
result = get_expected_result(operation)
result = get_expected_result(operation, session)
for attr in eval(params.get("vm_attrs")).keys():
if attr == "cpu":
numa_memory = new_vmxml.cpu.numa_cell[0]['memory']
Expand Down Expand Up @@ -161,7 +161,7 @@ def set_negative_memory(case):
cmd_result = virsh.define(vmxml.xml, debug=True)
libvirt.check_result(cmd_result, error_msg)

def get_dest_size(source_size, operation="start", check_current_mem=False):
def get_dest_size(source_size, operation="start", check_current_mem=False, session=None):
"""
Round up the source size and convert dest size
according to the operation
Expand Down Expand Up @@ -194,7 +194,12 @@ def get_dest_size(source_size, operation="start", check_current_mem=False):
dest_unit = 'KiB'
convert_size = memory_base.convert_data_size(source_size,
dest_unit)
round_up_size = math.ceil(convert_size/default_pagesize)
conf_page_size = session.cmd_output('getconf PAGE_SIZE')
test.log.debug('The PAGE_SIZE of guest is %s', conf_page_size)
if int(conf_page_size) == 65536:
round_up_size = math.floor(convert_size/default_pagesize)
else:
round_up_size = math.ceil(convert_size/default_pagesize)
dest_size = round_up_size * default_pagesize

else:
Expand All @@ -210,7 +215,7 @@ def get_dest_size(source_size, operation="start", check_current_mem=False):

return int(dest_size)

def get_expected_result(operation='start'):
def get_expected_result(operation='start', session=None):
"""
Get expected memory result.
Expand All @@ -220,7 +225,8 @@ def get_expected_result(operation='start'):
result_dict.update({
'memory': get_dest_size(mem_value+mem_unit, operation),
'current_mem': get_dest_size(current_mem+current_mem_unit,
operation, check_current_mem=True),
operation, check_current_mem=True,
session=session),
"max_mem_rt": get_dest_size(max_mem+max_mem_unit, operation),
"numa_memory": get_dest_size(mem_value+mem_unit, operation),
})
Expand Down

0 comments on commit 5e92de8

Please sign in to comment.