|
| 1 | +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 2 | +# |
| 3 | +# Copyright Redhat |
| 4 | +# |
| 5 | +# SPDX-License-Identifier: GPL-2.0 |
| 6 | +# |
| 7 | +# Author: Liping Cheng <[email protected]> |
| 8 | +# |
| 9 | +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 10 | + |
| 11 | +from virttest import virsh |
| 12 | + |
| 13 | +from virttest.utils_test import libvirt |
| 14 | + |
| 15 | + |
| 16 | +def run(test, params, env): |
| 17 | + """ |
| 18 | + To verify that memory compression cache size can be set/got by |
| 19 | + migrate-compcache. |
| 20 | +
|
| 21 | + :param test: test object |
| 22 | + :param params: Dictionary with the test parameters |
| 23 | + :param env: Dictionary with test environment. |
| 24 | + """ |
| 25 | + vm_name = params.get("migrate_main_vm") |
| 26 | + compression_cache = params.get("compression_cache") |
| 27 | + status_error = "yes" == params.get("status_error", "no") |
| 28 | + err_msg = params.get("err_msg") |
| 29 | + vm_status = params.get("vm_status") |
| 30 | + vm = env.get_vm(vm_name) |
| 31 | + |
| 32 | + test.log.info("Run test for migrate-compcache/migrate-compcache.") |
| 33 | + |
| 34 | + ret = virsh.migrate_compcache(vm_name, debug=True) |
| 35 | + orig_size = None |
| 36 | + if ret.exit_status: |
| 37 | + if vm_status == "vm_shutoff": |
| 38 | + libvirt.check_result(ret, err_msg) |
| 39 | + else: |
| 40 | + test.fail(f"Failed to get compression cache size: {ret.stdout_text}") |
| 41 | + else: |
| 42 | + orig_size = ret.stdout_text.strip().split(":")[-1] |
| 43 | + |
| 44 | + ret = virsh.migrate_compcache(vm_name, size=compression_cache, debug=True) |
| 45 | + if ret.exit_status: |
| 46 | + if status_error: |
| 47 | + libvirt.check_result(ret, err_msg) |
| 48 | + else: |
| 49 | + test.fail(f"Failed to set compression cache size: {ret.stdout_text}") |
| 50 | + |
| 51 | + if vm_status != "vm_shutoff": |
| 52 | + new_size = virsh.migrate_compcache(vm_name, debug=True).stdout_text.strip().split(":")[-1] |
| 53 | + if status_error: |
| 54 | + if orig_size.split()[0].strip() != new_size.split()[0].strip(): |
| 55 | + test.fail(f"For negative testing, compression cache size is modified: {new_size}") |
| 56 | + else: |
| 57 | + test.log.info(f"For negative testing, compression cache size " |
| 58 | + "remains the same as before.") |
| 59 | + else: |
| 60 | + value = new_size.split()[0].strip() |
| 61 | + unit = new_size.split()[-1].strip() |
| 62 | + value = int(float(value)) |
| 63 | + if unit == "KiB": |
| 64 | + size = int(int(compression_cache) / 1024) |
| 65 | + elif unit == "MiB": |
| 66 | + size = int(int(compression_cache) / 1048576) |
| 67 | + elif unit == "GiB": |
| 68 | + size = int(int(compression_cache) / 1073741824) |
| 69 | + if value != size: |
| 70 | + test.fail(f"For positive testing, failed to set the compression " |
| 71 | + "cache size: expected {size}, actual {value}") |
| 72 | + else: |
| 73 | + test.log.info(f"For positive testing, the compression cache " |
| 74 | + "size was set successfully.") |
0 commit comments