KVM test: New subtest - boot VMs until one of them becomes unresponsive
This test will boot VMs until one of them becomes unresponsive, and
records the maximum number of VMs successfully started.
Yolkfull Chow <yzhou@redhat.com>
git-svn-id: http://test.kernel.org/svn/autotest/trunk@3302 592f7852-d20e-0410-864c-8624ca9c26a4
diff --git a/client/tests/kvm/kvm_tests.py b/client/tests/kvm/kvm_tests.py
index 1852886..2d11fed 100644
--- a/client/tests/kvm/kvm_tests.py
+++ b/client/tests/kvm/kvm_tests.py
@@ -511,3 +511,77 @@
logging.info("VM resumed after S3")
session.close()
+
+
+def run_stress_boot(tests, params, env):
+ """
+ Boots VMs until one of them becomes unresponsive, and records the maximum
+ number of VMs successfully started:
+ 1) boot the first vm
+ 2) boot the second vm cloned from the first vm, check whether it boots up
+ and all booted vms can ssh-login
+ 3) go on until cannot create VM anymore or cannot allocate memory for VM
+
+ @param test: kvm test object
+ @param params: Dictionary with the test parameters
+ @param env: Dictionary with test environment.
+ """
+ # boot the first vm
+ vm = kvm_utils.env_get_vm(env, params.get("main_vm"))
+
+ if not vm:
+ raise error.TestError("VM object not found in environment")
+ if not vm.is_alive():
+ raise error.TestError("VM seems to be dead; Test requires a living VM")
+
+ logging.info("Waiting for first guest to be up...")
+
+ session = kvm_utils.wait_for(vm.ssh_login, 240, 0, 2)
+ if not session:
+ raise error.TestFail("Could not log into first guest")
+
+ num = 2
+ vms = []
+ sessions = [session]
+
+ # boot the VMs
+ while num <= int(params.get("max_vms")):
+ try:
+ vm_name = "vm" + str(num)
+
+ # clone vm according to the first one
+ vm_params = params.copy()
+ vm_params['image_snapshot'] = "yes"
+ vm_params['kill_vm'] = "yes"
+ vm_params['kill_vm_gracefully'] = "no"
+ curr_vm = vm.clone(vm_name, vm_params)
+ kvm_utils.env_register_vm(env, vm_name, curr_vm)
+ params['vms'] += " " + vm_name
+
+ #vms.append(curr_vm)
+ logging.info("Booting guest #%d" % num)
+ if not curr_vm.create():
+ raise error.TestFail("Cannot create VM #%d" % num)
+
+ curr_vm_session = kvm_utils.wait_for(curr_vm.ssh_login, 240, 0, 2)
+ if not curr_vm_session:
+ raise error.TestFail("Could not log into guest #%d" % num)
+
+ logging.info("Guest #%d boots up successfully" % num)
+ sessions.append(curr_vm_session)
+
+ # check whether all previous ssh sessions are responsive
+ for i, vm_session in enumerate(sessions):
+ if vm_session.get_command_status(params.get("alive_test_cmd")):
+ raise error.TestFail("Session #%d is not responsive" % i)
+ num += 1
+
+ except (error.TestFail, OSError):
+ for se in sessions:
+ se.close()
+ logging.info("Total number booted: %d" % (num - 1))
+ raise
+ else:
+ for se in sessions:
+ se.close()
+ logging.info("Total number booted: %d" % (num -1))