Skip to content

Commit

Permalink
env_process: improve the nested virtualization support
Browse files Browse the repository at this point in the history
This patch adds the support to run nested VMs in threads and pass
on the params from one level to next level which means currently
the tests in each level would run with the default params of the
test but with this support user can pass the customised params
specific to levels or specific to VMs in the levels while starting
the tests.

Signed-off-by: Balamuruhan S <bala24@linux.vnet.ibm.com>
  • Loading branch information
Balamuruhan S committed May 16, 2019
1 parent 6b66caf commit 6cb0867
Showing 1 changed file with 42 additions and 14 deletions.
56 changes: 42 additions & 14 deletions virttest/env_process.py
Expand Up @@ -8,6 +8,7 @@
import shutil
import sys
import copy
import ast
import multiprocessing
try:
from urllib.request import ProxyHandler, build_opener, install_opener
Expand Down Expand Up @@ -66,6 +67,8 @@
#: information from the output produced by `qemu -version`
QEMU_VERSION_RE = r"QEMU (?:PC )?emulator version\s([0-9]+\.[0-9]+\.[0-9]+)\s?\((.*?)\)"

THREAD_ERROR = False


def preprocess_image(test, params, image_name, vm_process_status=None):
"""
Expand Down Expand Up @@ -1096,21 +1099,40 @@ def preprocess(test, params, env):

# start test in nested guest
if params.get("run_nested_guest_test", "no") == "yes":
def thread_func(obj):
"""
Thread method to trigger nested VM test
:param obj: AvocadoGuest Object of the VM
"""
global THREAD_ERROR
try:
obj.run_avocado()
except Exception as info:
logging.error(info)
THREAD_ERROR = True
nest_params = params.copy()
current_level = nest_params.get("nested_guest_level", "L1")
max_level = nest_params.get("nested_guest_max_level", "L1")
nest_timeout = int(nest_params.get("nested_guest_timeout", "3600"))
install_type = nest_params.get("avocado_guest_install_type", "git")
nest_vms = env.get_all_vms()
# Have buffer memory 1G for VMs to work seamlessly
nest_memory = (int(nest_params.get("mem")) // len(nest_vms)) - 1024
if nest_memory < 512:
raise exceptions.TestCancel("Memory is not sufficient for "
"VMs to boot and perform nested "
"virtualization tests")
# set memory for the nested VM
nest_params["vt_extra_params"] = "mem=\"%s\"" % nest_memory
if current_level != max_level:
threads = []
nest_timeout = int(nest_params.get("nested_guest_timeout", "3600"))
install_type = nest_params.get("avocado_guest_install_type", "git")
nest_vms = env.get_all_vms()
# Have buffer memory 1G for VMs to work seamlessly
nest_memory = (int(nest_params.get("mem")) // len(nest_vms)) - 1024
if nest_memory < 512:
raise exceptions.TestCancel("Memory is not sufficient for "
"VMs to boot and perform nested "
"virtualization tests")
# set memory for the nested VM
nest_params["vt_extra_params"] = "mem=\"%s\"" % nest_memory
# pass the params current level to next level
nested_params = nest_params.get("nested_params", {})
nest_params["vt_extra_params"] += " nested_params=\"%s\"" % nested_params
# update the current level's param with nested params sent
# from previous level
nest_params.update(ast.literal_eval(nested_params))
next_level = "L%s" % (int(current_level[-1]) + 1)
logging.debug("Test is running in Guest level: %s", current_level)
for vm in nest_vms:
Expand All @@ -1130,9 +1152,15 @@ def preprocess(test, params, env):
avocado_vt=True,
reinstall=False,
add_args=avocadotestargs)
if not obj.run_avocado():
raise exceptions.TestFail("Test inside nested guest "
"reported failure")
thread = threading.Thread(target=thread_func, args=(obj,))
threads.append(thread)
for thread in threads:
thread.start()
for thread in threads:
thread.join()
if THREAD_ERROR:
raise exceptions.TestFail("Test inside nested guest "
"reported failure")
return params


Expand Down

0 comments on commit 6cb0867

Please sign in to comment.